2011-05-31 70 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什麼固定它。

不幸的是我懷疑這對你的特殊情況有很大的幫助,但是更多的信息永遠不會傷害你。