I'm trying to pull data from a SOAP API on a Wordpress site. I'm using the PHP SoapClient library.
I've scoured the internet over the past week trying every possible solution to this problem I can find, including trying other libraries, with no luck. I haven't even gotten to the point where I can pull data, I'm just trying to login to this service, which I can confirm the login and other functions work through thirdparty applications.
I've also tried refactoring my code into it's own class and calling things that way, but the same issues occur.
I keep getting the same error back no matter what I try:
Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at NjoynDataGateway.Login(String pr_UserName, String pr_Password, Boolean pr_AbortExistingSession) --- End of inner exception stack trace
This is the code I'm using:
$url = 'https://qa1.njoyn.com/CL4/net/WebService/NjoynDataExport.asmx?wsdl';
$username = 'username';
$password = 'password';
$abort_session = true;
$namespace = "http://njoyn.com/";
$soap_client = new SoapClient($url);
// Body of the Soap Header.
$headerbody = [
'pr_UserName' => $username,
'pr_Password' => $password,
];
// Create Soap Header.
$header = new SOAPHeader($namespace, 'AuthHeader', $headerbody);
$soap_client->__setSoapHeaders($header);
$result = $soap_client->__SoapCall('Login', [
'pr_UserName' => $username,
'pr_Password' => $password,
'pr_AbortExistingSession' => $abort_session,
]);
var_dump($result);
Expected results would be something that isn't an error to start with. According to their documentation, the login method should return true.
For anyone who's seeing this, I wasn't able to get the SOAP API working. I tried everything I could think of. I tried dozens of different coding approaches, tried connecting to other SOAP APIs which worked with no issues. I tried many online SOAP API clients, all of which failed except for one.
The Object reference not set to an instance of an object
error is a response from their API. All of the online SOAP clients I tried that failed were using the PHP SoapClient library and one used a Node.JS library. The one that worked was http://www.soapclient.com/soapTest.html which uses a C++ library. So there's potentially some sort of issue with the way their API is interacting with some of these libraries. I'm not familiar with the intricacies of SOAP at all so this is as far as I've gotten. Fortunately for me, they were able to provide me a link where I could scrape the data I needed from.
Hopefully others that run into this can find a non-SOAP approach to achieve their issue. If not, I'd start looking into, or contacting them to look into, issues on their end.