【发布时间】:2011-01-18 12:50:56
【问题描述】:
我有一个第 3 方 SOAP Web 服务。我需要调用它的一种方法。请求需要签名。如何签署请求?
【问题讨论】:
我有一个第 3 方 SOAP Web 服务。我需要调用它的一种方法。请求需要签名。如何签署请求?
【问题讨论】:
我假设您签署的意思是您使用安装在客户端的证书签署消息。
在 WCF 中执行此操作相对容易。假设您在security element 中使用wsHttpBinding,则必须将模式设置为SecurityMode.Message。您还必须将clientCredentialType of the message element 设置为MessageCredentialType.Certificate。
然后,您必须设置端点行为并配置 clientCertificate element(它是 clientCredentials element 的子代)以指示客户端证书的存储位置。
即使您不使用 wsHttpBinding,当您想使用客户端证书提供消息级安全性时,大多数其他绑定的配置也几乎相同。
如果您通过 HTTPS 进行调用,请注意您必须将安全元素上的模式属性设置为 Mode.TransportWithMessageCredential。
【讨论】:
以下是关于使用 WCF 使用需要签名的 Amazon SOAP 服务的问题。我认为答案提供了一个很好的例子,这可能对您的情况有所帮助。
How to sign an Amazon web service request in .NET with SOAP and without WSE
编辑:对于另一个 StackOverflow 问题的链接,显然存在一些混淆。我想指出投票率最高的答案。它绝对是一个 WCF 解决方案。您会注意到类 SigningMessageInspector 继承自 IClientMessageInspector(一个 WCF 接口)。我认为本节可能会对您有所帮助。
【讨论】:
基于来自@casperOne 的非常有用的答案,我最终得到了以下配置:
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding>
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<!-- specifies the endpoint to use when calling the service -->
<endpoint address="https://SomeEndPointUrl/v1"
binding="wsHttpBinding"
behaviorConfiguration="SigningCallback"
contract="ServiceReference1.EboxMessagePortType" name="MyBindingConfig">
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="SigningCallback">
<clientCredentials>
<clientCertificate findValue="*somecertsubjectname*"
storeLocation="LocalMachine"
storeName="TrustedPublisher"
x509FindType="FindBySubjectName"
/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
这适用于 https 上的肥皂客户端
【讨论】: