为什么我的SOAP调用不适用于PHP?

时间:2018-07-30 17:22:31

标签: php soap soapui

我正在尝试调用SOAP函数。我在SOAP UI上测试了该功能,并且工作正常。它给了我一个成功的回应。但是,当我尝试使用PHP调用函数时,它给了我这个错误:

  

SoapFault异常:[服务器]内部错误   /home/bookweeb/unus.site/V2/Dashboard/includes/npmeTracking.php:24   堆栈跟踪:#0   /home/bookweeb/unus.site/V2/Dashboard/includes/npmeTracking.php(24):   SoapClient-> __ soapCall('track',Array)#1 {main}

我已经尝试了一切,但无法弄清楚我在做什么。这是我的代码:

$username = 'XXXXXXXX';
$pro = '90986629';

        $wsdl = "https://unus.site/V2/Dashboard/includes/ShipmentTracking.wsdl";

        $request = array(
            'trackingNumber' => $pro,
            'userId ' => $username
        );

        $client = new SoapClient($wsdl);

        try
        {

            $result = $client->__soapCall("track", array(
                $request
            ));

            print_r($result);

        }
        catch(SoapFault $ex)
        {
            $ex->getMessage();
            echo $ex;

        }

这是我使用SOAP UI进行测试的快照:

enter image description here

1 个答案:

答案 0 :(得分:0)

Track是complexType,因此您需要向其传递一个对象,而不是数组:

<element name="track">
<complexType>
 <sequence>
  <element name="trackingNumber" nillable="true" type="xsd:string"/>
  <element name="deliveryNotificationRequested" nillable="true" type="xsd:string"/>
  <element name="deliveryNotificationEmail1" nillable="true" type="xsd:string"/>
  <element name="deliveryNotificationEmail2" nillable="true" type="xsd:string"/>
  <element name="userId" nillable="true" type="xsd:string"/>
 </sequence>
</complexType>

$request = new StdClass();
$request->trackingNumber = '12345';
$request->userId = '222'; 

$client->track($request);