简体   繁体   English

尝试在PHP中调用SOAP函数时出错

[英]Error when trying to call a SOAP function in PHP

I'm stuck for a couple of weeks now when trying to call a SOAP function in PHP. 现在,在尝试用PHP调用SOAP函数时,我停留了几个星期。

The error: 错误:

Server was unable to process request. ---> Object reference not set to an instance of an object

The XML: XML:

POST /example.com/example.asmx HTTP/1.1
Host: URL
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.example.com/action"

<?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:Header>
    <AuthenticationHeader xmlns="http://www.example.com/">
      <username>string</username>
      <password>string</password>
      <Id>long</Id>
    </AuthenticationHeader>
  </soap:Header>
  <soap:Body>
    <GetCardInfo xmlns="http://www.example.com/">
      <cardnumber>string</cardnumber>
      <pincode>string</pincode>
    </GetCardInfo>
  </soap:Body>
</soap:Envelope>

I'm using this code to call the function: 我正在使用以下代码来调用该函数:

$client = new SoapClient("http://example.com/example.asmx?WSDL", array('trace' => 1));    

$card = array(
      'cardnumber' => 'example card number',
      'pincode' => 'example pin code'
    );

    try {
      $result = $client->__soapCall('GetCardInfo', $card);
      print_r($result);
    }

    catch (SoapFault $q)
    {
      print_R($q);
    }

If you would like more info, please ask me. 如果您想了解更多信息,请询问我。 I'm new to this community. 我是这个社区的新手。

I solved it, I had to put the SoapHeader in the stdClass object, and cast it to an array. 我解决了它,我不得不将SoapHeader放在stdClass对象中,并将其转换为数组。 I have no idea why it worked but it does. 我不知道为什么它起作用,但它确实起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM