【问题标题】:Object reference not set to an instance of an object error when trying SOAP call尝试 SOAP 调用时未将对象引用设置为对象错误的实例
【发布时间】:2014-07-04 12:47:49
【问题描述】:

我正在尝试使用 SOAP / wsdl 连接到 Web 服务并对其进行身份验证,但我不断收到错误消息:

<b>Fatal error</b>:  Uncaught SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object. in /path/install.php:16

以下是我当前的代码:

<?php
header("Content-Type: text/plain"); 

$userinfo = array(
    'Username'=>'test',
    'Password'=>'test'
);

$wsdl_url = 'https://ws-e-distribution.kmd.dk/standard/ServiceAutorisation/ServiceAutorisation.svc?wsdl';
$client = new SoapClient($wsdl_url);

print_r($client->__getFunctions());
print_r($client->__getTypes());

//This is the problematic line:
$response = $client->__soapCall('LogOn', array('LogOn' => $userinfo));

var_dump($response);

我已经尝试了所有可能的包装用户名和密码参数的方法,我可以想到或找到任何人建议:

  • 使用自定义类
  • 使用stdClass
  • 使用SoapVar
  • 使用SoapParam
  • 使用简单数组
  • 双包装数组
  • 以上的很多组合。

我尝试过调用$client-&gt;__soapCall('LogOn', [milliontries])$client-&gt;LogOn([milliontries]) 之类的函数

...没有用,请帮忙。

更新:

我终于设法得到一个不同的错误(这表明至少我遇到了一些稍微不那么错误的错误)。我的代码现在看起来像这样:

$response = $client->LogOn(array('logon' => array('Username' => 'test','Password' => 'test')));

这给了我一个关于 LogOnType 不受支持的错误(在丹麦语中,这表明至少我现在与服务器有某种连接)。用户名和密码数组没有任何作用,我可以替换一个空字符串得到相同的结果,不同的是小写的logon

如果有人可以设置一个给出错误incorrect username or password 的工作示例,我将永远感激不尽...但任何指针将不胜感激。

据我了解,wsdl 提供了执行此操作所需的所有信息,我只是太喜欢[your_pick] 来获取它...?

【问题讨论】:

    标签: php soap wsdl


    【解决方案1】:

    难以置信!写这 16 行代码只用了 9 个小时。

    <?php
    header("Content-Type: text/plain"); 
    
    $userinfo = array(
        'Username'=>'test',
        'Password'=>'test'
    );
    
    $wsdl_url = 'https://ws-e-distribution.kmd.dk/standard/ServiceAutorisation/ServiceAutorisation.svc?wsdl';
    $client = new SoapClient($wsdl_url, array('trace' => 1, "exception" => 0));
    
    print_r($client->__getFunctions());
    print_r($client->__getTypes());
    
    //This actually works ! :) :) :)
    $response = $client->LogOn(array('logon' => new SoapVar($userinfo, SOAP_ENC_OBJECT, 'LogOnUsername', 'http://schemas.datacontract.org/2004/07/WebServiceAutorisation.BL')));
    
    var_dump($response);
    

    我曾多次如此接近,结果发现命名空间(URL)是我缺少的神奇之处。每次尝试使用 SoapVar's 时,我一直在使用主 wsdl 中的命名空间(或根本没有命名空间)。

    现在,进入登录的实际目的,可能不会更容易

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-03
      • 2012-02-26
      • 2011-07-09
      • 2012-08-31
      • 2011-11-21
      • 2012-10-01
      • 1970-01-01
      相关资源
      最近更新 更多