2 回答

TA貢獻1799條經驗 獲得超9個贊
...通常情況下,我的配置錯誤。我獲得了一個名為“MaternumCertificateClient”的證書,而不是我的服務器配置的證書,即“MaternumCertificateServer”。
更重要的是我是如何得出這個錯誤的。
第一步,我設置 Wireshark 以查看服務器的回復內容:
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/10.0
Set-Cookie: ASP.NET_SessionId=k0xmopx3eitnvmocv1rjas4h; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcREVWXE1BVFxNYXRlcm51bV9hcHBcc2VydmljZXNcTWF0ZXJudW1QZGZTZXJ2aWNlLnN2Y1xzb2Fw?=
X-Powered-By: ASP.NET
Date: Thu, 22 Aug 2019 16:25:19 GMT
Content-Length: 648
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
? ? <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
? ? <a:RelatesTo>urn:uuid:uid is here</a:RelatesTo>
</s:Header>
<s:Body>
? ? <s:Fault>
? ? ? ? <s:Code>
? ? ? ? ? ? <s:Value>s:Sender</s:Value>
? ? ? ? ? ? <s:Subcode>
? ? ? ? ? ? ? ? <s:Value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</s:Value>
? ? ? ? ? ? </s:Subcode>
? ? ? ? </s:Code>
? ? ? ? <s:Reason>
? ? ? ? ? ? <s:Text xml:lang="en-GB">An error occurred when verifying security for the message.</s:Text>
? ? ? ? </s:Reason>
? ? </s:Fault>
</s:Body>
</s:Envelope>
好不了多少,但我至少知道是誰拋出了異常。
因此,正如所示,我使用以下內容設置我的服務器:
<serviceSecurityAudit?auditLogLocation=“Application“? ????serviceAuthorizationAuditLevel=“Failure“? ????messageAuthenticationAuditLevel=“Failure“? ????suppressAuditFailure=“true“?/>
在配置/system.serviceModel/behaviors/serviceBehaviors/behavior。
然后,Windows 事件查看器會顯示有關該錯誤的詳細信息。
顯示的消息,
MessageSecurityException:?The?EncryptedKey?clause?was?not?wrapped?with?the?required?encryption?token?'System.IdentityModel.Tokens.X509SecurityToken'.
表示證書不匹配。我正在加載一個名為 MaternumCertificateClient 的證書,并且我需要 MaternumCertificateServer。此外,這些行
pdfService.ClientCredentials.ClientCertificate.Certificate?=?cert; pdfService.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode?=?X509CertificateValidationMode.PeerTrust; pdfService.ClientCredentials.ServiceCertificate.DefaultCertificate?=?GetCertificate("MaternumCertificateClient");
實際上并不需要;證書是從端點的身份中讀取的,并且我的設置不需要這些設置即可工作。

TA貢獻1770條經驗 獲得超3個贊
正如您所指出的,除了我們使用證書對客戶端進行身份驗證之外,不需要在客戶端提供證書。比如下面的配置。
<wsHttpBinding>?? ????<binding?name="WSHttpBinding_ICalculator">?? ??????<security?mode="Message">?? ????????<message?clientCredentialType="Certificate"?/>?? ??????</security>?? ????</binding>?? ??</wsHttpBinding>
在服務器端的綁定配置中,只有用戶名/密碼需要憑證。
??<security> ????<message?clientCredentialType="UserName"?negotiateServiceCredential="false" ??????establishSecurityContext="false"?/> ??</security>
證書通過使用公鑰加密 SOAP 消息來提供消息安全性。在通信過程中,客戶端和服務器端交換證書的公鑰。我們甚至可以指定服務器域名作為身份,它只是用來保證服務器的身份。
另外,如果你的回復解決了你的問題。請標記為有用,以便幫助遇到類似問題的其他人。
如果有什么需要我幫忙的,請隨時告訴我。
- 2 回答
- 0 關注
- 150 瀏覽
添加回答
舉報