user1757223
user1757223

Reputation: 71

Exception thrown when connecting to web service

I'm having a problem consuming a java web service via HTTPS from a .NET windows application. The web service requires server authentication, but when I try to call any method I receive the follor error:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm=login'.

I added the web service as a service reference in Visual Studio. Here is my app configuration:

In the <security> section I have this:

<security mode="Transport">
  transport clientCredentialType="None" proxyCredentialType="None"
   realm="" />
   <message clientCredentialType="UserName" algorithmSuite="Default" />
 </security>

In the <httpsTransport> section I have this:

<httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
  maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
  bypassProxyOnLocal="false"
  hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true"
  maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
  realm="" transferMode="Buffered" 
  unsafeConnectionNtlmAuthentication="false"
  useDefaultWebProxy="true" requireClientCertificate="false" />

And my code looks like this:

ServiceReference1.servicePortTypeClient service = new ServiceReference1.servicePortTypeClient ("enpointbindingname"); 
service .ClientCredentials.UserName.UserName = "username";          
service .ClientCredentials.UserName.Password = "password";
service.method();

Upvotes: 1

Views: 3117

Answers (1)

Elian Ebbing
Elian Ebbing

Reputation: 19027

From the response of the server, it looks like the webservice requires basic http authentication. This means authentication on the transport level, not the message level. So maybe the security configuration could be just this:

<security mode="Transport">
    <transport clientCredentialType="Basic" />
</security>

If the webservice indeed uses HTTPS with basic authentication, then this msdn page describes this scenario in detail.

Upvotes: 3

Related Questions