SOAP error encoding external reference in PHP - php

I am trying to use a function from SOAP, which will fetch details about a specific news item. The problem is that I don't get the expected results, just a a strange error. I am using the built-in SOAP client in PHP5.
My error is:
Fatal error: Uncaught SoapFault
exception: [Client] SOAP-ERROR:
Encoding: External reference
'https://newsclient.omxgroup.com/cdsPublic/viewDisclosure.action?disclosureId=379485&messageId=454590'
in
/home/********/public_html/********/updatenews3.php:15
My code is:
<?php
$login = '***';
$password = '***';
$client = new SoapClient(
'https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl',
array(
'login' => $login,
'password' => $password
));
$param = array('lastPublicationId' => 361825);
$result = $client->fetchNews($param);
?>
The error is the same for all lastPublicationId, where a result is found. It seems as if PHP is trying to load a link, which is found somewhere in the XML-reply (the URL, which is in the error message), and can't access it. Even though I have googled this a lot, I can't find any solution. The only thing I can find is that this seems to have been reported as a bug in a previous version of PHP, but the error refers to PHP 5.2.2 Since I'm using PHP 5.2.9, I'm thinking it can't be that. I'm suspecting the &-character to be the cause of this error?
The WSDL-file can be found here: https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl
Does somebody know this error, and know of any solution?

It's possible that the XML being returned by $client->fetchNews($param); isn't being escaped properly - there seems to be an unescaped & in the URL which is shown in the error message.
Best thing is probably to check exactly what XML is being returned, by turning on tracing and printing the last response:
$client = new SoapClient(
'https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl',
array(
'login' => $login,
'password' => $password,
'trace' => 1
));
$param = array('lastPublicationId' => 361825);
try {
$result = $client->fetchNews($param);
}
catch (SoapFault $sf) {
print '<pre>';
// print the exception
print_r($sf);
// print the XML response
print $client->__getLastResponse();
}
A workaround (if the server is returning invalid XML) is to use code similar to the above to catch the exception. You can then manually get at the XML returned (using __getLastResponse()), and clean it up yourself (e.g. using htmlenties or a regexp), before returning it and using it in the rest of your application.

Related

SOAP-ERROR: Parsing WSDL: Couldn't load from : Document is empty

I have check every configuration is perfect like, SOPA, CURL, XML, libxml in php.ini file. But I am getting issue. I don't know what is the issue. It's working on local machine but when i upload on server and check then it's not working. I am trying to integrate dynamic nav api using NTLMSoapClient but it's not working in server.
Please see Below Code
$product = new NTLMSoapClient(PRODUCT_URL);
/*$params_d = array('filter' => array(
),
'setSize' => 2);*/
$result = $product->ReadMultiple();
$productData = $result->ReadMultiple_Result->WebItems;
Please help me if you know any solution
This error message is really unspecific and could just mean that curl returned false, luckily you can use curl_error to find out what exactly went wrong. In my implementation it looked like this.
$this->buffer = curl_exec($this->ch);
if (curl_errno($this->ch)) {
$error = curl_error($this->ch);
throw new Exception('CURL error: ' . $error);
}

SOAP-ERROR: Parsing WSDL (PHP Version 5.6.17)

Really hoping someone can help with this as I just can't seem to resolve this issue.
I am having great difficulty with getting the code below to work on my website.
The purpose of the script is to return car lengths based on a provided registration number.
The problem is when I move this over to my live environment the script simply won't work. Please can anyone suggest a possible resolution? I don't understand why It works absolutely fine in the development environment but when I attempt to run it on my main site I get the following error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://website.com/CarLengthChecker.asmx?WSDL' : failed to load external entity "https://website.com/CarLengthChecker.asmx?WSDL"
<?php
$carReg = "0000000";
try{
$opts = array(
'http'=>array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$client = new SoapClient ('https://wesite.com/CarLengthChecker.asmx?WSDL',
array('stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE));
$result = $client->GetVehicleDetails(array(
'VRM' => $carReg,
));
print_r($result);
}
catch(Exception $e){
echo $e->getMessage();
}
?>
I can access the WSDL address from a browser on the live server just not from the script.
I have checked the PHP settings on live and can confirm that both OpenSSL & SOAP
are enabled.
The resolution I found for this was to use the nusoap library (www.sourceforge.net/projects/nusoap). This problem may have been specific to our to live server environment but I would recommend attempting it if you are experiencing similar issues.

Using PHP SOAP client in non-WSDL mode

I am working on an api for a client. I have received the following information:
API Url: http://xyz-crm.example/WebAPI/Custom/project_name/XML/
Username: foobar
password: spameggs
I need to configure the PHP SOAP client for the same in non-WSDL mode. I have written the following but it does not seem to work:
$wsdl = null;
$options = array(
'uri' => 'http://xyz-crm.example/WebAPI/Custom/project_name/XML/',
'location' => 'http://xyz-crm.exmaple.com/WebAPI/Custom/project_name/XML/',
'login' => 'foobar',
'password' => 'spameggs'
);
$client = new SoapCLient($wsdl, $options);
I just want to make a successful ping to the api at first. See if things are working fine. What am I doing wrong here?
Update 1
I made the following changes:
$wsdl = null;
$options = array(
'uri' => "http://xyz-crm.example/WebAPI/Custom/project_name/XML/",
'location' => "http://xyz-crm.example/",
'Username' => "foobar",
'Password' => "spameggs",
'soap_version' => '1.2'
);
$client = new SoapClient($wsdl, $options);
$client = $client->getListings();
I get the error: looks like we got no XML document
[Edit by me, hakre: This update was done as feedback to answer #1. It changes the location option using a shortened URL (reason not given by OP) and it adds the soap_version option (as suggested in answer #1, but not as constant but as string (containing an invalid value), so there should be no wonder this creates an error, a correct option value is given in answer #1 (the SOAP_1_1 constant) and by intention, the correct value would be the SOAP_1_2 constant for this example). Error message as commented by OP was "SOAP Fault: Wrong version."]
Update 2
I tried the following but it still fails:
$listing = $client->getListings();
$request = $client->__getLastRequest();
The execution stops at the first line itself without ever going to the second one.
[Edit by me, hakre: As review has shown wrong configuration options in Update 1 already which are not addressed in Update 2 it would be a miracle if it still wouldn't fail. The execution stops because an Exception is thrown and no error/exception handling is done]
Die URI or file ending does not matter, it could even be .jpg, there is no default.
Have a look at similiar questions: Does this SOAP Fault mean what I think it means?
It would be helpful if you put the error message into the question, aswell as the XML output of your request.
try setting the SOAP Version in the array of your SoapClient instance to one of the constants (try different ones):
new SoapClient($url, array("soap_version" => SOAP_1_1,.......
or SOAP_1_2 ...
To debug the XML try the answer from Inspect XML created by PHP SoapClient call before/without sending the request
The error message of your updated question does not look like it coming from PHP, looks more like an answer from the webservice, means your request is actually working.

Soap request failing. Server or code issue?

I'm trying to setup a data request for a site, but, am running into a problem when trying to pull the data.
I tested the url and credentials using http://www.soapclient.com/soaptest.html and it works perfectly so I know the service is up and the correct credentials are being entered, but, when using the code below, I'm given the following error;
Fatal error: Uncaught SoapFault exception: [Invalid Login] in...
The full code (except generalized URL) that I'm using to make the request is;
<?php
$client2 = new SoapClient("http://www.example.com/api/soap.php?wsdl", array('trace'=> true));
$results2 = $client2->boxInfo(array(
"customer" => 'XBLK',
"size" => "four",
"price" => "twenty"));
echo "<pre>";
var_dump($client2-> __getLastRequestHeaders());
var_dump($client2-> __getLastRequest());
var_dump($client2-> __getLastResponseHeaders());
var_dump($client2-> __getLastResponse());
var_dump($results2);
echo "</pre>";
?>
As I'm new to these calls, I'm not sure if I missed something with the SOAP installation when I updated php (I verified it's installed and enabled) or if I've just been staring at the code so long that I'm simply missing something obvious.
It's a client issue if it works elsewhere. Try using an object to hold the parameters instead of an array:
$params = new stdClass();
$params->customer = 'XBLK';
$params->size = 'four';
$params->price = 'twenty';
$results2 = $client2->boxInfo($params);

Soap 1.2 not working with stamps.com

I am feebly trying to implement a stamps.com api interface into my platform. This is my first time using SOAP, I event had to recompile PHP to enable the libraries.
I'm moving along but now I'm having a problem. They support soap 1.1 and soap 1.2 requests, and when I run the following code:
$client = new SOAPClient(
'./SWSIM.wsdl',
array(
'trace' => 1
)
);
I get back a successful response from my request that comes after this.
However if I add the option to use soap 1.2 like this:
$client = new SOAPClient(
'./SWSIM.wsdl',
array(
'trace' => 1,
'soap_version' => SOAP_1_2
)
);
I get the following error:
There was an exception running the extensions specified in the config file. ---> Value cannot be null. Parameter name: input
This line is not actually throwing the exception. Its the following command that throws it, but removing the soap_version is what "fixes it". I would like to use soap 1.2 so naturally this is bugging me.
FTR The command I'm running is this:
$authData = array(
"Credentials" => array(
"IntegrationID" => "MYUID",
"Username" => "MYUSERNAME",
"Password" => "MYPASSWORD"
)
);
try {
$objectresult = $client->AuthenticateUser($authData);
} catch (Exception $e) {
echo "EXCEPTION: " . $e->getMessage();
print_r($e);
exit;
}
The WSDL file can be viewed here:
https://swsim.stamps.com/swsim/swsimv22.asmx?wsdl
I have also checked in with their developer support and they said:
"The message you are currently receiving is returned from whichever program you are designing your integration with. This has been commonly noted happening within Visual Basic where is creates a wrapper class that needs certain variables for the response. This could be similar to the behavior that you are experiencing. Please verify how your program language consumes a WSDL."
I also noticed that the __soapCall method excepts an "input headers" argument. I'm not entirely sure I should be / can even use that method in my code. I suppose I should just try and play with it.
Check your WSDL file. I was using the wrong one, and it appears you may be as well. Try this one: http://developer.stamps.com/developer/downloads/files/Stamps.com_SWSIM.wsdl
NOTE: The above is out of date. Contact stamps.com for the current wsdl!
I know this is an old thread, but here is an example class that should get anyone started with the stamps.com api in php https://github.com/aaronjsmith/stamps.com-php
The WSDL looks fine and it's the same input structure for both Soap versions. The problem is a bug somewhere at their end, you'll have to contact them to resolve.
I would also test it via a .NET app just to see if it behaves the same.

Categories