【发布时间】:2015-01-17 20:22:41
【问题描述】:
将 WSE3 Web 服务客户端代码转换为 WCF
嗨。如果专家能够将以下 WSE3 Web 服务客户端代码转换为一些工作(尽可能)WCF 代码(最好在代码中配置并且整个代码尽可能短),那将不胜感激?我看过一些使用 ChannelFactory 类的例子,但可能有更简洁/更短的方法。
被调用的第 3 方 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>
【问题讨论】:
-
请修复您的 XML 以正确使用
<和>。 -
嗨,约翰。我已经为你修复了 xml。