The object reference is not set to an instance of an object error when trying to call SOAP

I am trying to connect to a web service and authenticate using the SOAP / wsdl service, but I constantly get an error message:

<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 tried all possible ways to reset the username and password parameters that I could imagine, or find someone offering:

  • using custom class
  • using stdClass
  • using SoapVar
  • using SoapParam
  • using a simple array
  • double packed array
  • Many combinations of the above.

And I tried to call a function like $client->__soapCall('LogOn', [milliontries]) , as well as $client->LogOn([milliontries])

... nothing works, please help.

Update:

I finally managed to get another error (this suggests that at least I came across something a little less erroneous). Now my code is as follows:

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

Which gives me an error when LogOnType not supported (in Danish, which tells me that at least I now have some kind of connection to the server). An array of username and password has no effect, I can replace the empty string and get the same result, which makes the difference in lowercase logon .

If anyone can set up a working example that gives an incorrect username or password error, I will be forever grateful ... but any pointers will be very grateful.

As far as I understand, wsdl provides all the information needed for this, I just have too much [your_pick] to get it ...?

+3
source share
1 answer

Unbelievable! It took nine hours to write these 16 lines of 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, 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 a few times, and it turned out that the namespace (URL) was a magic bit that I was missing. I used a namespace from the main wsdl (or no namespace at all) with every attempt to use SoapVar .

Well, now, with the actual purpose of logging in, it might not be easier.

+11
source

Source: https://habr.com/ru/post/1266590/


All Articles