By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

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

P: n/a
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_PROP ERTY,"username");

stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROP ERTY,"password");
stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDR ESS_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
Nov 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

"Nate" wrote:
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_PROP ERTY,"username");

stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROP ERTY,"password");
stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDR ESS_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

Nov 23 '05 #2

P: n/a
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

"John Scragg" wrote:
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

"Nate" wrote:
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_PROP ERTY,"username");

stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROP ERTY,"password");
stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDR ESS_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

Dec 21 '05 #3

P: n/a
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

"Striboldt" wrote:
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

"John Scragg" wrote:
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

"Nate" wrote:
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_PROP ERTY,"username");

stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROP ERTY,"password");
stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDR ESS_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

Jan 16 '06 #4

P: n/a
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/mi...058abceb9610f8 (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


"DStone" wrote:
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

"Striboldt" wrote:
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

"John Scragg" wrote:
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

"Nate" wrote:

> 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_PROP ERTY,"username");
>
> stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROP ERTY,"password");
> stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDR ESS_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

Jan 31 '06 #5

P: 1
Yes. This was bugging me too. So here's some code that'll do Basic Auth:

Firstly you need to sub-class the WebService class generated by 'Add Web reference' as follows (lets assume the generated web service is called GeneratedWebService):

Expand|Select|Wrap|Line Numbers
  1.     public class MyWebService : GeneratedWebService
  2.     {
  3.         private String m_HeaderName;
  4.         private String m_HeaderValue;
  5.  
  6.         //----------------
  7.         // GetWebRequest
  8.         //
  9.         // Called by the SOAP client class library
  10.         //----------------   
  11.         protected override WebRequest GetWebRequest(Uri uri)
  12.         {
  13.             // call the base class to get the underlying WebRequest object
  14.             HttpWebRequest req = (HttpWebRequest)base.GetWebRequest(uri);
  15.  
  16.             if (null != this.m_HeaderName)
  17.             {
  18.                 // set the header
  19.                 req.Headers.Add(this.m_HeaderName, this.m_HeaderValue);
  20.             }
  21.  
  22.             // return the WebRequest to the caller
  23.             return (WebRequest)req;
  24.         }
  25.  
  26.         //----------------
  27.         // SetRequestHeader
  28.         //
  29.         // Sets the header name and value that GetWebRequest will add to the
  30.         // underlying request used by the SOAP client when making the 
  31.         // we method call
  32.         //----------------   
  33.         public void SetRequestHeader(String headerName, String headerValue)
  34.         {
  35.             this.m_HeaderName = headerName;
  36.             this.m_HeaderValue = headerValue;
  37.         }
  38.     }
Then set up the web service as follows:
Expand|Select|Wrap|Line Numbers
  1.             MyWebService svc1 = new MyWebService();
  2.             byte[] bcred = Encoding.ASCII.GetBytes("username:password");
  3.             string b64cred = Convert.ToBase64String(bcred);
  4.             svc1.SetRequestHeader("Authorization", "Basic " + b64cred);
Replace username and password with an actual username and password.
Feb 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.