[英]WCF Security in a Windows Service
我有一個WCF服務,可以作為控制台應用程序和Windows服務運行。 我最近將控制台應用程序復制到具有以下安全設置的W2K3服務器:
<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服務訪問系統資源有關。 我嘗試在與控制台應用程序相同的帳戶下運行它,但沒有運氣。 有沒有人有任何想法?
這是一個有時與安全無關的錯誤。
我建議你首先嘗試在沒有安全性的情況下使用它,然后只使用消息安全性,然后使用傳輸,最后使用TransportWithMessageCredential。
此外,如果您在同一台計算機上運行控制台應用程序和Windows服務應用程序,請確保在啟動Windows服務之前停止控制台應用程序,以避免端口沖突
啟用服務診斷。 這應該讓你很好地了解服務是否甚至接收消息以及服務拋出異常的位置。
更新 - 我將customUserNamePasswordValidatorType從Custom更改為Windows。 這在Console和Windows服務中都運行良好。 我只能假設自定義驗證器中的某些內容導致了問題。
自定義驗證程序使用App.config中的自定義配置部分來驗證用戶標識和密碼。 我原本以為這可以從Windows服務工作。
感謝所有發表回復的人。
您正在使用自定義用戶/名稱驗證程序 - Windows服務是否可以訪問該文件?
您在哪個帳戶下運行NT服務?
是否可以關閉所有安全措施? (只是看看)
渣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.