Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / January 2006

Tip: Looking for answers? Try searching our database.

Calling a Web Service hosted on a Web Logic server from a C# SOAP client

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nate - 19 Oct 2005 18:30 GMT
We are attempting to make a request to a web service (we will refer to it as
XXXServices) hosted on a Web Logic server from a C# SOAP client.  The server
responds with a 401 Unauthorized error (that appears in plain text), and
causes the client to crash.  This C# code has been deployed both as an
ASP.NET application and a WinForms app, each of which produced the same
result.  Further, moving the clients from a Windows XP machine to Windows
2003 Server on a different network resulted in the same errant behavior.

However, a Java client that accesses the same web service succeeds.  We
employed an HTTP packet sniffer to examine the difference between the
Request and Response interaction between the respective clients and the
server.  First, here is the C# client's request:

Hypertext Transfer Protocol
   POST /xxxservices/ws HTTP/1.1\r\n
       Request Method: POST
       Request URI: /xxxervices/ws
       Request Version: HTTP/1.1
   User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client
Protocol 1.1.4322.2032)\r\n
   Content-Type: text/xml; charset=utf-8\r\n
   SOAPAction: ""\r\n
   Content-Length: 790\r\n
   Expect: 100-continue\r\n
   Connection: Keep-Alive\r\n
   Host: xxxxx.xxxxxxxxxxx.com\r\n
   \r\n

Next, here is the request made by the Java client

Hypertext Transfer Protocol
   POST /xxxservices/ws?wsdl HTTP/1.1\r\n
       Request Method: POST
       Request URI: /xxxservices/ws?wsdl
       Request Version: HTTP/1.1
   Content-Type: text/xml\r\n
   SOAPAction: ""\r\n
   Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=\r\n
       Credentials: username:password
   User-Agent: Java/1.5.0_05\r\n
   Host: xxxxx.xxxxxxxxxxx.com\r\n
   Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n
   Connection: keep-alive\r\n
   Content-Length: 686\r\n
   \r\n

Here is the C# client code, which fails:

try
  {
   XXXServices service = new XXXServices();
   String userName = "username";
   String password = "password";

   NetworkCredential cred = new NetworkCredential(userName,password);

   service.Credentials = cred;

   String appString = "appstring";
   String xmlReq  = "A string that contains XML data";

   textBox1.Text =  service.Url + Environment.NewLine +
service.sendxml(appString,xmlReq);

  }
  catch(Exception ex)
  {

   textBox1.Text = ex.ToString();
  }

Finally, here is the Java code, which succeeds:

try
       {
           String
wsdlUrl="http://xxxxx.xxxxxxxxxxx.com/xxxservices/ws?wsdl";
           System.out.println("Getting proxy to = "+wsdlUrl);
           XXXServices service = new XXXServices_Impl();
           XXXServicesPort_Stub stub = (XXXServicesPort_Stub)
service.getXXXServicesPort();

stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,"username");

stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,"password");
           stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
wsdlUrl);
           XXXServicesPort port = (XXXServicesPort) stub;
           String xmlTrans = "A string that contains XML data";
           System.out.println("Sending transaction: "+xmlTrans);
           String result = port.sendxml("appstring",xmlTrans);
           System.out.println("Result = "+result);

       }
       catch(Exception e)
       {
           System.out.println(e.toString());
           e.printStackTrace();
       }

The ideal outcome to this problem involves somehow "fixing" the C# code so
it plays nicely with the Web Logic server.  We have entertained the
following possible approaches:

1. Deploy the Java code as some kind of intermediate "translator"
between C# and Java SOAP formats
2. Integrate the Java code using Interop into the C# client, so that
all the Web Service interaction is done in Java, but the business logic
remains C#
3. Overload the auto-generated C# proxy to produce a header that
"looks-like" the Java header.

None of these seems particular "right."  Further, we're not entirely sure
how we would do any of them, since we are mostly a .NET shop and have little
Java experience.  Our operations group is also not crazy about running an
Apache server to host the Java code, if it comes to that.

Can anyone on this list recommend either a) a better solution that works or
b) an implementation approach to one of the above-mentioned solutions, 1, 2
or 3?  We would also be very interested to hear about similar experiences
and solutions that have succeeded or failed.  Lastly, if this is a
documented problem that Microsoft, Sun, BEA (or whoever) knows about, and
someone can point us to an article, that would be very helpful.

Many thanks in advance.

-Nate
John Scragg - 19 Oct 2005 19:35 GMT
Nate,

Try setting your "service .PreAuthenticate = true" on your proxy object
before making the call to the ws method.

If that does not work (cross your fingers ;-) Then you may need to look at
WSE so that you can create a SoapContext object and a UsernameToken object
rather than the build in credentials.

UsernameToken userToken = new New UsernameToken("name", "pw",
PasswordOption.SendPlainText) ;

SoapContext  requestContext = service .RequestSoapContext ;

requestContext.Security.Tokens.Add(userToken) ;
requestContext.Timestamp.Ttl = 60000;
requestContext.Path.EncodedMustUnderstand = "false";

Best of luck,

John Scragg

> We are attempting to make a request to a web service (we will refer to it as
> XXXServices) hosted on a Web Logic server from a C# SOAP client.  The server
[quoted text clipped - 121 lines]
>
> Many thanks in advance
Striboldt - 21 Dec 2005 13:05 GMT
I have tried using the service.PreAuthenticate, and it stills fails to
include credentials in the WebLogic web service request.
Are there really no solution to this problem?

If you know how to do a Basic authentication up against a WebLogic web
service please tell.

Best Regards,
Morten

> Nate,
>
[quoted text clipped - 143 lines]
> >
> > Many thanks in advance
DStone - 16 Jan 2006 10:30 GMT
Hello,

I have the same problem (although the server is Lotus/Domino).  I just can't
get my code to send out the basic authorization tag on the first request.

In my case, the server does not respond with a 401, but sends back a html
login screen, which causes the call to the webservice to crash.

I've setup the credential cache, and set PreAuthenticate to true.  Packet
sniffer shows that nothing is sent.

I'm using framework 2.0 with VS 2005

> I have tried using the service.PreAuthenticate, and it stills fails to
> include credentials in the WebLogic web service request.
[quoted text clipped - 153 lines]
> > >
> > > Many thanks in advance
Joseph Hanna - 31 Jan 2006 05:10 GMT
I too am having this problem.  I have waded my way through literally hundreds
of posts on this topic and no one can seem to solve the problem.

I just need to add "AUTHORIZATION" to the HTTP Header (not SOAP Header - so
I can't use "ws.Credentials").

PLEASE MS - HELP US!!!!!!!!

The webservice I'm trying to connect to is written with PHP on Apache.  To
complicate matters, I'm trying to do this on the Compact Framework.  I have
seen some posts regarding the Overriding of GetWebRequest with this CSharp
code:-

http://groups.google.com.au/group/microsoft.public.dotnet.languages.csharp/msg/b
1058abceb9610f8
 (although I would prefer VB).

I cannot work out where this Override goes?  It cannot override the method
in the base class for my WebService Proxy (SoapHttpClientProtocol), and I
would hate to have to roll-my-own Proxy for the WebService when wsdl.exe does
most of what I need.

Please help. I have a looming deadline that I'm struggling to meet.

Many thanks in advance.

Joe

> Hello,
>
[quoted text clipped - 166 lines]
> > > >
> > > > Many thanks in advance

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.