2011-02-23 53 views
3

所以我打算連接到第三方服務並在PHP中遇到一些問題。當我嘗試在WebService的Studio中的服務請求時,它工作正常,所發送的請求是這樣的:PHP SoapClient生成不同的格式化SOAP請求

<?xml version="1.0" encoding="utf-16"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <createUser xmlns="http://ws.example.com"> 
      <arg0 xmlns="">[email protected]</arg0> 
      <arg1 xmlns="">123</arg1> 
      <arg2 xmlns="">1234</arg2> 
      <arg3 xmlns="">1234567890abcdef</arg3> 
      <arg4 xmlns="">test</arg4> 
      <arg5 xmlns="">user</arg5> 
      <arg6 xmlns="">02472</arg6> 
      <arg7 xmlns="">[email protected]</arg7> 
      <arg8 xmlns="">A</arg8> 
      <arg9 xmlns="">0</arg9> 
      <arg10 xmlns="">true</arg10> 
     </createUser> 
    </soap:Body> 
</soap:Envelope> 

現在,當我嘗試從PHP使用以下命令調用服務:

$this->web_service->createAccount('[email protected]', 123, 1234, '1234567890abcdef', 'test', 'user', '12345', '[email protected]', 'A', 0, true) 

和調試請求,我得到這個:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.example.com"> 
    <SOAP-ENV:Body> 
     <ns1:createUser/> 
     <param1>123</param1> 
     <param2>1234</param2> 
     <param3>1234567890abdcef</param3> 
     <param4>test</param4> 
     <param5>user</param5> 
     <param6>12345</param6> 
     <param7>[email protected]</param7> 
     <param8>A</param8> 
     <param9>0</param9> 
     <param10>true</param10> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

有幾件事情立即跳出來在我的PHP SoapClient生成的請求。第一件事是第一個參數(第一次通過[email protected])沒有在param1中傳遞,第二個參數是。接下來的事情是createUser的請求是一個自動關閉標記,不包括正在傳遞的參數。顯然,整個結構與使用的標籤有一點不同。我已經嘗試使用數組(甚至沒有去引發請求),在SoapParam中包裝參數,使用__call()和使用__soapCall(),但沒有一個解決了這個問題。

任何人都知道這樣的PHP的SoapClient的產生的請求匹配的WebService的工作室短生成手動生成手工肥皂請求一個什麼可能解決這個問題?

+0

? createAccount方法的定義是什麼? – Cfreak 2011-02-23 16:15:54

+0

我正在使用WSDL,但不能公開發布該信息 – ryanzec 2011-02-23 16:37:43

回答

0

我想你可以用與指數

$this->webService->createAccount(array('arg0'=>'[email protected]')...); 

或使用__soapCall功能

+0

嘗試過,但沒有奏效。 – ryanzec 2011-02-24 14:16:22

+0

您可以在嘗試此方法後發佈getLastRequest調用的結果嗎? – 2011-02-26 15:42:02

6

我有一個類似的問題(與自行閉合的操作標籤)

參數名稱的數組,得到更好的服務

原來,問題在於我是如何通過參數。與預期參數的WSDL定義如下:

<s:element name="ValidateStudent"> 
<s:complexType> 
<s:sequence> 
    <s:element minOccurs="0" maxOccurs="1" name="studentNumber" type="s:string" /> 
    <s:element minOccurs="0" maxOccurs="1" name="surname" type="s:string" /> 
    <s:element minOccurs="0" maxOccurs="1" name="dob" type="s:string" /> 
    <s:element minOccurs="0" maxOccurs="1" name="clientIP" type="s:string" /> 
    <s:element minOccurs="0" maxOccurs="1" name="clientUserAgent" type="s:string" /> 
    <s:element minOccurs="0" maxOccurs="1" name="clientReferrer" type="s:string" /> 
</s:sequence> 
</s:complexType> 
</s:element> 



<wsdl:message name="ValidateStudentSoapIn"> 
    <wsdl:part name="parameters" element="tns:ValidateStudent" /> 
</wsdl:message> 



<wsdl:operation name="ValidateStudent"> 
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Validation of user credentials to student portal</wsdl:documentation> 
    <wsdl:input message="tns:ValidateStudentSoapIn" /> 
    <wsdl:output message="tns:ValidateStudentSoapOut" /> 
</wsdl:operation> 



<wsdl:operation name="ValidateStudent"> 
    <soap:operation soapAction="http://test.example.com/ValidateStudent" style="document" /> 
    <wsdl:input> 
    <soap:body use="literal" /> 
    </wsdl:input> 
    <wsdl:output> 
    <soap:body use="literal" /> 
    </wsdl:output> 
</wsdl:operation> 

因此,該方法,ValidateStudent()需要一個參數(也稱爲ValidateStudent - 這是在第二部分中所定義),它是一個複雜類型如第一部分所定義。

在我的情況,我不得不通過PARAMS如下(爲單獨的元件,鍵合爲「ValidateStudent」,與名爲子元件作爲WSDL中定義的):所以

$soapParams = array('ValidateStudent' => array(
    'studentNumber'  => $stuCode, 
    'surname'   => $lastName, 
    'dob'    => $dob, 
    'clientIP'   => $ip, 
    'clientUserAgent' => $uAgent, 
    'clientReferrer' => $referer 
)); 

$response = $soapClient->__soapCall('ValidateStudent', $soapParams); 

,基本上,請確保您理解定義爲您正在使用的WSDL擺出來,你正在使用WSDL來連接到服務遵循其結構爲T.

+0

我有同樣的問題,我解決了像你一樣構建數組結構,考慮了SOAP請求的所有子組/節點 – gyss 2014-07-03 11:39:12