views:

10

answers:

0

I want to authenticate user in WCF and getting this errror:

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

web.conf

<security mode="Transport">           
      <transport clientCredentialType="Basic"
                 proxyCredentialType="None"
                 realm="dotnetstore" />           
</security>

Behaviours (web.conf, for custom user validation)

<serviceCredentials>
    <userNameAuthentication userNamePasswordValidationMode="Custom"
          customUserNamePasswordValidatorType="Service.CustomUserNameValidator, Service"/>
</serviceCredentials>

Client code:

EndpointAddress address = new EndpointAddress(
        new Uri("https://DotNetStore/b2bServiceSite/Service.svc"),
            EndpointIdentity.CreateDnsIdentity("DotNetStore"),
            new AddressHeaderCollection()
    );

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Transport.Realm = "dotnetstore";

var client = new PartnerService.Service1Client(binding, address);
client.ClientCredentials.UserName.UserName = "java";
client.ClientCredentials.UserName.Password = "javapwd";

client.Open();