Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]

like image 876
Varun Jain Avatar asked Oct 29 '13 08:10

Varun Jain


Video Answer


1 Answers

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.

like image 104
Daniel W. Avatar answered Sep 27 '22 18:09

Daniel W.