我试图结合几个帖子和php手册页,但我不太明白如何使用php soap客户端发出简单的肥皂请求。
这是我必须参考的 SOAP 示例:
http://<endpoint>/ourServer/services/spPushDataServicePort.svc
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {connection=[Keep-Alive], Content-Length=[789], content-type=[text/xml; charset=UTF-8], host=[urbelog.tilab.com], SOAPAction=["pushData"], user-agent=[Axis2], via=[1.1 urlXXX], x-forwarded-for=[Url2Ip], x-forwarded-host=[urlXXX], x-forwarded-server=[urlXXX]}
Payload: <?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns1:outData xmlns:ns1="http://serverYYY">
<vin>M55</vin>
<serviceProvider>URBELOG</serviceProvider>
<codeFunction>FLEET</codeFunction>
<date>2016-10-19T11:06:20.000+00:00</date>
<groups>
<name>GPS_DATA</name>
<params>
<name>LATITUDE</name>
<value>45.086666</value>
</params>
<params>
<name>LONGITUDE</name>
<value>9.29</value>
</params>
<params>
<name>TIMESTAMP</name>
<value>2016-10-19 13:06:20</value>
</params>
<params>
<name>ODOMETER</name>
<value>483734.56</value>
</params>
</groups>
</ns1:outData>
</soapenv:Body>
</soapenv:Envelope>
这是我到目前为止写的: 类发送数据 {
function __construct($vin, $serviceProvider,$codeFunction, $date, $lat, $long, $timeStamp, $mt)
{
$this->vin = $vin;
$this->serviceProvider = $serviceProvider;
$this->codeFunction=$codeFunction;
$this->date = $date;
$this-> groups= array('name'=>"GPS_DATA",
array('params'=>['LATITUDE'=>$lat]),
array('params'=>['LONGITUDE'=>$long]),
array('params'=>['TIMESTAMP'=>$timeStamp]),
array('params'=>['ODOMETER'=>$mt]));
}
}
/* Initialize webservice with your WSDL */
$client = new SoapClient("http://<endpoint>/ourServer/services/spPushDataServicePort.svc");
/* Set your parameters for the request */
$params=new sendData("uno","due","3","4","5","6","7","8");
/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall(?????, $params);
var_dump($response);
我的问题是:
- 在
$response = $client->__soapCall(?????, $params);
"????"部分设置什么? - 将参数传递给 SOAP 函数的正确方法是什么?
- 这是解决问题的正确和更明智的方法吗?
__soapCall
的第一个参数是你要调用的函数名,所以在这种情况下应该是 "pushData" (示例指示 SOAPAction=["pushData"]
(
__soapCall
的第二个参数采用数组,因此传递参数的正确方法是:
$response = $client->__soapCall("pushData", array($params));
更好、更干净的方法可能是这样做:
$response = $client->pushData($params);
若要从 Web 服务获取有关需要使用的方法和数据类型的详细信息,可以使用:
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
下面是有关 SoapClient
类以及可以使用它执行的操作的详细信息。