【问题标题】:WCF Authentication with ClientCredentials error带有 ClientCredentials 错误的 WCF 身份验证
【发布时间】:2014-06-30 17:57:46
【问题描述】:

我正在尝试连接到 WCF 服务,但是当我这样做时出现此错误:

HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是 '基本领域="ServiceGateway"'。

我知道我在 WCF 客户端上设置客户端凭据时进行身份验证:

new wcfClient(enpointconfigurationName, url) 
{
    ClientCredentials =
    {
        UserName =
        {
            UserName = "yyy", 
            Password = "zzz"
        }
    }
}

编辑

我在 web.config 中有这个 WCF 配置:

<client>
    <endpoint address="xxx" binding="basicHttpBinding" bindingconfiguration="myBinding" contract="yyy" name="myName" />
</client>

<basichttpbinding>
    <binding name="myBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
    </binding>
</basichttpbinding>

【问题讨论】:

  • 查看这个问题的答案stackoverflow.com/questions/1365163/…
  • 阅读。我的配置错了吗?
  • 尝试使用安全模式和 clientCredentialType,例如尝试将安全模式设置为“Transport”,将 clientCredentialType 设置为“Basic”

标签: c# wcf authentication


【解决方案1】:

需要修改配置才能在绑定中使用这个:

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

编辑

它起作用的原因是,即使在代码中设置了 UserName 属性,仍需要配置 WCF 服务以发送凭据。这是在 WCF ABC (http://msdn.microsoft.com/en-us/library/aa480190.aspx) 的 B 中完成的:

"A" stands for Address: Where is the service?
"B" stands for Binding: How do I talk to the service?
"C" stands for Contract: What can the service do for me?

WCF 的整体理念是它应该是可配置的,以便在服务发生更改时无需重新部署代码。

【讨论】:

  • 能否解释一下为什么这种方法可以解决错误或提供链接供参考?
猜你喜欢
  • 2011-02-16
  • 1970-01-01
  • 2011-06-08
  • 2013-07-10
  • 2012-03-25
  • 1970-01-01
  • 2010-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多