[英]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: 我已经尝试了一切可能的方法来包装我可以想到的用户名和密码参数,或者找到任何人建议:
stdClass
stdClass
SoapVar
SoapVar
SoapParam
SoapParam
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.