简单的PHP肥皂客户端帮助

时间:2017-02-08 11:36:01

标签: php web-services soap wsdl

我尝试将几个帖子和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>

这是我直到现在所写的:     class sendData {

    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);&#34; ????&#34;一部分?
  • 将params传递给soap函数的正确方法是什么?
  • 这是解决问题的正确方法吗?

1 个答案:

答案 0 :(得分:1)

__soapCall的第一个参数是你想要调用的函数名,所以在这种情况下它应该是&#34; pushData&#34; (该示例表示SOAPAction=["pushData"]

__soapCall的第二个参数采用数组,因此传递params的正确方法是:

$response = $client->__soapCall("pushData", array($params));

更好更清洁的方法可能就是这样做:

$response = $client->pushData($params);

要从Web服务获取有关您需要使用的方法和数据类型的更多信息,您可以使用:

var_dump($client->__getFunctions());
var_dump($client->__getTypes());
关于SoapClient课程的

Here's more info以及您可以用它做什么。