我正在尝试使用VSTO实现身份验证。我添加了一个指向下面的WSDL的Web服务引用,它生成了所有必需的类,但是我找不到用于身份验证的类,即使这是在WSDL中指定的。我已经尝试编辑app.config文件来制作:
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
但是,我仍然无法让VS生成应该自动生成的身份验证类。我是以正确的方式来做这件事的吗?我搜索的另一个选项是创建SOAP扩展。因为所有真正需要的是标头包含此身份验证信息:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
<wsu:Expires>2014-01-06T15:05:10.334Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>MyUserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPassword</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MyNonce==</wsse:Nonce>
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
WSDL:
<?xml version="1.0" encoding="utf-8"?>
<s0:definitions xmlns:s1="http://rsm.govt.nz/smart/download" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" name="DownloadService" targetNamespace="http://rsm.govt.nz/smart/download" xmlns:s0="http://schemas.xmlsoap.org/wsdl/">
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UTOverTransport">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Lax />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
</wsp:Policy>
</sp:SignedSupportingTokens>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<s0:types>
<xs:schema xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://rsm.govt.nz/smart/download" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://rsm.govt.nz/smart/download" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="DownloadLicences?xsd=LicenceDownloadService.xsd" />
</xs:schema>
</s0:types>
<s0:message name="LicenceDownloadException">
<s0:part name="errorMessage" element="s1:errorMessage" />
</s0:message>
<s0:message name="msgDetailResponse">
<s0:part name="detailResponse" element="s1:Licence" />
</s0:message>
<s0:message name="msgSearchResponse">
<s0:part name="searchResponse" element="s1:SearchResult" />
</s0:message>
<s0:message name="msgSearch">
<s0:part name="arg0" element="s1:SearchCriteria" />
</s0:message>
<s0:message name="msgDetail">
<s0:part name="arg0" element="s1:LicenceDetailsRequest" />
</s0:message>
<s0:portType name="LicenceDownloadWebService">
<s0:operation name="searchLicences">
<s0:input message="s1:msgSearch" />
<s0:output message="s1:msgSearchResponse" />
<s0:fault name="licenceDownloadException" message="s1:LicenceDownloadException" />
</s0:operation>
<s0:operation name="getLicenceDetails">
<s0:input message="s1:msgDetail" />
<s0:output message="s1:msgDetailResponse" />
<s0:fault name="licenceDownloadException" message="s1:LicenceDownloadException" />
</s0:operation>
</s0:portType>
<s0:binding name="LicenceDownloadServiceBinding" type="s1:LicenceDownloadWebService">
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
<s0:operation name="searchLicences">
<s2:operation soapAction="searchLicences" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
</s0:binding>
<s0:service name="LicenceDownloadService">
<s0:port name="LicenceDownloadServicePort" binding="s1:LicenceDownloadServiceBinding">
<s2:address location="https://data.eat.business.govt.nz/services/DownloadLicences" />
</s0:port>
</s0:service>
</s0:definitions>
非常感谢任何帮助。
干杯!
我将与WSDL提供商进行讨论。我希望所有的身份验证信息都已经从我能看到的内容中包含在WSDL中了:
<?xml version="1.0" encoding="utf-8"?>
<s0:definitions xmlns:s1="http://rsm.govt.nz/smart/download" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" name="DownloadService" targetNamespace="http://rsm.govt.nz/smart/download" xmlns:s0="http://schemas.xmlsoap.org/wsdl/">
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UTOverTransport">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Lax />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
</wsp:Policy>
</sp:SignedSupportingTokens>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<s0:types>
我还可以确定每个SOAP请求中都有一个标头,因为使用SOAP UI,SOAP消息原始如下所示:
POST https://data.eat.business.govt.nz/services/DownloadLicences?wsdl HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "searchLicences"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: data.eat.business.govt.nz
Content-Length: 1219
<soapenv:Envelope xmlns:dow="http://rsm.govt.nz/smart/download" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
<wsu:Expires>2014-01-06T15:05:10.334Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>MyUserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPassword</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MyNonce==</wsse:Nonce>
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<dow:SearchCriteria clientId="506682">
</dow:SearchCriteria>
</soapenv:Body>
</soapenv:Envelope>
亲切的问候
埃文
答案 0 :(得分:0)
<s0:binding name="LicenceDownloadServiceBinding" type="s1:LicenceDownloadWebService">
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
<s0:operation name="searchLicences">
<s2:operation soapAction="searchLicences" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
上面是你的wsdl绑定,我无法在这里看到任何操作,负责身份验证。这就是为什么它没有产生你所需要的课程,我猜。 请求您的wsdl提供程序实现您需要的身份验证方法并重新生成wsdl ..
<强>更新强>
The authentication information e.g. username, password etc. are all included within the header of each SOAP method. Which means when I send a "searchLicences" or "getLicenceDetails" message it will include the authentication details within the header of those messages
你如何确定肥皂信息的标题,因为根据你的wsdl,你的请求中不会有肥皂标题。
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
如果你的传入肥皂请求中有一个标题,那就是这样的。
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
<s2:header message="tns:getAuthHeader" part="username" use="literal" />
<s2:header message="tns:getAuthHeader" part="password" use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
还有一件事,有时web服务提供商隐藏了很少的方法,比如wsdl中的身份验证。您应该咨询您的wsdl提供程序,以在wsdl中包含该方法。否则,您将无法在客户端中生成该类。