简单 php soap 客户端帮助

simple php soap client helps

我尝试合并几个 post 和 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 发送数据 {

    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);

我的问题是:

__soapCall的第一个参数是你要调用的函数名,所以在本例中应该是"pushData"(例子表示SOAPAction=["pushData"]

__soapCall的第二个参数是一个数组,所以正确的传参方式是:

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

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

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

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

var_dump($client->__getFunctions());
var_dump($client->__getTypes());

Here's more info 关于 SoapClient class 以及您可以用它做什么。