Reputation: 2186
I just want to consume a HTTPS-soap-webservice from a c# client with user and password. I don't want to use the app.config so I just set the few properties directly inside the code.
When I try to access a webservice-method I always get the following error:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm......
This is my code (I tried many more thinks but this is my code now):
var b = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
b.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
....
var client = new MyClient(b, new Endpoint("https://myurl..."))
client.clientCredentials.UserName.UserName = "myuser";
client.clientCredentials.UserName.Password = "mypassword";
client.myMethodcall();
Like I wrote above I already found many "solutions" how to fix this error but they just doesn't work for me. I used basicHttpBinding, I used WSHttpBinding, I set the binding-timeouts, I used SecurityMode.TransportWithMessageCredential, etc. It seems that the client doesn't set the authentication-header at all!
It shouldn't make a difference to set all the properties directly in code or to use the app.config, right? Can anybody please help me with this?
Upvotes: 1
Views: 4215
Reputation: 2186
I finally found the error.
I created a client which takes the app.config-settings and I created a client for which i set the settings directly in code and found out that the one from the app.config uses
SecurityMode.Transport
by default and not
SecurityMode.TransportWithMessageCredentials
So i changed my code to SecurityMode.Transport and it works.
Upvotes: 1