2008-12-27 93 views
25

我已經編寫了一個非常簡單的WCF服務來發送和接收消息。我已通過VS 2008默認Web服務器主機測試了該應用程序,並且一切正常。但是,當我將WCF服務部署到另一臺計算機的IIS時,我收到以下錯誤:WCF:由於驗證失敗,無法滿足安全令牌請求

「由於驗證失敗,無法滿足安全令牌請求。」

如何設置使用個性化的用戶名和密碼在配置文件中的身份驗證類型? 如果這是不可能的,請告訴我如何設置其Windows憑據,因爲我使用的2臺計算機不共享相同的用戶。

回答

32

您需要關閉綁定的安全性。否則,我相信,默認情況下,wsHttpBinding將嘗試協商安全上下文令牌(SCT)。

所以,修改端點定義爲指向的結合配置部分。這裏有一個例子:

<endpoint address="" 
      binding="wsHttpBinding" 
      contract="HelloWorldService.IService1" 
      bindingConfiguration="TheBindingConfig"> 

然後在web.config中的<system.serviceModel>部分<services>節之後添加類似以下的綁定配置。

將安全設置爲「無」是關鍵。

希望這有助於!


上面幫我 - 但究竟是不是立即明顯的是如何添加到服務末(其明確的,一旦你已經做了什麼需要,但直到你已經這樣做了)。其原因並不完全明顯是因爲缺省情況下沒有綁定部分,而客戶端中可能存在綁定部分。

所以,只需要非常清楚 - 在服務端,添加綁定部分(如上所述),然後添加到適當的端點添加bindingConfiguration =「TheBindingConfig」屬性。很明顯,一旦你已經做了一次......

+4

我認爲這是一個不好的答案automiticaly去關閉安全 – TruthOf42 2013-11-01 20:32:51

12

一定要客戶端和服務器上設置此bindingConfiguration(指定安全模式「無」),否則你會得到這樣的信息 - 這是一個相當紅鯡魚至於調試問題。

The message could not be processed. This is most likely because the action ' http://tempuri.org/IInterfaceName/OperationName ' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

20

您實際上並不需要關閉安全性,在某些情況下您不應該關閉安全性。在一個bindingConfiguration,您可以指定消息級安全性進行如下的不建立安全上下文:

<security mode="Message"> 
    <transport clientCredentialType="Windows" proxyCredentialType="None" 
         realm="" /> 
    <message clientCredentialType="Windows" negotiateServiceCredential="true" 
     algorithmSuite="Default" establishSecurityContext="false" /> 
</security> 

注意establishSecurityContext屬性。客戶端和服務都應該具有安全配置,其中establishSecurityContext設置爲相同的值。 true值也可以正常工作,但在服務器負載均衡的環境中建議使用false。

+0

+1這是一個漂亮的第一篇文章先生! – 2010-11-16 16:09:19

0

如果你在調試模式,則默認設置調試屬性爲

<serviceDebug includeExceptionDetailInFaults="true"/> 

,而你去調試它拋出異常它設置爲假..所以。

希望它有幫助。

相關問題