繁体   English   中英

在VSTO中设置客户端凭据

[英]Setting Client Credentials in VSTO

我正在尝试使用VSTO实现身份验证。 我添加了一个Web服务参考,该参考指向下面的WSDL,并且它生成了所有必需的类,但是,即使在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>

亲切的问候

埃文

<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

您如何确定soap消息的标头,因为根据您的wsdl,您的请求中不会包含任何soap标头。

<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中。 否则,您将无法在客户端中生成该类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM