【问题标题】:Preventing negotiation handshake on subsequent service calls防止后续服务调用中的协商握手
【发布时间】:2015-06-11 18:23:56
【问题描述】:

我正在调用使用 Windows 身份验证的 SOAP 服务。这是我的配置:

new BasicHttpBinding
{
    Security = new BasicHttpSecurity
    {
        Mode = BasicHttpSecurityMode.TransportCredentialOnly,
        Transport = new HttpTransportSecurity
        {
            ClientCredentialType = HttpClientCredentialType.Windows
        }
    },
};

我在这里手动设置凭据,因为用户位于不同的域中:

client.ClientCredentials.Windows.ClientCredential.Domain = "...";
client.ClientCredentials.Windows.ClientCredential.UserName = "...";
client.ClientCredentials.Windows.ClientCredential.Password = "...";

我注意到我通过客户端代理进行的每次调用都会导致三个行程:

Request: POST /EndPoint (no auth)
Response: 401 Unauthorized, WWW-Authenticate: Negotiate

Request: POST /EndPoint, Authorization: Negotiate
Response: 401 Unauthorized, WWW-Authenticate: Negotiate <gunk>

Request: Post /EndPoint, Authorization: Negotiate <gunk>
Response: 200 OK

如果这只发生在第一次调用时,它不会那么糟糕,但它会发生在对同一客户端代理实例的所有后续调用中。

我要呼叫的服务器不在我的控制范围内,并且延迟时间不小,所以我很想找到一种方法来消除这些多余的行程。有可能吗?

【问题讨论】:

  • 我认为它尝试了不同版本的加密 tls1.0、1.1 等,您可以按特定顺序设置它们。这也可能是服务器端问题,它首先期望最高形式等,但这只是一个非常模糊的猜测
  • @CoryNelson WCF 服务由 IIS 托管?

标签: c# .net wcf soap windows-authentication


【解决方案1】:

我刚刚使用您的绑定设置和手动 un+pwd 身份验证创建了带有 WCF 服务的虚拟客户端。 WCF 服务设置为接受 Windows 身份验证。

但是,在我的情况下,所有后续调用都会自动进行身份验证。

Request: Post /Service1.svc

响应 1:

HTTP/1.1 401 Unauthorized
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM

响应 2:

HTTP/1.1 401 Unauthorized
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
WWW-Authenticate: Negotiate xxxxxxxxxxxxxxxxxxxxxxxxxx.....

响应 3:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 202
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
WWW-Authenticate: Negotiate xxxxxxx....

在响应标头中,我有 Persistent-Auth: true 。这对你来说也一样吗?如果否 - IIS 中有设置可以强制客户端在每次请求后进行身份验证 - 请参阅此MSDN post

基本上,我猜你必须在服务器上有:

authPersistSingleRequest =  False
authPersistNonNTLM = True

然后就可以了。

【讨论】:

  • authPersistNonNTLM 看起来是个不错的候选人。我会试试这个并报告回来..
  • 这修复了它。谢谢。
猜你喜欢
  • 2019-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多