将WSE3 Web服务客户端代码转换为WCF

时间:2015-01-15 21:34:08

标签: c# wcf soap wse

将WSE3 Web服务客户端代码转换为WCF

您好。如果专家能够将以下WSE3 Web服务客户端代码转换为一些工作(尽可能多的)WCF代码(最好是代码中的配置和整个代码尽可能短),我将不胜感激吗?我已经看到一些使用ChannelFactory类的例子,但可能有一个更清洁/更短的方式。

被调用的第三方Web服务是:HTTPS,EndPoint是ASMX文件,SOAP 1.1,并使用ws-security。工作的WSE3代码是:

    Dim ExpCertificate As New X509Certificate2
    ExpCertificate = New X509Certificate2("<pfx file>", "<password>")
    Dim waspservice As New TokenService
    waspservice.ClientCertificates.Add(ExpCertificate)
    waspservice.Url = "https://somesite.asmx"
    Dim res As String = waspservice.STS("<WASPAuthenticationRequest><ApplicationName>Example Client</ApplicationName><AuthenticationLevel>CertificateAuthentication</AuthenticationLevel><AuthenticationParameters/></WASPAuthenticationRequest>")
    Response.Write(res & vbCrLf & vbCrLf)

示例soap请求是:          

<wsse:Security>

<wsu:Timestampwsu:Id="Timestamp-2b27a32b-ca9c-4405-b377-4444f63c8f29">

<wsu:Created>2011-02-20T16:36:54Z</wsu:Created>

<wsu:Expires>2011-02-20T16:41:54Z</wsu:Expires>

</wsu:Timestamp>

<wsse:BinarySecurityToken ValueType="CompanyWASP" EncodingType="wsse:Base64Binary" wsu:Id="SecurityToken-f64439f9-c12c-4d09-ac3d-fc478ad19775">MjAtRTctQ0YtMTUtN0EtODEtNTk.</wsse:BinarySecurityToken>

</wsse:Security>

</soap:Header>

<soap:Body>

<! -- SOAP content for the service call -- >

</soap:Body>

WSDL是:

<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.uk.company.com/WASP/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://www.uk.company.com/WASP/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.uk.company.com/WASP/">
      <s:element name="STS">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="authenticationBlock" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="STSResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="STSResult" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="string" nillable="true" type="s:string" />
    </s:schema>
  </wsdl:types>
  <wsdl:message name="STSSoapIn">
    <wsdl:part name="parameters" element="tns:STS" />
  </wsdl:message>
  <wsdl:message name="STSSoapOut">
    <wsdl:part name="parameters" element="tns:STSResponse" />
  </wsdl:message>
  <wsdl:message name="STSHttpGetIn">
    <wsdl:part name="authenticationBlock" type="s:string" />
  </wsdl:message>
  <wsdl:message name="STSHttpGetOut">
    <wsdl:part name="Body" element="tns:string" />
  </wsdl:message>
  <wsdl:message name="STSHttpPostIn">
    <wsdl:part name="authenticationBlock" type="s:string" />
  </wsdl:message>
  <wsdl:message name="STSHttpPostOut">
    <wsdl:part name="Body" element="tns:string" />
  </wsdl:message>
  <wsdl:portType name="TokenServiceSoap">
    <wsdl:operation name="STS">
      <wsdl:input message="tns:STSSoapIn" />
      <wsdl:output message="tns:STSSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="TokenServiceHttpGet">
    <wsdl:operation name="STS">
      <wsdl:input message="tns:STSHttpGetIn" />
      <wsdl:output message="tns:STSHttpGetOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="TokenServiceHttpPost">
    <wsdl:operation name="STS">
      <wsdl:input message="tns:STSHttpPostIn" />
      <wsdl:output message="tns:STSHttpPostOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="TokenServiceSoap" type="tns:TokenServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
    <wsdl:operation name="STS">
      <soap:operation soapAction="http://www.uk.company.com/WASP/STS" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="TokenServiceHttpGet" type="tns:TokenServiceHttpGet">
    <http:binding verb="GET" />
    <wsdl:operation name="STS">
      <http:operation location="/STS" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="TokenServiceHttpPost" type="tns:TokenServiceHttpPost">
    <http:binding verb="POST" />
    <wsdl:operation name="STS">
      <http:operation location="/STS" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="TokenService">
    <documentation xmlns="http://schemas.xmlsoap.org/wsdl/">company Token Service</documentation>
    <wsdl:port name="TokenServiceSoap" binding="tns:TokenServiceSoap">
      <soap:address location="https://secure.authenticator.uat.uk.company.com/WaspAuthenticator/TokenService.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

1 个答案:

答案 0 :(得分:0)

生成使用的代理类 wsdl.exe或通过在visual studio中添加服务引用。这将创建所需的代理。 代理将具有您要调用的方法。通过所需的参数,你应该很好。