PHP SoapClient Generating Different Formatted SOAP Request
So I am tring to connect to a third party service and having some issues with it in PHP. When I try the service request in WebService Studio it works fine and the sent request looks like this:
<?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="">test@test.com</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="">test@test.com</arg7>
<arg8 xmlns="">A</arg8>
<arg9 xmlns="">0</arg9>
<arg10 xmlns="">true</arg10>
</createUser>
</soap:Body>
</soap:Envelope>
Now w开发者_JAVA百科hen I try to call the service from PHP with the following command:
$this->web_service->createAccount('test@test.com', 123, 1234, '1234567890abcdef', 'test', 'user', '12345', 'test@test.com', 'A', 0, true)
and debugging the request, I get this:
<?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>test@test.com</param7>
<param8>A</param8>
<param9>0</param9>
<param10>true</param10>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
A few things jump out at me right away with the request generated by SoapClient in PHP. The first thing is that the first parameter (the first time I pass test@test.com) is not being passed in param1, the second parameter is. The next thing is the the request to createUser is a self closing tag not including the parameters being pass. Then obviously the whole structure is a little different with the tag being used.
I have tried using an array (which doesn't even go to the point of throwing the request), wrapping the params in SoapParam, using __call(), and using __soapCall() but none of those fix this issue.
Anyone know what might fix this issue so the request generated by SoapClient in PHP matches the one generated by WebService Studio short of manually generate the soap request by hand?
I was having a similar problem (with the self closing operation tag)
Turns out, the problem was with how I was passing the params. The definition from the wsdl of the expected parameters was as follows:
<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>
So, the method, ValidateStudent() expects one parameter (also called ValidateStudent -- this is defined in the second section) which is a complex type as defined in the first section.
In my case, I had to pass the params as follows (as a single element, keyed as 'ValidateStudent', with sub-elements named as defined within the wsdl):
$soapParams = array('ValidateStudent' => array(
'studentNumber' => $stuCode,
'surname' => $lastName,
'dob' => $dob,
'clientIP' => $ip,
'clientUserAgent' => $uAgent,
'clientReferrer' => $referer
));
$response = $soapClient->__soapCall('ValidateStudent', $soapParams);
So, basically, make sure you understand the definition as laid out in the wsdl you're working with, and follow its structure to a T.
精彩评论