0
votes

I m trying to connect to a wcf service hosted with https

I passed the right Credentials to the server

enter code here   var channel = new ConfigurationChannelFactory<C>(serviceConfigName, pluginConfig, new EndpointAddress(Url));
        if (!string.IsNullOrEmpty(UserName))
        {
            channel.Credentials.UserName.UserName = UserName;
            channel.Credentials.UserName.Password = Password;
            channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        }
        return channel; 

and I used the below configuration

<configuration>
  <system.serviceModel>
    <client>
      <endpoint
          name="ms_basic_http"
          address="http://localhost"
          binding="basicHttpBinding"
          bindingConfiguration="defaultBasicHttpsBinding"
          contract="ICONTRACT" />
    </client>
    <bindings>
      <basicHttpBinding >
        <binding name="defaultBasicHttpsBinding">
          <security mode="Message">
            <transport clientCredentialType="Basic" realm="BS"   />
            <message clientCredentialType="UserName"  />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

but getting the below response from the server

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

2

2 Answers

0
votes

when I changed the config to be

<configuration>
  <system.serviceModel>
    <client>
      <endpoint
          name="ms_basic_http"
          address="http://localhost"
          binding="basicHttpBinding"
          bindingConfiguration="defaultBasicHttpsBinding"
          contract="contract" />
    </client>
    <bindings>
      <basicHttpBinding >
        <binding name="defaultBasicHttpsBinding">
          <security mode="Transport">
            <transport clientCredentialType="Basic" proxyCredentialType="None" realm="BS" />
            
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>
0
votes

Change the security config to:

<bindings>
  <basicHttpBinding >
    <binding name="defaultBasicHttpsBinding">
      <security mode="Transport"> //or none
        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>