2011-05-31 45 views
5

我有一个需要基本授权的Web服务,并且需要使用需要NTLM授权的Internet代理的用户。我还有一个表单应用程序,用于调用Web服务并向用户请求Web服务凭据(与NTLM凭据不同)。通过代理与NTLM授权不起作用的基本授权请求Web服务

我得到了应用程序配置工作(WCF ServiceModel),它使用默认代理凭据,请求正在与代理进行身份验证,但是在使用Web服务进行身份验证后,由于某种原因它不发送请求正文。

如果我在没有NTLM代理的情况下在本地进行测试,该过程将正常工作。很抱歉,很长的例子,但我不得不包括他们。

1日要求:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://tempuri.org/MyMethod" 
Host: www.myservice.com 
Content-Length: 329 
Expect: 100-continue 
Accept-Encoding: gzip, deflate 
Proxy-Connection: Keep-Alive 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>[...]</s:Body></s:Envelope> 

接收:

HTTP/1.1 407 Proxy Authentication Required 
Proxy-Authenticate: NTLM 
Proxy-Authenticate: BASIC realm="corporaterealm" 
Cache-Control: no-cache 
Pragma: no-cache 
Content-Type: text/html; charset=utf-8 
Proxy-Connection: close 
Set-Cookie: BCSI-CS-36204A5A7BBD24D9=2; Path=/ 
Connection: close 
Content-Length: 1057 
Proxy-Support: Session-Based-Authentication 

[...] 

第二请求:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://tempuri.org/MyMethod" 
Accept-Encoding: gzip, deflate,gzip, deflate 
Proxy-Authorization: NTLM TlRMTVNTUAABAAAAB7IIoggACAAxAAAACQAJACgAAAAFASgKAAAAD1dTUkswNDg3MENPTUVUTkVU 
Host: www.myservice.com 
Content-Length: 0 

接收:

HTTP/1.1 407 Proxy Authentication Required 
Proxy-Authenticate: NTLM TlRMTVNTUAACAAAAEAAQADgAAAAFgomiysOwieqrhFEAAAAAAAAAALIAsgBIAAAABQLODgAAAA9DAE8ATQBFAFQATgBFAFQAAgAQAEMATwBNAEUAVABOAEUAVAABABoAVgBJAC0AUgBJAEMASwBEAEMALQAwADAAMQAEABwAYwBvAG0AZQB0AG4AZQB0AC4AbABvAGMAYQBsAAMAOABWAEkALQBSAEkAQwBLAEQAQwAtADAAMAAxAC4AYwBvAG0AZQB0AG4AZQB0AC4AbABvAGMAYQBsAAUAHABjAG8AbQBlAHQAbgBlAHQALgBsAG8AYwBhAGwAAAAAAA== 
Cache-Control: no-cache 
Pragma: no-cache 
Content-Type: text/html; charset=utf-8 
Proxy-Connection: Keep-Alive 
Set-Cookie: BCSI-CS-36204A5A7BBD24D9=2; Path=/ 
Connection: Keep-Alive 
Content-Length: 1074 
Proxy-Support: Session-Based-Authentication 

[...] 

第三请求:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://tempuri.org/MyMethod" 
Accept-Encoding: gzip, deflate,gzip, deflate,gzip, deflate 
Proxy-Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHgAAAAYABgAkAAAABAAEABIAAAADgAOAFgAAAASABIAZgAAAAAAAACoAAAABYKIogUBKAoAAAAPQwBPAE0ARQBUAE4ARQBUAFAAYQByAHMAbwBuAEoAVwBTAFIASwAwADQAOAA3ADAAlap7g+mPRMEAAAAAAAAAAAAAAAAAAAAARLAhi5lf3nd+l9xENAcu2W6xf6iJbyM6 
Host: www.myservice.com 
Content-Length: 329 
Expect: 100-continue 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>[...]</s:Body></s:Envelope> 

接收:

HTTP/1.1 401 Unauthorized 
Content-Type: text/html 
Server: Microsoft-IIS/6.0 
WWW-Authenticate: Basic realm="myrealm" 
X-Powered-By: ASP.NET 
Date: Tue, 31 May 2011 13:09:33 GMT 
Cache-Control: proxy-revalidate 
Content-Length: 1656 
Proxy-Connection: Keep-Alive 
Connection: Keep-Alive 
Proxy-support: Session-based-authentication 
Age: 0 

[...] 

第四请求:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://tempuri.org/MyMethod" 
Accept-Encoding: gzip, deflate,gzip, deflate,gzip, deflate,gzip, deflate 
Authorization: Basic Y29nZW50YVxjb21ldC1kbTM6Kmh0JTg2NCU= 
Proxy-Authorization: NTLM TlRMTVNTUAABAAAAB7IIoggACAAxAAAACQAJACgAAAAFASgKAAAAD1dTUkswNDg3MENPTUVUTkVU 
Host: www.myservice.com 
Content-Length: 0 

接收:

HTTP/1.1 400 Bad Request 
Date: Tue, 31 May 2011 13:09:33 GMT 
Server: Microsoft-IIS/6.0 
X-Powered-By: ASP.NET 
X-AspNet-Version: 4.0.30319 
Cache-Control: private, proxy-revalidate 
Content-Length: 0 
Proxy-Connection: Keep-Alive 
Connection: Keep-Alive 
Age: 0 

我不明白为什么它不会在第四请求发送信封。两个握手都完成了,所以理论上一切都应该没问题。

1日要求:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://tempuri.org/MyMethod" 
Host: www.myservice.com 
Content-Length: 329 
Expect: 100-continue 
Accept-Encoding: gzip, deflate 
Connection: Keep-Alive 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>[...]</s:Body></s:Envelope> 

接收:

HTTP/1.1 401 Unauthorized 
Content-Length: 1656 
Content-Type: text/html 
Server: Microsoft-IIS/6.0 
WWW-Authenticate: Basic realm="myrealm" 
X-Powered-By: ASP.NET 
Date: Tue, 31 May 2011 13:31:46 GMT 

[...] 

当我这样做本地没有NTLM代理,如预期的信封被发送

2nd re任务奖励:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://tempuri.org/MyMethod" 
Accept-Encoding: gzip, deflate,gzip, deflate 
Authorization: Basic Y29nZW50YVxjb21ldC1kbTM6Kmh0JTg2NCU= 
Host: www.myservice.com 
Content-Length: 329 
Expect: 100-continue 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>[...]</s:Body></s:Envelope> 

接收:

HTTP/1.1 200 OK 
Date: Tue, 31 May 2011 13:31:47 GMT 
Server: Microsoft-IIS/6.0 
X-Powered-By: ASP.NET 
X-AspNet-Version: 4.0.30319 
Set-Cookie: ASP.NET_SessionId=svv4i11awg05v1j5viz1impo; path=/; HttpOnly 
Cache-Control: private, max-age=0 
Content-Type: text/xml; charset=utf-8 
Content-Length: 5127 

[...] 
+0

您用来发送这些请求的客户端库是什么?有些请求看起来是不正常的:例如,发送expect:continue标头和POST数据。 – 2011-06-02 15:39:27

+0

我正在使用.NET WCF服务参考。有一个Sytem.ServiceModel对象。 – Edgar 2011-06-02 15:46:42

+0

这比我在.Net中使用NTLM更进一步,你能够回答http://stackoverflow.com/questions/4723062吗? – Keith 2011-06-06 10:44:24

回答

1

我不得不改变服务器的安全配置,以接受摘要式身份验证。基于某些原因,Basic不起作用。

1

我遇到了一个潜在的类似问题,并认为我的情况可能与建立到代理的原始NTLM连接有关。

根据我的经验,我有三个请求每小时顺序进行,并重新配置。

这些请求中有两个会工作,一个会失败,一个400,然后当第一个重试它也工作。

有一个与IE一个类似的问题在这里确定:http://blogs.msdn.com/b/asiatech/archive/2012/01/30/400-bad-request-when-posting-webservice-or-wcf-request-from-ie.aspx

我跑了一些网络跟踪,并观看行为,发现往往是TCP流似乎得到共享,从而使请求人会提早结束一个NTLM身份验证消息(零内容长度)在另一个身份验证之后发送给代理。在这种情况下,代理刚刚通过零内容消息(因为流已经过验证)。

我就要搬到一个WCF的自定义customBinding(使用textMessageEncodingSoap11一个messageVersion维护我basicHttpBinding行为)和(不知道如果需要的话)设置keepAliveEnabled为false什么固定它。

不幸的是我怀疑这对你的特殊情况有很大的帮助,但是更多的信息永远不会伤害你。