首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VSTO中设置客户端凭据

在VSTO中设置客户端凭据
EN

Stack Overflow用户
提问于 2014-01-06 10:49:31
回答 1查看 365关注 0票数 0

我正在尝试使用VSTO实现身份验证。我已经添加了一个指向下面WSDL的web服务引用,它生成了所有必需的类,但是我找不到用于身份验证的类,即使这是在WSDL中指定的。我已经尝试编辑app.config文件来制作:

代码语言:javascript
复制
                <security mode="Transport">
                    <transport clientCredentialType="Basic" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>

然而,我似乎仍然不能让VS生成它应该自动生成的身份验证类。我这样做对吗?我搜索的另一个选项是创建一个SOAP扩展。因为真正需要做的就是让头部包含此身份验证信息:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<?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中了,我可以从下面的内容中看到:

代码语言:javascript
复制
<?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消息的原始内容如下所示:

代码语言:javascript
复制
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>

亲切的问候

埃文

EN

回答 1

Stack Overflow用户

发布于 2014-01-06 12:38:40

代码语言:javascript
复制
<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。

更新:

代码语言:javascript
复制
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标头。

代码语言:javascript
复制
<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>

如果在传入的soap请求中有一个头,那么应该是这样的。

代码语言:javascript
复制
 <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>

还有一件事,有时webservice提供者在wsdl中隐藏了一些方法,比如身份验证。您应该咨询您的wsdl提供程序,以便在wsdl中包含该方法。否则,您将无法在您的客户端中生成该类。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20942165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档