0

Convert WSE3 Web Service Client Code to WCF

Hi. It would be much appreciated if an expert could be able to convert the following WSE3 web service client code to some working(well as much as possible) WCF code(preferable with configuration in code and entire code as short as can be) please? I've seen some examples using the ChannelFactory class but there may be a cleaner/shorter way.

The 3rd Party web service being called is: HTTPS, EndPoint is ASMX file, SOAP 1.1, and using ws-security. The working WSE3 code is:

    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)

An example soap request is:

<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>

The WSDL is:

<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 Answers1

0

Generate proxy class either of using wsdl.exe OR by adding service reference in visual studio. That will create required proxy. Proxy will have methods which you want to call. Pass in required parameters and you should be good.

Pankaj Kapare
  • 7,486
  • 5
  • 40
  • 56