【问题标题】:Why is my SOAP call not working with PHP?为什么我的 SOAP 调用不能与 PHP 一起使用?
【发布时间】:2018-07-30 17:22:31
【问题描述】:

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

SoapFault 异常:[Server] 内部错误 /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 进行测试的快照:

【问题讨论】:

    标签: php soap soapui


    【解决方案1】:

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

    【讨论】:

    • 不幸的是,它仍然给我同样的错误。
    • 您确定request 属性包含strings?另外,您确定错误完全相同吗?该错误不应提及array,因为您不再通过...或者不应该是
    • 我使用字符串作为参数。这是我在尝试时遇到的错误:SoapFault 异常:/home/bookweeb/unus.site/V2/Dashboard/includes/npmeTracking.php:21 中的 [服务器] 内部错误堆栈跟踪:#0 /home/ bookweeb/unus.site/V2/Dashboard/includes/npmeTracking.php(21): SoapClient->__call('track', Array) #1 /home/bookweeb/unus.site/V2/Dashboard/includes/npmeTracking.php (21): SoapClient->track(Object(stdClass)) #2 {main}
    • 使用trace 选项初始化您的soap 客户端$client = new SoapClient($wsdl, array('trace'=&gt;1, 'exceptions' =&gt; 0)); 然后在您的catch 块中查看最后一条响应消息$client-&gt;__getLastResponse();
    • 这是我现在得到的响应:SoapFault Object ( [message:protected] => Internal Error [string:Exception:private] => [code:protected] => 0 [file :protected] => /home/bookweeb/unus.site/V2/Dashboard/includes/npmeTracking.php [line:protected] => 22 [trace:Exception:private] => Array ( [0] => Array ( [ file] => /home/bookweeb/unus.site/V2/Dashboard/includes/npmeTracking.php [line] => 22 [function] => __call [class] => SoapClient [type] => -> [args] => 数组 ( [0] => 轨道 [1] => 数组 ( [0] => 数组 ( [trackingNumber] => 90986629 [userId ] => XXXX ) ) ) ) [1] =>
    猜你喜欢
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 2020-10-08
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多