WCF分布式开发常见错误(26):Authentication failed
生活随笔
收集整理的這篇文章主要介紹了
WCF分布式开发常见错误(26):Authentication failed
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這個也是WCF分布式安全開發(fā)實踐過程里常見的錯誤。? 驗證失敗,因為遠端已經關閉傳輸流。
??? WCF 傳輸安全模式下,客戶端和服務器端使用證書進行驗證。WSHttpBinding.啟動服務宿主程序。
??? 在進行客戶端添加服務引用的時候遇到的錯誤。導致客戶端無法添加服務元數據引用。這個問題我查找完畢后解決了。現在整理一下好給大家參考。
【1】錯誤信息:
??? There was an error downloading 'https://frank-xu2009:8001/mex'.
The underlying connection was closed: An unexpected error occurred on a send.
Authentication failed because the remote party has closed the transport stream.
Metadata contains a reference that cannot be resolved: 'https://frank-xu2009:8001/mex'.
An error occurred while making the HTTP request to https://frank-xu2009:8001/mex.
??? This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.The underlying connection was closed: An unexpected error occurred on a send.
Authentication failed because the remote party has closed the transport stream.
If the service is defined in the current solution, try building the solution and adding the service reference again.
【2】中文翻譯:
??? 從'https://frank-xu2009:8001/mex'下載時出現錯誤。
??基礎連接關閉:一個意外錯誤發(fā)生在發(fā)送時。
? 驗證失敗因為遠端關閉了傳輸流。
? 元數據包含的引用不能解析'https://frank-xu2009:8001/mex',
??當向https://frank-xu2009:8001/mex發(fā)送HTTP請求的時候出現錯誤。
??這個可能是由于服務器證書沒有與HTTP.SYS正確配置。
??這個可能是由于客戶端和服務端之間的綁定不匹配所致,基礎連接關閉:一個意外錯誤發(fā)生在發(fā)送時。
驗證失敗因為遠端關閉了傳輸流。? 如果服務業(yè)在此解決方案里定義,請編譯此解決方案然后重新添加服務引用。
【3】問題分析:
???? 和這個問題的解決方式一樣:http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/54450aa5-27c8-480b-bcfb-e51f7a1e9e35。
??? 主要還是證書的設置不對。客戶端提供的證書出錯。制作的客戶端證書要安裝到服務器證書信任的存儲區(qū)。
【4】解決步驟:
??? 修改sky選項為exchange,可以交換密鑰。因為要導出帶密鑰的證書,要安裝到信任的證書機構和信任的人。
1.制作一個證書。制作證書:makecert -sr localmachine -ss My -n CN=MyClientCer -sky exchange -pe -r。http://msdn.microsoft.com/zh-cn/library/aa702761.aspx
2.導出證書文件,帶密鑰的pfx文件。使用mmc
3.導入證書到信任的人。
4.導入證書到信任的機構,這個證書就被信任了。
【4.1】制作和設置信任證書:
(1)使用makecert 工具:Microsoft Visual Studio 2008-->Visual Studio Tools-->Visual Studio 2008 命令提示行。
輸入:makecert -sr localmachine -ss My -n CN=WCFServerPK -sky exchange -pe -r<?XML:NAMESPACE PREFIX = O />
輸入:makecert -sr localmachine -ss My -n CN=WCFClientPK -sky exchange -pe -r。
-這里制作了連個證書,主要只使用一個WCFServerPK,可以到出密鑰文件pfx,后續(xù)我們要導入到其他存儲區(qū),設置為信任的證書。WCFClientPK?-是為以后文章準備的,也是可以設置為信任的證書。
?(2)?打開瀏覽器---->Internet 選項----->內容----->證書----->個人,默認是保存到當前用戶CurrentUser,你會看到剛才制作的證書。這個可以查看部分證書,但是功能有限。我們還是使用控制臺證書管理工具。 (3)使用MMC建立證書控制單元查看證書的信息:
??開始--運行--MMC--控制臺--添加刪除單元--證書--當前用戶和計算機各添加一個。能查看和管理CurrentUser和LocalMachine的證書。如圖:
(4)導入證書到信任的人和信任的CA機構里。步驟如下:
??? 1.導出證書文件,帶密鑰的pfx文件。使用mmc,保存到桌面位置(方便查找)。這里記住你制作證書的密碼。要使用。
??? 2.導入證書到信任的人。使用任務-導入向導--選擇證書文件,導入即可。
??? 3.導入證書到信任的機構,使用任務-導入向導--選擇證書文件,導入即可。這個證書就被信任了。
【4.2】查詢SSL證書設置:
???? 需要為使用的端口SSL注冊證書。Windows Server 2003 或 Windows XP,則使用 HttpCfg.exe 工具。Windows Server 2003 中已安裝該工具。下載該工具/Files/frank_xl/HttpcfgFrankXuLei.rar。如果運行的是 Windows Vista,則使用已安裝的 Netsh.exe 工具。在Windows\System32目錄下。運行此工具需要命令窗口切換到相應工具解壓縮目錄下,我直接放置到D盤根目錄。方便查找。
???? (1)在 Windows Server 2003 或 Windows XP 中,通過 query 和 ssl 開關使用 HttpCfg.exe 工具查看當前端口配置,在命令窗口切換到HttpCfg在文件目錄,你如下面代碼:
httpcfg query ssl
??(2)Vista:
netsh http show sslcert
【4.3】設置SSL證書:
(1)在 Windows Server 2003 或 Windows XP:
httpcfg set ssl -i 0.0.0.0:9001-h 9174185b2860b6d5ec3de133d5fcc4e1419b09e5
(2)Vista:
netsh http add sslcert ipport=0.0.0.0:9001 certhash=9174185b2860b6d5ec3de133d5fcc4e1419b09e5
? appid={11111111-2222-3333-4444-qqqqqqqqqqqqq} 。最后一個GUID.你可以隨便編寫一個。使用工具也可以。certhash 參數指定證書的指紋。ipport 參數指定 IP 地址和端口,功能類似于前述 Httpcfg.exe 工具的 -i 開關。appid 參數為可用于標識所屬應用程序的 GUID。
【4.4】刪除SSL證書:
(1)Windows Server 2003 和 Windows XP 中:
httpcfg delete ssl -i 0.0.0.0:9001-h 9174185b2860b6d5ec3de133d5fcc4e1419b09e5
(2)Vista:
Netsh http delete sslcert ipport=0.0.0.0:9001。
【4.5】服務器端證書設置: system.serviceModel>
????<services>
??????<service?behaviorConfiguration="WCFService.WCFServiceBehavior"?name="WCFService.WCFService"?>
????????<endpoint?
??????????address="WCFService"?
??????????binding="wsHttpBinding"?
??????????bindingConfiguration="BindingConfiguration"
??????????contract="WCFService.IWCFService">
????????</endpoint>
????????<endpoint?address="mex"?binding="mexHttpsBinding"?contract="IMetadataExchange"?/>
????????<host>
??????????<baseAddresses>
????????????<add?baseAddress="https://computer:9001/"/>
??????????</baseAddresses>
????????</host>
??????</service>
????</services>
????<behaviors>
??????<serviceBehaviors>
????????<behavior?name="WCFService.WCFServiceBehavior">
??????????<serviceMetadata?httpsGetEnabled="true"?/>
??????????<serviceDebug?includeExceptionDetailInFaults="false"?/>
??????????<serviceCredentials>
??????????????<serviceCertificate??storeName="My"??x509FindType="FindBySubjectName"?findValue="WCFServerPK"?storeLocation="LocalMachine"/>
??????????</serviceCredentials>
????????</behavior>
??????</serviceBehaviors>
????</behaviors>
????<bindings>
????<wsHttpBinding>
??????<binding?name="BindingConfiguration">
????????<security?mode="Transport">
??????????<transport?clientCredentialType="Certificate"/>
????????</security>
??????</binding>
????</wsHttpBinding>
????</bindings>
??</system.serviceModel>
?? 這里服務器需要導入客戶的證書。?過程一樣。? 由于我們開發(fā)制作的都是臨時證書,所以猶豫證書設置或者信任問題導致的安全錯誤最多。有問題可以參考WCF分布式安全開發(fā)實踐(5):傳輸安全模式之Certificate身份驗證:Transport_Certificate_WSHttpBinding 的具體步驟。
??
參考資料:
1.http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/ce445c55-f549-4207-956e-c75c1805e15b
??? WCF 傳輸安全模式下,客戶端和服務器端使用證書進行驗證。WSHttpBinding.啟動服務宿主程序。
??? 在進行客戶端添加服務引用的時候遇到的錯誤。導致客戶端無法添加服務元數據引用。這個問題我查找完畢后解決了。現在整理一下好給大家參考。
【1】錯誤信息:
??? There was an error downloading 'https://frank-xu2009:8001/mex'.
The underlying connection was closed: An unexpected error occurred on a send.
Authentication failed because the remote party has closed the transport stream.
Metadata contains a reference that cannot be resolved: 'https://frank-xu2009:8001/mex'.
An error occurred while making the HTTP request to https://frank-xu2009:8001/mex.
??? This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.The underlying connection was closed: An unexpected error occurred on a send.
Authentication failed because the remote party has closed the transport stream.
If the service is defined in the current solution, try building the solution and adding the service reference again.
【2】中文翻譯:
??? 從'https://frank-xu2009:8001/mex'下載時出現錯誤。
??基礎連接關閉:一個意外錯誤發(fā)生在發(fā)送時。
? 驗證失敗因為遠端關閉了傳輸流。
? 元數據包含的引用不能解析'https://frank-xu2009:8001/mex',
??當向https://frank-xu2009:8001/mex發(fā)送HTTP請求的時候出現錯誤。
??這個可能是由于服務器證書沒有與HTTP.SYS正確配置。
??這個可能是由于客戶端和服務端之間的綁定不匹配所致,基礎連接關閉:一個意外錯誤發(fā)生在發(fā)送時。
驗證失敗因為遠端關閉了傳輸流。? 如果服務業(yè)在此解決方案里定義,請編譯此解決方案然后重新添加服務引用。
【3】問題分析:
???? 和這個問題的解決方式一樣:http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/54450aa5-27c8-480b-bcfb-e51f7a1e9e35。
??? 主要還是證書的設置不對。客戶端提供的證書出錯。制作的客戶端證書要安裝到服務器證書信任的存儲區(qū)。
【4】解決步驟:
??? 修改sky選項為exchange,可以交換密鑰。因為要導出帶密鑰的證書,要安裝到信任的證書機構和信任的人。
1.制作一個證書。制作證書:makecert -sr localmachine -ss My -n CN=MyClientCer -sky exchange -pe -r。http://msdn.microsoft.com/zh-cn/library/aa702761.aspx
2.導出證書文件,帶密鑰的pfx文件。使用mmc
3.導入證書到信任的人。
4.導入證書到信任的機構,這個證書就被信任了。
【4.1】制作和設置信任證書:
(1)使用makecert 工具:Microsoft Visual Studio 2008-->Visual Studio Tools-->Visual Studio 2008 命令提示行。
輸入:makecert -sr localmachine -ss My -n CN=WCFServerPK -sky exchange -pe -r<?XML:NAMESPACE PREFIX = O />
輸入:makecert -sr localmachine -ss My -n CN=WCFClientPK -sky exchange -pe -r。
-這里制作了連個證書,主要只使用一個WCFServerPK,可以到出密鑰文件pfx,后續(xù)我們要導入到其他存儲區(qū),設置為信任的證書。WCFClientPK?-是為以后文章準備的,也是可以設置為信任的證書。
?(2)?打開瀏覽器---->Internet 選項----->內容----->證書----->個人,默認是保存到當前用戶CurrentUser,你會看到剛才制作的證書。這個可以查看部分證書,但是功能有限。我們還是使用控制臺證書管理工具。 (3)使用MMC建立證書控制單元查看證書的信息:
??開始--運行--MMC--控制臺--添加刪除單元--證書--當前用戶和計算機各添加一個。能查看和管理CurrentUser和LocalMachine的證書。如圖:
(4)導入證書到信任的人和信任的CA機構里。步驟如下:
??? 1.導出證書文件,帶密鑰的pfx文件。使用mmc,保存到桌面位置(方便查找)。這里記住你制作證書的密碼。要使用。
??? 2.導入證書到信任的人。使用任務-導入向導--選擇證書文件,導入即可。
??? 3.導入證書到信任的機構,使用任務-導入向導--選擇證書文件,導入即可。這個證書就被信任了。
【4.2】查詢SSL證書設置:
???? 需要為使用的端口SSL注冊證書。Windows Server 2003 或 Windows XP,則使用 HttpCfg.exe 工具。Windows Server 2003 中已安裝該工具。下載該工具/Files/frank_xl/HttpcfgFrankXuLei.rar。如果運行的是 Windows Vista,則使用已安裝的 Netsh.exe 工具。在Windows\System32目錄下。運行此工具需要命令窗口切換到相應工具解壓縮目錄下,我直接放置到D盤根目錄。方便查找。
???? (1)在 Windows Server 2003 或 Windows XP 中,通過 query 和 ssl 開關使用 HttpCfg.exe 工具查看當前端口配置,在命令窗口切換到HttpCfg在文件目錄,你如下面代碼:
httpcfg query ssl
??(2)Vista:
netsh http show sslcert
【4.3】設置SSL證書:
(1)在 Windows Server 2003 或 Windows XP:
httpcfg set ssl -i 0.0.0.0:9001-h 9174185b2860b6d5ec3de133d5fcc4e1419b09e5
(2)Vista:
netsh http add sslcert ipport=0.0.0.0:9001 certhash=9174185b2860b6d5ec3de133d5fcc4e1419b09e5
? appid={11111111-2222-3333-4444-qqqqqqqqqqqqq} 。最后一個GUID.你可以隨便編寫一個。使用工具也可以。certhash 參數指定證書的指紋。ipport 參數指定 IP 地址和端口,功能類似于前述 Httpcfg.exe 工具的 -i 開關。appid 參數為可用于標識所屬應用程序的 GUID。
【4.4】刪除SSL證書:
(1)Windows Server 2003 和 Windows XP 中:
httpcfg delete ssl -i 0.0.0.0:9001-h 9174185b2860b6d5ec3de133d5fcc4e1419b09e5
(2)Vista:
Netsh http delete sslcert ipport=0.0.0.0:9001。
【4.5】服務器端證書設置: system.serviceModel>
????<services>
??????<service?behaviorConfiguration="WCFService.WCFServiceBehavior"?name="WCFService.WCFService"?>
????????<endpoint?
??????????address="WCFService"?
??????????binding="wsHttpBinding"?
??????????bindingConfiguration="BindingConfiguration"
??????????contract="WCFService.IWCFService">
????????</endpoint>
????????<endpoint?address="mex"?binding="mexHttpsBinding"?contract="IMetadataExchange"?/>
????????<host>
??????????<baseAddresses>
????????????<add?baseAddress="https://computer:9001/"/>
??????????</baseAddresses>
????????</host>
??????</service>
????</services>
????<behaviors>
??????<serviceBehaviors>
????????<behavior?name="WCFService.WCFServiceBehavior">
??????????<serviceMetadata?httpsGetEnabled="true"?/>
??????????<serviceDebug?includeExceptionDetailInFaults="false"?/>
??????????<serviceCredentials>
??????????????<serviceCertificate??storeName="My"??x509FindType="FindBySubjectName"?findValue="WCFServerPK"?storeLocation="LocalMachine"/>
??????????</serviceCredentials>
????????</behavior>
??????</serviceBehaviors>
????</behaviors>
????<bindings>
????<wsHttpBinding>
??????<binding?name="BindingConfiguration">
????????<security?mode="Transport">
??????????<transport?clientCredentialType="Certificate"/>
????????</security>
??????</binding>
????</wsHttpBinding>
????</bindings>
??</system.serviceModel>
?? 這里服務器需要導入客戶的證書。?過程一樣。? 由于我們開發(fā)制作的都是臨時證書,所以猶豫證書設置或者信任問題導致的安全錯誤最多。有問題可以參考WCF分布式安全開發(fā)實踐(5):傳輸安全模式之Certificate身份驗證:Transport_Certificate_WSHttpBinding 的具體步驟。
??
參考資料:
1.http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/ce445c55-f549-4207-956e-c75c1805e15b
總結
以上是生活随笔為你收集整理的WCF分布式开发常见错误(26):Authentication failed的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Dns服务器与iptables的问题【已
- 下一篇: SICP学习笔记(1.1.4~1.1.5