PHP SoapClient生成不同的格式化SOAP请求
所以我打算连接到第三方服务并在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的工作室短生成手动生成手工肥皂请求一个什么可能解决这个问题?
尝试过,但没有奏效。 – ryanzec 2011-02-24 14:16:22
您可以在尝试此方法后发布getLastRequest调用的结果吗? – 2011-02-26 15:42:02
我有一个类似的问题(与自行闭合的操作标签)
参数名称的数组,得到更好的服务原来,问题在于我是如何通过参数。与预期参数的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.
我有同样的问题,我解决了像你一样构建数组结构,考虑了SOAP请求的所有子组/节点 – gyss 2014-07-03 11:39:12
? createAccount方法的定义是什么? – Cfreak 2011-02-23 16:15:54
我正在使用WSDL,但不能公开发布该信息 – ryanzec 2011-02-23 16:37:43