1

我尝试通过提供的登录功能登录 affilinet 网络服务。我在 Rails 3 环境 (3.0.x) 中工作。我在版本 2 中使用了 ruby​​ on rails gem Savon,而后者又使用肥皂连接到 affilinet。
最新的 wsdl 可以在这里找到https://api.affili.net/V2.0/Logon.svc?wsdl
我的代码如下所示:

client = Savon.client do
  wsdl "https://api.affili.net/V2.0/Logon.svc?wsdl"
end
message = {'Username' => 'username', 'Password' => 'password', 'WebServiceType' => 'Publisher'}
response = client.call(:logon, :message => message)

Savon 生成的请求:

<?xml version="1.0" encoding="UTF-8"?>  
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://affilinet.framework.webservices/Svc" xmlns:ins3="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:ins2="http://affilinet.framework.webservices/types" xmlns:ins1="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF" xmlns:ins0="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
  <env:Body>  
    <tns:LogonRequestMsg>  
      <tns:Password>password</tns:Password>  
      <tns:WebServiceType>Publisher</tns:WebServiceType>  
      <tns:Username>username</tns:Username>  
    </tns:LogonRequestMsg>  
  </env:Body>  
</env:Envelope>  

将此请求发送到 Web 服务时,我收到此(错误)响应:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
      <s:Fault>
        <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode>
        <faultstring xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://affilinet.framework.webservices/Svc:LogonRequestMsg. The InnerException message was 'Error in line 1 position 775. 'EndElement' 'LogonRequestMsg' from namespace 'http://affilinet.framework.webservices/Svc' is not expected. Expecting element 'Username | Password | WebServiceType'.'.  Please see InnerException for more details.</faultstring>
        <detail>
          <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <HelpLink i:nil="true"/>
            <InnerException>
              <HelpLink i:nil="true"/>
            <InnerException i:nil="true"/>
            <Message>Error in line 1 position 775. 'EndElement' 'LogonRequestMsg' from namespace 'http://affilinet.framework.webservices/Svc' is not expected. Expecting element 'Username | Password | WebServiceType'.</Message>
            <StackTrace>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, Int32 memberIndex, Int32 requiredIndex, XmlDictionaryString[] memberNames)&#xD; ... (loads more) ...
            </StackTrace>
            <Type>System.ServiceModel.Dispatcher.NetDispatcherFaultException</Type>
          </ExceptionDetail>
        </detail>
      </s:Fault>
    </s:Body>
</s:Envelope>

有什么想法有什么问题吗?

编辑:

soapUI 中的请求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:svc="http://affilinet.framework.webservices/Svc" xmlns:typ="http://affilinet.framework.webservices/types">  

<soapenv:Header/>
<soapenv:Body>
  <svc:LogonRequestMsg>
     <!--Optional:-->
     <typ:Username>username</typ:Username>
     <!--Optional:-->
     <typ:Password>password</typ:Password>
     <typ:WebServiceType>Publisher</typ:WebServiceType>
     <!--Optional:-->
     <typ:DeveloperSettings>
        <!--Optional:-->
        <typ:SandboxPublisherID>?</typ:SandboxPublisherID>
     </typ:DeveloperSettings>
     <!--Optional:-->
     <typ:ApplicationSettings>
        <!--Optional:-->
        <typ:ApplicationID>?</typ:ApplicationID>
        <!--Optional:-->
        <typ:DeveloperID>?</typ:DeveloperID>
     </typ:ApplicationSettings>
  </svc:LogonRequestMsg>
</soapenv:Body>
</soapenv:Envelope>

也许请求的差异(由 Savon 和 soapUI 生成)是关键!?尤其是不同的命名空间:svc/typ 与 env/tns。有任何想法吗?如何告诉 Savon 为 LogonRequestMsg 使用 svc 命名空间?

4

2 回答 2

3

查看 Affili.net 的 WSDL,它显示用户名、密码、WebserviceType 等具有错误的命名空间。

在再次查看您的示例后为命名空间编辑。用户名、密码和 WebServiceType 在命名空间 ins2="http://affilinet.framework.webservices/types" 中定义,在您的情况下由“ins2”标记。

克服它的快速而肮脏的方法是

client = Savon.client do
  wsdl "https://api.affili.net/V2.0/Logon.svc?wsdl"
end
message = {'ins2:Username' => 'username',
           'ins2:Password' => 'password',
           'ins2:WebServiceType' => 'Publisher'}

response = client.call(:logon, :message => message)
于 2013-03-11T14:12:06.380 回答
1

我认为问题出在命名空间顺序上,在几个请求在命名空间中看到不同的顺序之后。

此代码适用于我(savod 版本 1),覆盖命名空间:

   message = { 
              'ins0:Username' => 'XXXXXXX',
              'ins0:Password' => 'XXXXXXX',
              'ins0:WebServiceType' => 'XXXXXX',
              :order!     => ['ins0:Username', 'ins0:Password', 'ins0:WebServiceType']
            }


  @client.wsdl.document = 'https://api.affili.net/V2.0/Logon.svc?wsdl'

  response = @client.request :logon do
    soap.body = message
    soap.namespaces["xmlns:ins0"] = "http://affilinet.framework.webservices/types"
    soap.namespaces["xmlns:ins1"] = "http://schemas.microsoft.com/2003/10/Serialization/Arrays"
    soap.namespaces["xmlns:ins2"] = "http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation"
    soap.namespaces["xmlns:ins3"] = "http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF"
  end
于 2016-07-19T13:14:58.637 回答