2009-10-13 77 views
5

我有一個可以作爲控制檯應用程序和Windows服務運行的WCF服務。我最近複製的控制檯應用程序多達W2K3服務器有下列安全設置:Windows服務中的WCF安全

<wsHttpBinding> 
<binding name="ServiceBinding_Security" transactionFlow="true" > 
    <security mode="TransportWithMessageCredential" > 
    <message clientCredentialType="UserName" /> 
    </security>   
</binding>    
</wsHttpBinding> 

<serviceCredentials> 
<userNameAuthentication userNamePasswordValidationMode="Custom" 
    customUserNamePasswordValidatorType="Common.CustomUserNameValidator, Common" /> 
</serviceCredentials> 

安全工作正常,沒有任何問題。我有完全相同的代碼,但在Windows服務運行,我收到以下錯誤,當我嘗試調用任何方法從客戶端:

System.ServiceModel.Security.MessageSecurityException was unhandled 
Message="An unsecured or incorrectly secured fault was received from 
     the other party. See the inner FaultException for the fault code and detail." 
    Source="mscorlib" 
    StackTrace: 
    Server stack trace: 
     at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout) 
     ...... 
    (lots of stacktrace info - not very useful) 

    InnerException: System.ServiceModel.FaultException 
     Message="An error occurred when verifying security for the message." 

例外告訴我什麼。我假設它與來自Windows服務的系統資源的訪問有關。我已經嘗試在與控制檯應用程序相同的帳戶下運行它,但沒有運氣。有沒有人有任何想法?

+0

哎喲,這讓我頭疼...... – James 2009-10-13 15:20:26

+0

安全信息是: <的wsHttpBinding> <綁定名稱= 「ServiceBinding_Security」 transactionFlow = 「真」> <安全模式= 「TransportWithMessageCredential」> \t <消息clientCredentialType = 「用戶名」/> \t \t \t \t \t \t \t Alphonso 2009-10-13 15:21:20

回答

0

您正在使用自定義用戶/名稱驗證程序 - Windows服務是否可以訪問該文件?

你在哪個帳戶下運行NT服務?

它是否可以在所有安全關閉的情況下工作? (只是爲了看)

Marc

+0

診斷錯誤消息=安全協議不能驗證傳入消息。沒有其他的。 我可以確認服務工作沒有安全。 我試過在「本地系統」和「管理員」下運行服務 自定義名稱驗證器正在根據app.config中的自定義部分進行驗證。 – Alphonso 2009-10-13 16:33:55

1

這是一個有時與安全無關的錯誤。

我建議你先嚐試讓它在沒有安全性的情況下工作,然後只是使用消息安全性,然後使用傳輸,最後使用TransportWithMessageCredential。

此外,如果你正在運行控制檯應用程序,並在同一臺機器上的Windows服務程序確保在啓動Windows服務之前停止控制檯應用程序,爲了避免端口衝突

1

上的服務啓用診斷。這應該給你一個很好的想法,即服務是否接收到消息,服務在哪裏拋出異常。

1

更新 - 我將CustomUserNamePasswordValidatorType從Custom更改爲Windows。在控制檯和Windows服務中都可以正常工作。我只能假設自定義驗證器中的某些內容導致了問題。

自定義驗證程序在App.config中使用自定義配置節來驗證用戶標識和密碼。我原以爲這會從Windows服務工作。

感謝所有發佈回覆的人。