views:

26

answers:

1

Hi,

I am trying to connect to service which is accesssible over https and need authentication.

The error I get is:

Test method TestProject1.UnitTest1.TestReharB2B threw exception: System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="Application"'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized..

It seems to me like that username and password is not sent to service. What am I missing?

The code:

EndpointAddress address = new EndpointAddress(
                    new Uri("https://84.52.158.151:8443/JavaStore/services/B2BService"),
                        EndpointIdentity.CreateDnsIdentity("JavaStore"),
                        new AddressHeaderCollection()
                );

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

var client = new ReharB2BService.B2BServicePortTypeClient(binding, address);

client.ChannelFactory.Credentials.UserName.UserName = "dotNet";
client.ChannelFactory.Credentials.UserName.Password = "dotnetpwd";

client.Open();
client.getAllItems();
+1  A: 

Your service returns error because there is some misconfiguration between server and client. Your client uses transport security with UserName message credentials. That means that HTTPS is used and message contains SOAP header with user name and password. But your service returns exception because it (probably IIS) expects transport security with Basic credentials. That means HTTPS and HTTP Basic authentication (HTTP header).

Ladislav Mrnka