2

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?

1
  • when I just use the app.config to define the bindings it works with no problems. So what is the problem with the above code? Edit: I'm using above EndpointAddress and not Endpoint. Commented Jul 22, 2014 at 7:47

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.