2016-09-23 56 views
1

我嘗試在SOAP網絡服務來創建CreateOrder方法順序:解決SoapClient錯誤:「對象引用未設置爲對象的實例。」

http://80.72.84.109/MW/services/bilkiservice.asmx?wsdl

這個簡單的代碼:

$soap = new SoapClient(MW_SOAP_URL, array(
     "trace" => 1, 
     "exceptions" => 1 
    )); 

    //set headers 
    $headerbody = array(
     'Database' => MW_DATABASE, 
     'Username' => MW_USERNAME, 
     'Password' => MW_PASSWORD 
    ); 
    $ns = 'http://tempuri.org/'; 
    $header = new SoapHeader($ns, 'AuthenticationHeader', $headerbody); 
    $this->soap->__setSoapHeaders($header); 

    $orderInfo = array(
     'OrderNumber' => 23344, 
     'Email' => '[email protected]', 
     'Delivery' => array(
      'Name' => 'Peter', 
      'City' => 'LA', 
      'Post' => 1000, 
      'Address' => 'Test Street 1', 
      'Email' => '[email protected]', 
      'Phone' => '12345' 
     ), 
     'PaymentType' => 2, 
     'Items' => array(
      'OrderItem' => array(
       'Code' => 3479, 
       'Quantity' => 1, 
       'TotalPrice' => 2.73 
      ) 
     ) 
    ); 
    $soap->CreateOrder($orderInfo); 

但我總是得到這個錯誤:

object(stdClass)#5 (1) { ["CreateOrderResult"]=> object(stdClass)#6 (4) 
    { ["ErrorMessage"]=> string(53) "Object reference not set to an instance of an object." 
    ["ErrorCode"]=> int(-1) ["Errs"]=> object(stdClass)#7 (0) { } ["OrderID"]=> int(0) } } 

我用另一種方法CreateContragent成功創建了新的反應,但是CreateOrder沒有工作。

可能是數組數據有誤?但我嘗試了很多配置,沒有任何工作。

回答

0

這不是你的錯,你的網絡服務不起作用。那就是你的CreatingOrder函數的結果說明:

<?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> 
    <CreateOrderResponse xmlns="http://tempuri.org/"> 
     <CreateOrderResult> 
     <Errs> 
      <ErrorItem> 
      <ErrorCode>int</ErrorCode> 
      <ErrorMessage>string</ErrorMessage> 
      <ItemNumber>int</ItemNumber> 
      </ErrorItem> 
      <ErrorItem> 
      <ErrorCode>int</ErrorCode> 
      <ErrorMessage>string</ErrorMessage> 
      <ItemNumber>int</ItemNumber> 
      </ErrorItem> 
     </Errs> 
     <OrderID>int</OrderID> 
     </CreateOrderResult> 
    </CreateOrderResponse> 
    </soap:Body> 
</soap:Envelope> 
相關問題