PHP中的SOAP - 需要多个参数帮助

时间:2016-02-22 07:59:24

标签: php soap

我有一些xml soap数据,在PurchaseOrderNumbers区域内,我无法让字符串正常工作。

POST /services/trevco.asmx HTTP/1.1
Host: b2b.trevcoinc.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://trevcoinc.com/GetOrderStatus"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
<GetOrderStatus xmlns="http://trevcoinc.com/">
  <request>
    <APIKey>string</APIKey>
    <APIPasscode>string</APIPasscode>
    <PurchaseOrderNumbers>
      <string>string</string>
      <string>string</string>
    </PurchaseOrderNumbers>
    <PONumber>string</PONumber>
  </request>
</GetOrderStatus>
 </soap:Body>
</soap:Envelope>

这是我试过的一些示例PHP代码

$client_trevco = new SoapClient(
    "url",
    array('APIKey' => "", 'APIPasscode' => "")
);

$xml = array(
    'PurchaseOrderNumbers' => array(
        'string' => array(
            array( "GC-0998" )
        )
    )
);

$results = $client_trevco->__call("GetOrderStatus", $xml);

print_r($results->GetItemListResult);

和我得到的错误

  

致命错误:未捕获的SoapFault异常:[soap:Server]服务器无法处理请求。 ---&GT;对象引用未设置为对象的实例。

1 个答案:

答案 0 :(得分:0)

问题在于遵循XML的流程,这么简单,我忽略了它。

更正代码

$orderNumbers = array('0998', '1001');

$arr = array("request" => array("APIKey" => '', "APIPasscode" => '', 'PurchaseOrderNumbers' => array('string' => $orderNumbers)));

$client_trevco = new SoapClient("https://b2b.trevcoinc.com/services/trevco.asmx?wsdl");

$sa = $client_trevco->GetOrderStatus($arr);

<GetOrderStatus xmlns="http://trevcoinc.com/">
  <request>
    <APIKey>string</APIKey>
    <APIPasscode>string</APIPasscode>
    <PurchaseOrderNumbers>
      <string>string</string>
      <string>string</string>
    </PurchaseOrderNumbers>
    <PONumber>string</PONumber>
  </request>
</GetOrderStatus>