douhan1860 2013-10-09 11:19
浏览 70
已采纳

PHP SOAP Errormessage - System.NullReferenceException:未将对象引用设置为对象的实例

I have this problem, currently I am learning soap and developing online booking system with wsdl of http://vanillatours.com in PHP

their required headers are soapaction, and charset. which I have included, soapaction changes for desired request. for example, currently trying to do checklogin() function.

I tried print_r($client->__getFunctions()) to see if functions are attached, they are!

I tried print_r($client) to see if headers are attached and they are

the problem is that I can not figure out why I get this errormessage.

System.NullReferenceException: Object reference not set to an instance of an object.
at WcfService.Wcf.CheckLogin(LoginHeaderWcfRequest loginHeader)

Tried everything! I am very new with soap and any help would be appreciated. maybe I am not using correctly data "request"?

thank you!

<?php 

    $wsdl = "http://xmltest.vanillatours.com/Wcf.svc?wsdl";
    $client = new SoapClient($wsdl);

    $data = array(
     "request" => array(
      "a:AgentId" => blabla,
      "a:Language" => "En",
      "a:Password" => "blabla",
      "a:Username" => "blabla"
     )
    );

    $header = array();

    $header[] = new SoapHeader('http://tempuri.org/IWcf/CheckLogin','SOAPAction');
    $header[] = new SoapHeader('text/xml; charset=utf-8','ContentType');

    $client->__setSoapHeaders($header);


    $response = $client->__soapCall('CheckLogin', $data);

    echo '<pre>';


    print_r($client->__getFunctions()); // functions seem to show pretty well

    echo '<br>------------------------------------------------------<br><br>';

    print_r($client); // headers are attached 

    echo '<br>------------------------------------------------------<br><br>';

    print_r($response); // errormessage, can not figure out what is the problem.

    echo '</pre>';
?>

this is how to connect from their documentation, if I can use other method, would appreciate too.

CheckLogin function checks the user credentials is valid or not. SOAPAction value is http://tempuri.org/IWcf/CheckLogin

3.1.2 Request

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
 <s:Body> 

<CheckLogin xmlns="http://tempuri.org/"> 
<loginHeader xmlns:a="http://schemas.datacontract.org/2004/07/WcfService" 
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
 <a:AgentId>Your Agent Id</a:AgentId> 
 <a:Language>Your preferred language</a:Language> 
 <a:Password>Your Password</a:Password> 
 <a:Username>Your username</a:Username> 
 </loginHeader> 
 </CheckLogin> 
 </s:Body> 
 </s:Envelope>
  • 写回答

1条回答 默认 最新

  • doulai8405 2013-10-09 11:45
    关注

    The structure of $data is not right. It should be:

    $data = array(
        "loginHeader" => array(
             "AgentId" => blabla,
             "Language" => "En",
             "Password" => "blabla",
             "Username" => "blabla"
        )
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题
  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用
  • ¥88 用uniapp写一个多端的程序,用到高德地图,用高德的JSAPI吗?
  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle
  • ¥15 有人会搭建生鲜配送自营+平台的管理系统吗