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

问题描述 投票:0回答:1

当我试图在PHP中调用SOAP函数时,我已经停留了几个星期。

错误:

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

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>

我正在使用此代码来调用该函数:

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

如果您想了解更多信息,请询问我。我是这个社区的新手。

php soap soap-client
1个回答
0
投票

我解决了它,我必须将SoapHeader放在stdClass对象中,并将其转换为数组。我不知道为什么它有效,但它确实有效。

© www.soinside.com 2019 - 2024. All rights reserved.