cancel
Showing results for 
Search instead for 
Did you mean: 

Web Service client authorization error: HTTP status 401

Former Member
0 Kudos

.NETters,

My .NET client program is invoking a simple "Hello World" Web Service written in ABAP. Here is the code:

Z_HWWSDServiceWse svc = new Z_HWWSDServiceWse();

try {

string msg = svc.ZHelloworld();

Console.WriteLine(msg);

}catch(Exception e) {

Console.WriteLine(e.Message);

}

The code uses WSE 2.0 framework.

This code works if I edit the properties on WSD service using transaction SICF and specify anonymous login options. However, I would like to pass the user token from the client program itself.

So I removed anonymous login options and supplied the required information programmatically.

UsernameToken ut = new UsernameToken("pradeep", "password", PasswordOption.SendPlainText);

svc.RequestSoapContext.Security.Tokens.Add(ut);

However, when I run this code, I get an error: "The request failed with HTTP status 401: Unauthorized"

I then tried supplementing this code with network credentials logic:

System.Net.CredentialCache cc = new System.Net.CredentialCache();

cc.Add(new Uri("http://servermachname"), "Basic", new System.Net.NetworkCredential("pradeep", "password", null));

svc.Credentials = cc;

The problem still doesn't go away :-(.

Does anyone have any idea on what is it that I am missing in my code?

Thank you in advance for your help.

Pradeep

Accepted Solutions (1)

Accepted Solutions (1)

reiner_hille-doering
Active Contributor
0 Kudos

In my tests with normal .NET WS client something like the following allways worked:

WSProxy proxy = new WSProxy();

proxy.Credentials = new System.Net.NetworkCredential("user", "password");

proxy.PreAuthenticate = true;

proxy.CallMethod();

As your code is very similar, it may be a compatibility problem between WSE and WAS. I would recommend that you use a network snippen and look what really goes over the wire.

I have also seen an issue where the settings in SICF where somehow corrupted (e.g. the fixed credentials checkbock was on, but no credentials where specified). The solution was just to "reset" the settings in SICF.

Former Member
0 Kudos

Reiner,

Thank you for your help. I took your suggestion and added just one line of code:

svc.Crendentials = new System.Net.NetworkCredential(user, pass)

And it works :-).

There are way many articles on sdn and saphelp that can confuse people sometime :-).

Appreciate your help. You get full points.

Pradeep

Answers (0)