因此,我一直在嘗試爲我的客戶端和服務設置證書身份驗證。最終的目標是根據客戶端連接的證書對數據進行分區(即,證書成爲他們對較大系統的憑證,並且他們的數據基於這些憑證進行分區)。WCF:使用客戶端時的SecurityNegotiationException
我已經能夠在客戶端和服務器端成功設置它。我創建了一個證書和一個私鑰,將它們安裝在我的計算機上,並設置了我的服務器,以便1)它具有基於證書的服務憑證和2)如果客戶端連接了而沒有提供基於證書的憑證和拋出異常。
然後我做的是創建一個簡單的客戶端,並將證書憑證添加到配置中,並嘗試調用該服務的簡單操作。
它看起來像客戶端連接OK,它看起來像證書服務器接受,但我得到這個:
SecurityNegotiationException:
「對方沒有被驗證服務。」
這對我來說似乎很模糊。請注意,我正在使用wsHttpBinding,它被認爲默認爲Windows身份驗證以用於傳輸安全性...但所有這些進程都以我的用戶帳戶運行,正如我在調試環境中運行的那樣。
這裏是我的服務器配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyServiceBinding">
<security mode="Message">
<transport clientCredentialType="None"/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint binding="wsHttpBinding" bindingConfiguration="MyServiceBinding" contract="IMyContract"/>
<endpoint binding="mexHttpBinding" address="mex" contract="IMetadataExchange">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<serviceCertificate storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" findValue="tmp123"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
這裏是我的客戶端配置 - 請注意,我用的是我的服務使用客戶端相同的證書:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Message">
<!--<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>-->
<message clientCredentialType="Certificate" negotiateServiceCredential="true" algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50120/UserServices.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService" behaviorConfiguration="IMyService_Behavior" contract="UserServices.IUserServices" name="WSHttpBinding_IMyService">
<identity>
<certificate encodedValue="Some RSA stuff"/>
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="IMyService_Behavior">
<clientCredentials>
<clientCertificate storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" findValue="tmp123"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
任何人都可以請幫助提供一些有關可能會在這裏的一些見解?
感謝,
是的,我試圖刪除,無濟於事 - 同樣的問題。我也嘗試爲客戶生成一個證書,併爲該服務頒發證書,但也無濟於事。 我想知道該服務如何知道接受哪些證書......在配置中沒有映射,它看起來像......它只是對運行該服務的用戶的可信任證書? – 2010-04-16 16:24:09