如何创建soap信封以在c#.net中向Web服务发送请求

时间:2013-12-30 07:40:19

标签: c# wcf web-services soap

我必须向Web服务发送SOAP请求。客户端为我提供了WSDL,端点,x509证书以及WSDL链接。我必须创建以下请求,但我无法帮助我。

<soap:Envelope xmlns:get="http://www.americanexpress.com/GCST/" 
               xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
    <wsse:Security 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-26F72BFC485DA34D761355972749631103">MIIC1TCCAj6gAwIBAgIPfiKGyzlXlaz4AngN8FZcMA0GCSqGSIb3DQEBBQUAMG4xLTArBgkqhkiG9w0BCQEWHmRhdGFkZWxpdmVyeS5zdXBwb3J0QHBhdG5pLmNvbTELMAkGA1UEBhMCVVMxCzAJBgNVBAoTAkdFMQ4wDAYDVQQLEwVHRUNQUzETMBEGA1UEAxMKdlBheW1lbnRDQTAeFw0xMjExMDIyMTExMzBaFw0xNTExMDIyMjExMzFaMH4xJzAlBgkqhkiG9w0BCQEWGHZwYXltZW50c3VwcG9ydEBhZXhwLmNvbTELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDURhc2hib2FyZFRlc3QxFjAUBgNVBAsTDURhc2hib2FyZFRlc3QxFjAUBgNVBAMTDURhc2hib2FyZFRlc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKlUJxJ2+qRFdGzGG07U4IzHTbfv4IwgL8B21eUjB+drvAo+QUm1cVBNtB7zqgK9WaCYA+brU40j9MjjRa1YuaxpOzMNBsQfLwmdlQb36fQvVQK2Jr/Wp68dAaNhZDxIxALhsZSGhJozP4JouSpCERUG9C11g9kUHcmRLa9nxTAgMBAAGjZTBjMA4GA1UdDwEBwQEAwIHgDARBglghkgBhvhCAQEEBAMCB4AwHwYDVR0jBBgwFoAU9aTpu8Uzh0P7wKpCdS6gmMEMIcwHQYDVR0OBBYEFG0cjPjtJbD2WwtR3p0ciMizeZZpMA0GCSqGSIb3DQEBBQUAA4GBAGKvtCadz0gJjfeN+CKVfC2YyfhJZpW6E0di8a8YgZg4+w1KfWfi7ubMciQLBsMqkhyFF4mXBbsAO1LAyKi0Nqfq9QYv9HKxlullkVsJER+hECnn60LhxZd3X0G7y0j39RFile+7lVtDX8nEVenSI91LFHYgoCrvjGBSDuW</wsse:BinarySecurityToken>
      <ds:Signature Id="SIG-35" 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="get soap" 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="#id-1">
            <ds:Transforms>
              <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                <ec:InclusiveNamespaces PrefixList="get" 
                                        xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </ds:Transform>
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
            <ds:DigestValue>y7jjytjujJyBM8cnGJEYUSXkqFOB6Klzg=</ds:DigestValue>
          </ds:Reference>     
        </ds:SignedInfo>
        <ds:SignatureValue>hhPRZ5R09OVGBsPcTYiBjUg3tIImXlgOK+wMKI2F8QvsWoR/JNHNX3+ahd2O34aREg5jJV5qrY0SHYBjGHgcpXejL3VDagiRrj+fUiNco8PpjGcJK7pBjgOrMW3DXI1i8lrMgU1JkC8+XAskC27BhgISu9qE6Xuw5jMbBGYExeA=</ds:SignatureValue>
        <ds:KeyInfo Id="KI-26F72BF56C485DA34D761355972749631104">
          <wsse:SecurityTokenReference wsu:Id="STR-26656775F72BFC485DA34D761355972749631105">      
            <wsse:Reference URI="#X509-26F72BFC485DA34D761355972749631103"
                            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:Security>   
  </soap:Header>
  <soap:Body wsu:Id="id-1" 
             xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <get:getAuthorizationSummary>
      <get:Request>
        <get:authorizationSummaryReq>
          <get:accountNumber>XXXXXXXXXXXXXX</get:accountNumber>
          <get:cardPoolID>In</get:cardPoolID>
          <get:senderID>34344</get:senderID>
          <get:recieverID>67677</get:recieverID>
        </get:authorizationSummaryReq>
      </get:Request>
    </get:getAuthorizationSummary>
  </soap:Body>
</soap:Envelope>

我创建了WCF客户端并添加了它创建的app.config的WSDL引用。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="PreAuthBinding12">
          <textMessageEncoding maxReadPoolSize="64" 
                               maxWritePoolSize="16"
                               messageVersion="Soap12" 
                               writeEncoding="utf-8">
            <readerQuotas maxDepth="32" 
                          maxStringContentLength="8192" 
                          maxArrayLength="16384"
                          maxBytesPerRead="4096" 
                          maxNameTableCharCount="16384" />
          </textMessageEncoding>
          <httpsTransport manualAddressing="false" 
                          maxBufferPoolSize="524288"
                          maxReceivedMessageSize="65536" 
                          allowCookies="false" 
                          authenticationScheme="Anonymous"
                          bypassProxyOnLocal="false"
                          hostNameComparisonMode="StrongWildcard"
                          keepAliveEnabled="true" 
                          maxBufferSize="65536" 
                          proxyAuthenticationScheme="Anonymous"
                          realm="" transferMode="Buffered"
                          unsafeConnectionNtlmAuthentication="false"
                          useDefaultWebProxy="true" requireClientCertificate="false" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https:ww.abc.com"
                binding="customBinding" 
                bindingConfiguration="PreAuthBinding12"
                contract="Vpay" name="PreAuthorizationServicePort12" />
    </client>
  </system.serviceModel>
</configuration>

所以我不明白如何使用x509证书创建soap信封,如何创建签名,摘要算法,规范,wsu,wsse。

0 个答案:

没有答案