HTTP请求未经授权使用客户端身份验证方案' Anonymous'。

时间:2018-01-31 12:55:41

标签: wcf wcf-security

我正在尝试连接到使用https

托管的wcf服务

我将正确的凭据传递给服务器

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; 

我使用了以下配置

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

但是从服务器获得以下响应

HTTP请求未经授权使用客户端身份验证方案&#39; Anonymous&#39;。从服务器接收的认证标题是&#39; Basic realm =&#34; BS&#39;

2 个答案:

答案 0 :(得分:0)

将安全配置更改为:

onMessageReceived()

答案 1 :(得分:0)

当我更改配置时

<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>
我有 HTTP请求未经授权使用客户端身份验证方案“Basic”。从服务器收到的验证头是'Basic realm =“BS”'。