PHP SoapClient生成不同格式的SOAP请求
因此,我尝试连接到第三方服务,但在PHP中遇到了一些问题。当我在WebService Studio中尝试服务请求时,它工作正常,发送的请求如下所示:PHP SoapClient生成不同格式的SOAP请求,php,web-services,soap,Php,Web Services,Soap,因此,我尝试连接到第三方服务,但在PHP中遇到了一些问题。当我在WebService Studio中尝试服务请求时,它工作正常,发送的请求如下所示: <?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" xm
<?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>
调试请求后,我得到以下结果:
<?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>
123
1234
1234567890abdcef
测试
用户
12345
test@test.com
A.
0
真的
在PHP中由SoapClient生成的请求中,我马上想到了一些事情。第一件事是第一个参数(我第一次通过test@test.com)未在param1中传递,第二个参数为。下一件事是,对createUser的请求是一个自动关闭标记,不包括正在传递的参数。显然,整个结构与所使用的标签略有不同
我尝试过使用数组(甚至没有到抛出请求的地步)、在SoapParam中包装参数、使用_call()和使用_soapCall(),但这些都不能解决这个问题
有没有人知道什么可以解决这个问题,从而使PHP中SoapClient生成的请求与WebService Studio生成的请求相匹配,而不是手动生成soap请求?我也遇到了类似的问题(使用self-closing operation标记) 事实证明,问题在于我是如何传递参数的。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>
因此,基本上,请确保您理解您正在使用的wsdl中的定义,并遵循它的结构进行操作。您是否使用wsdl连接到服务?createAccount方法的定义是什么?我使用的是WSDL,但不能公开发布该信息。我遇到了同样的问题,我解决了构建数组结构的问题,就像您一样,考虑到SOAP请求的所有子组/节点
<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>
$soapParams = array('ValidateStudent' => array(
'studentNumber' => $stuCode,
'surname' => $lastName,
'dob' => $dob,
'clientIP' => $ip,
'clientUserAgent' => $uAgent,
'clientReferrer' => $referer
));
$response = $soapClient->__soapCall('ValidateStudent', $soapParams);