这是我的SOAP请求:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://impl.user">
<soapenv:Header/>
<soapenv:Body>
<impl:UserSessionDetails soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<in0 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">requstXml</in0>
<in1 xsi:type="impl:UserInfo">
<password xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">pwd</password>
<userName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">pwd</userName>
</in1>
</impl:UserSessionDetails>
</soapenv:Body>
</soapenv:Envelope>
我尝试过以下PHP代码:
$soapClient = new SoapClient("http://example.com/services/?WSDL");
$sh_param = array(
'userName' => 'user',
'Password' => 'pwd'
);
$headers = new SoapHeader('http://tempuri.org/', false);
$soapClient->__setSoapHeaders(array($headers));
$requestXML = '<request name= "UserSessionDetails"><UserDetails><user_name>username</user_name><from_date>fromdate</from_date><to_date>to_date</to_date><group></group></UserDetails></request>';
$result = $soapClient->UserSessionDetails(array('in0'=> $requestXML, 'in1'=> $sh_param));
$simple = $result->$simple = $result->UserSessionDetailsResponse;
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
echo "<pre>";
print_r($vals);
echo "</pre>"
但它什么也没有回报。有谁能告诉我这是什么问题?
答案 0 :(得分:0)
不要在SoapClient请求中使用原始xml。请改用对象/数组或SoapVar。
基本示例:
<?php
$client = new \SoapClient('http://example.com/services/?WSDL');
// Optionally your service endpoint
$client->__setLocation('http://example.com/services');
$userDetails = new stdClass();
$userDetails->user_name = 'username';
$userDetails->from_date = 'fromdate';
$userDetails->to_date = 'to_date';
$in0 = new stdClass();
$in0->UserDetails = $userDetails;
$in1 = new stdClass();
$in1->userName = 'pwd';
$in1->Password = 'pwd';
$request = new stdClass();
$request->in0 = $in0;
$request->in1 = $in1;
$result = $client->UserSessionDetails($request);
您可以使用SOAPUI
等任何SOAP客户端调试SOAP服务P.S。 请查看Zend_Soap_Client和SoapVar examples