【问题标题】:WCF Consumer not attaching client credentials to headerWCF 消费者未将客户端凭据附加到标头
【发布时间】:2014-06-07 16:56:58
【问题描述】:

我有一个使用用户名身份验证的 WCF 服务,我有一个使用该服务并尝试访问受保护方法的控制台应用程序。我运行代码,Fiddler 在 auth 选项卡中说:

不存在代理授权标头。

不存在授权标头。

这是我的访问代码:

BasicHttpBinding binding = new BasicHttpBinding();

binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
binding.Security.Transport.Realm = "MyRealm";         

ServiceReference1.MobileAPIClient serviceProxy = new ServiceReference1.MobileAPIClient(binding, new EndpointAddress("https://xx.xx.xx.xx/InventoryServices.MobileApi.svc"));

serviceProxy.ClientCredentials.UserName.UserName = "test";
serviceProxy.ClientCredentials.UserName.Password = "test123";

serviceProxy.ChannelFactory.Credentials.UserName.UserName = "test";
serviceProxy.ChannelFactory.Credentials.UserName.Password = "test123";

try 
{
    serviceProxy.Test();
}
catch (Exception ex) 
{
    var ex2 = ex;
}

为什么凭据没有附加到标头?

【问题讨论】:

    标签: c# wcf authentication


    【解决方案1】:

    wcf 中有握手模式。因此客户端和服务在第一次请求之前与凭据交换,然后他们只使用会话令牌。 要禁用此模式,您应该在 web.config 中设置

    <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" negotiateServiceCredential="false" establishSecurityContext="false"/>
    </security>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 2014-05-30
      相关资源
      最近更新 更多