【问题标题】:How to sign a SOAP request with WCF如何使用 WCF 签署 SOAP 请求
【发布时间】:2011-01-18 12:50:56
【问题描述】:

我有一个第 3 方 SOAP Web 服务。我需要调用它的一种方法。请求需要签名。如何签署请求?

【问题讨论】:

    标签: c# .net wcf .net-3.5


    【解决方案1】:

    我假设您签署的意思是您使用安装在客户端的证书签署消息。

    在 WCF 中执行此操作相对容易。假设您在security element 中使用wsHttpBinding,则必须将模式设置为SecurityMode.Message。您还必须将clientCredentialType of the message element 设置为MessageCredentialType.Certificate

    然后,您必须设置端点行为并配置 clientCertificate element(它是 clientCredentials element 的子代)以指示客户端证书的存储位置。

    即使您不使用 wsHttpBinding,当您想使用客户端证书提供消息级安全性时,大多数其他绑定的配置也几乎相同。

    如果您通过 HTTPS 进行调用,请注意您必须将安全元素上的模式属性设置为 Mode.TransportWithMessageCredential。

    【讨论】:

    • 你是对的,我说的是使用位于发出请求的机器上的证书来签署请求。
    • 我使用的是 basicHttpBinding,因为这是该实用程序默认生成的内容,我只需在 web.config 中替换它即可将其切换为 wsHttpBinding。当我提出请求时,我收到错误消息:“请求已中止:无法创建 SSL/TLS 安全通道。”
    • @Mr Bell:您应该可以使用相同的属性在 basicHttpBinding 上设置安全模式。
    • 当我查看原始请求(来自跟踪文件)时,它没有提到任何关于签名的内容
    【解决方案2】:

    以下是关于使用 WCF 使用需要签名的 Amazon SOAP 服务的问题。我认为答案提供了一个很好的例子,这可能对您的情况有所帮助。

    How to sign an Amazon web service request in .NET with SOAP and without WSE

    编辑:对于另一个 StackOverflow 问题的链接,显然存在一些混淆。我想指出投票率最高的答案。它绝对是一个 WCF 解决方案。您会注意到类 SigningMessageInspector 继承自 IClientMessageInspector(一个 WCF 接口)。我认为本节可能会对您有所帮助。

    【讨论】:

    • 使用 WCF 也不行。
    • @casperOne - 在 Tim 的链接之后,一个大答案说“我最终更新了代码以使用 WCF ...”。那怎么不使用 WCF?
    • @Tim C:您发布链接时的唯一答案是:stackoverflow.com/questions/1204191/… 这绝对没有 WCF 解决方案。
    【解决方案3】:

    基于来自@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 上的肥皂客户端

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 2011-11-27
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      • 2010-11-15
      • 2011-07-26
      相关资源
      最近更新 更多