Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WCF客户端中对soap头进行签名_C#_Wcf_Soap_Client_Ws Security - Fatal编程技术网

C# 如何在WCF客户端中对soap头进行签名

C# 如何在WCF客户端中对soap头进行签名,c#,wcf,soap,client,ws-security,C#,Wcf,Soap,Client,Ws Security,我正在尝试调用web服务。格式良好的soap消息(来自服务规范)如下所示: <soapenv:Envelope xmlns:ebs="http://ebs.health.ontario.ca/" xmlns:edt="http://edt.health.ontario.ca/" xmlns:idp="http://idp.ebs.health.ontario.ca/" xmlns:msa="http://msa.ebs.health.ontario.ca/" xmlns:soapenv=

我正在尝试调用web服务。格式良好的soap消息(来自服务规范)如下所示:

 <soapenv:Envelope xmlns:ebs="http://ebs.health.ontario.ca/" xmlns:edt="http://edt.health.ontario.ca/" xmlns:idp="http://idp.ebs.health.ontario.ca/" xmlns:msa="http://msa.ebs.health.ontario.ca/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="X509-ED7F771775BF23B4CE137760623417313">MIICDzCCAXigAwIBAgIEUYu//zANBgkqhkiG9w0BAQQFADBMMQswCQYDVQQGEwJDQTETMBEGA1UECgwKREVOSVNfVGVzdDEoMCYGA1UEAxMfT05EMkMwMDczMTMwMy5jaWhzLmFkLmdvdi5vbi5jYTAeFw0xMzA1MDkxNTI1NTFaFw0xNDA1MDkxNTI1NTFaMEwxCzAJBgNVBAYTAkNBMRMwEQYDVQQKDApERU5JU19UZXN0MSgwJgYDVQQDEx9PTkQyQzAwNzMxMzAzLmNpaHMuYWQuZ292Lm9uLmNhMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCBDiEjn5QX0qL9Xgp1t1+y/nGmBke8oYqEybV0/slsffe7nmK//TqMxhDCxxYx1BiU/ddpxI8hlsLGVaGu/QfcBFYeGfTSQBQ+ZQNbp9D8O5I9T7Uds52dOljCq6fIgZ5eMFWKHL1zlm2VUOi19SS++HuhpDDsAgEClUCDYhs1BwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBABeuNnUGNWSlLHALdJMCdiU4C40+QXOrOwy5IB5rXA3RsQt0MPU7+FKCBClCcKrIJEKGZFrRg/axN0woiQhKPfcuOT7n1O8dvbXf5cGGR5l/kVDOO6DR2Mguo3jcKndVVpp0AjqI1jpxo1MkROJwbERtBqbjYRdOKyFexICVHN3k</wsse:BinarySecurityToken>
      <ds:Signature Id="SIG-30" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:SignedInfo>
          <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
            <ec:InclusiveNamespaces PrefixList="ebs edt idp msa soapenv" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
          </ds:CanonicalizationMethod>
          <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
          <ds:Reference URI="#TS-25">
            <ds:Transforms>
              <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                <ec:InclusiveNamespaces PrefixList="wsse ebs edt idp msa soapenv" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </ds:Transform>
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
            <ds:DigestValue>vVFQZIFYpfV/qk0X7lZpVuV9ao6Zckl4g78O+UXKCBE=</ds:DigestValue>
          </ds:Reference>
          <ds:Reference URI="#UsernameToken-26">
            <ds:Transforms>
              <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                <ec:InclusiveNamespaces PrefixList="ebs edt idp msa soapenv" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </ds:Transform>
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
            <ds:DigestValue>IqZOA4Ha1Ial3UqDc9Gl6wPLQF18xOSTBPR1/oj0mwY=</ds:DigestValue>
          </ds:Reference>
          <ds:Reference URI="#id-27">
            <ds:Transforms>
              <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                <ec:InclusiveNamespaces PrefixList="edt idp msa soapenv" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </ds:Transform>
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
            <ds:DigestValue>qHx6/vbUQhLVSqZmvJZSIEFXwSJ5TQhfgtJ3OfSnhdY=</ds:DigestValue>
          </ds:Reference>
          <ds:Reference URI="#id-28">
            <ds:Transforms>
              <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                <ec:InclusiveNamespaces PrefixList="ebs edt msa soapenv" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </ds:Transform>
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
            <ds:DigestValue>Mm83R8AW0mj1cGq4MwOxMiT9sI5nD8qo4KGcKfr/N8Q=</ds:DigestValue>
          </ds:Reference>
          <ds:Reference URI="#id-29">
            <ds:Transforms>
              <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                <ec:InclusiveNamespaces PrefixList="ebs edt idp msa" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </ds:Transform>
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
            <ds:DigestValue>f5Rcb1Z6o074KqaJDr7DDuIPIqaYS1OcYnZogVFWln0=</ds:DigestValue>
          </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue>
          Uue2z5y0zbmbiG2qYXm83L5WYTeDL6uMasDMo6Ns7KLUmRndX0Iv+XGuA6EIG4HEpeCpCsjjFaQ8
          m1wZbEg+uLjug7QlkdhMCTA6gXEdlzgl7p9IGbnHgTGjPuY+af57ArwMAgktr5FXTKXLEPMQHyg/
          Isi6r1c12vFdERUai7w=
        </ds:SignatureValue>
        <ds:KeyInfo Id="KI-ED7F771775BF23B4CE137760623417314">
          <wsse:SecurityTokenReference wsu:Id="STR-ED7F771775BF23B4CE137760623417315">
            <wsse:Reference URI="#X509-ED7F771775BF23B4CE137760623417313" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
          </wsse:SecurityTokenReference>
        </ds:KeyInfo>
      </ds:Signature>
      <wsse:UsernameToken wsu:Id="UsernameToken-26">
        <wsse:Username>username</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
      </wsse:UsernameToken>
      <wsu:Timestamp wsu:Id="TS-25">
        <wsu:Created>2013-08-27T12:23:54Z</wsu:Created>
        <wsu:Expires>2013-08-27T12:28:54Z</wsu:Expires>
      </wsu:Timestamp>
    </wsse:Security>
    <idp:IDP wsu:Id="id-28" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <ServiceUserMUID>282673</ServiceUserMUID>
    </idp:IDP>
    <ebs:EBS wsu:Id="id-27" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <SoftwareConformanceKey>1111</SoftwareConformanceKey>
      <AuditId>2222</AuditId>
    </ebs:EBS>
  </soapenv:Header>
  <soapenv:Body wsu:Id="id-29" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <edt:list>
      <resourceType>CL</resourceType>
      <pageNo>1</pageNo>
    </edt:list>
  </soapenv:Body>
</soapenv:Envelope>

这是一篇关于中国的文章,一篇关于中国的一篇文章,一篇关于中国的一篇文章,一篇关于中国的一篇文章,一篇关于中国的一篇文章,一篇关于中国的一篇文章,一篇关于中国的一篇文章,一篇关于中国的一篇文章,一篇关于中国的文章,一篇关于中国的一篇文章,一篇关于一篇关于中国的文章,一篇关于一篇关于中国的文章,一篇关于一篇关于中国的文章,一篇关于一篇关于中国的文章,一篇关于一篇关于中国的文章,一篇关于一篇关于中国的文章,一篇关于中国的文章,一篇关于一篇关于一篇关于中国的文章,一篇关于中国的文章,一篇关于一篇关于一篇关于中国的文章,一篇关于一篇关于一篇关于中国的文章,一篇关于中国的文章,一篇关于一篇关于一篇关于一篇关于中国的文章,一篇关于一篇关于中国的文章,一篇关于一篇关于中国QL9X这一领域的研究成果是一个非政府部门的研究。这一领域的研究成果是一个非政府部门的研究成果。这一领域的研究成果是一个非政府部门的QQFFFFFQQQQBQ(QQQBQQQQQBQ(QQQBQBQQQQBQBQQQQQBBBQQQQBBQ+是一个非政府部门的研究。他们的第二部分是一个数字是一个非非非政府的非政府的非政府的非非政府的非政府部门的非政府的非非政府的非政府的非非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非政府的非埃尔特比耶尔多基FexICVHN3k
vVFQZIFYpfV/qk0X7lZpVuV9ao6Zckl4g78O+UXKCBE=
IQZOA4HA1Il3UQDC9GL6WPLQF18XOSTBPR1/oj0mwY=
qHx6/VBUQHLVSQZMVJZSIEFXWSJ5TQHFGTJ3OFSNDY=
Mm83R8AW0mj1cGq4MwOxMiT9sI5nD8qo4KGcKfr/N8Q=
f5Rcb1Z6o074KqaJDr7DDuIPIqaYS1OcYnZogVFWln0=
UUE2Z5Y0ZMBIG2QYXM83L5WYTEDL6UMASDMO6NS7KLUMRNDX0IV+XGUA6EIG4EPECPCSJJFAQ8
m1wZbEg+ULJG7QLKDHMCTA6GXEDLZGL7P9IGBNHGTGJPUY+af57ArwMAgktr5FXTKXLEPMQHyg/
Isi6r1c12vFdERUai7w=
用户名
密码
2013-08-27T12:23:54Z
2013-08-27T12:28:54Z
282673
1111
'
配置为加密。考虑使用
SecurityVersion.WsSecurity11及更高版本,或使用传输安全性
加密完整消息

编辑:使用此EBS-EDT服务的详细解决方案

因为您只需要签名而不需要加密,所以请尝试在消息契约本身中指定:

[MessageHeader(ProtectionLevel=System.Net.Security.ProtectionLevel.Sign)]
谢谢,已经找到了)。在下一个问题上苦苦挣扎。。无论如何,非常感谢
[MessageHeader(ProtectionLevel=System.Net.Security.ProtectionLevel.Sign)]