解决SoapClient错误:"对象引用未设置为对象的实例。"

时间:2016-09-23 11:21:27

标签: php web-services soap wsdl

我尝试在soap web服务中使用CreateOrder方法创建订单:

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' => 'test@test.com',
        'Delivery' => array(
            'Name' => 'Peter',
            'City' => 'LA',
            'Post' => 1000,
            'Address' => 'Test Street 1',
            'Email' => 'test@test.com',
            '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成功创建了新的contragent,但CreateOrder无法正常工作。

可能是数组数据错了?但我尝试了很多配置,没有任何作用。

1 个答案:

答案 0 :(得分: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>