简体   繁体   English

尝试SOAP调用时,对象引用未设置为对象错误的实例

[英]Object reference not set to an instance of an object error when trying SOAP call

I am trying to connect to and authenticate with a webservice using SOAP / wsdl, but I constantly get the error: 我正在尝试使用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

Below is my current code: 以下是我目前的代码:

<?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);

I have tried every possible way of wrapping the username and password parameters that I could conceive of or find anyone suggesting: 我已经尝试了一切可能的方法来包装我可以想到的用户名和密码参数,或者找到任何人建议:

  • using a custom class 使用自定义类
  • using a stdClass 使用stdClass
  • using SoapVar 使用SoapVar
  • using SoapParam 使用SoapParam
  • using a simple array 使用简单的数组
  • double wrapped array 双包裹数组
  • A lot of combinations of the above. 以上很多组合。

And I've tried calling the function like $client->__soapCall('LogOn', [milliontries]) as well as $client->LogOn([milliontries]) 我尝试调用函数,如$client->__soapCall('LogOn', [milliontries])以及$client->LogOn([milliontries])

...nothing works, please help. ......什么都行不通,请帮忙。

Update: 更新:

I finally managed to get a different error (that suggests at least I hit upon something slightly less wrong). 我终于设法得到一个不同的错误(这表明至少我遇到了一些稍微错误的东西)。 My code now looks like this: 我的代码现在看起来像这样:

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

Which gives me an error about the LogOnType being unsupported (in Danish, which suggests to me that at least I have some sort of connection to the server now). 这给了我一个关于不支持LogOnType的错误(丹麦语,这告诉我至少我现在有一些与服务器的连接)。 The username and password array has no effect, I can substitute an empty string and get the same result, the thing that makes the difference is the lowercase logon . 用户名和密码数组没有任何效果,我可以替换空字符串并获得相同的结果,产生差异的是小写logon

If anyone can set up a working example that gives the error incorrect username or password I will be forever grateful... but any pointers will be much appreciated. 如果有人可以设置一个工作示例,给错误的incorrect username or password错误,我将永远感激...但任何指针将非常感激。

As far as I understand the wsdl gives all the information needed to do this, I'm just too much of a [your_pick] to get it...? 据我所知,wsdl提供了执行此操作所需的所有信息,我只是太多了[your_pick]来获取它...?

Unbelievable ! 难以置信的 ! It only took nine hours to write these 16 lines of code. 编写这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);

I was so close several times, and it turned out the namespace (the URL) was the magic bit I was missing. 我几次如此接近 ,结果发现命名空间(URL)是我遗漏的神奇之处。 I had been using the namespace from the main wsdl (or no namespace at all) in every attempt at using SoapVar 's. 在每次尝试使用SoapVar我一直在使用主wsdl(或根本没有命名空间)的命名空间。

Well now, on to the actual purpose of logging in, probably won't be any easier 那么现在,关于登录的实际目的,可能不会更容易

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

相关问题 Soap错误:对象引用未设置为对象的实例 - Soap Error: Object reference not set to an instance of an object php soap错误:对象引用未设置为的实例 - php soap Error :Object reference not set to an instance of an 用PHP进行SOAP API调用,“对象引用未设置为对象的实例”! - SOAP API call with PHP, “Object reference not set to an instance of an object”! SOAP API错误:未将对象引用设置为对象的实例 - SOAP API Error: Object reference not set to an instance of an object 错误:在PHP中调用SOAP cilent时“对象引用未设置为对象的实例” - Error : “Object reference not set to an instance of an object” when calling SOAP cilent in PHP Soap WCF对象引用未设置为对象上的实例 - Soap WCF Object Reference Not Set To An Instance On An Object 获取对象引用未设置为对象的实例PHP Soap Client - Getting object reference not set to an instance of an object PHP Soap Client PHP,SOAP,.NET - 未将对象引用设置为对象的实例 - PHP, SOAP, .NET - Object reference not set to an instance of an object PHP SOAP问题:未将对象引用设置为对象的实例 - PHP SOAP Issue : Object reference not set to an instance of an object NODEJS / PHP WSDL SOAP:对象引用未设置为对象的实例 - NODEJS / PHP WSDL SOAP: Object reference not set to an instance of an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM