cancel
Showing results for 
Search instead for 
Did you mean: 

PHP Web Service

PHP Web Service

Hi,

 

Is it possible to do PHP Web Service without AJAX? 

 

We already did Web Service using AJAX. But now we need to convert by using the only PHP. Not included with AJAX. 

 

Is it possible?. If yes please give any sample code for that.

 

Thanks

3 REPLIES 3

Re: PHP Web Service

Hi,

 

Do you want to connect to a web service from PHP or do you want to create a web service in PHP? Ajax refers to a browser doing an asynchronous request from the client browser to a web service. If I understand your question correctly you want to connect to a web service from inside PHP. You can achieve this using the SoapClient or using curl.

If my answer helps you solve your problem don't forget to accept it as a solution.

Re: PHP Web Service

Hi,

 

Thanks for your reply!

 

Yes, your right. I want to connect a web service from inside PHP.

And added PHP code with SoapClient also. I added the following code:

 

$wsdl = "http://xx.xx.xxx.xxx:xx/SalesOrder.asmx?wsdl";
$client = new SoapClient($wsdl, array('trace'=>1)); // The trace param will show you errors stack

// web service input params
$request_param = array(
"productnumber" => $productnumber,
"productname" => $name,
"sku" => $sku,
"quantity" => $productIds["quantity"],
"price" => $productIds["base_subtotal"],
"customername" => $productIds["customername"],
"region" => $region,
"postcode" => $postcode,
"street" => $street,
"city" => $city,
"telephone" => $telephone,
"customer_email" => $productIds["customer_email"],
"status" => $productIds["status"],
"shipping_description" => $productIds["shipping_description"],
"customer_id" => $productIds["customer_id"],
"base_grand_total" => $productIds["base_grand_total"],
"base_tax_amount" => $productIds["taxamt"],
"base_currency_code" => $productIds["base_currency_code"],
"base_shipping_amount" => $productIds["base_shipping_amount"]
);

try
{
$responce_param = $client->readSalesOrder($request_param);
//$responce_param = $client->call("readSalesOrder", $request_param); // Alternative way to call soap method
}
catch (Exception $e)
{
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}

 

But I got the following Error:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xx.xx.xxx.xxx:xx/SalesOrder.asmx/readSalesOrder' : failed to load external entity "http://xx.xx.xxx.xxx:xx/SalesOrder.asmx/readSalesOrder"

 

Please help to fix the above issue.

 

Thanks,

Re: PHP Web Service

Do you have access to the wsdl from the machine that you are calling it from? If you do, can you provide the wsdl. Secondly are you connecting over SSL? The third thing it could be is that you are connecting to a SOAP1.2 service. You can play around with the below code to see if it helps:

// options for ssl in php 5.6
$opts = array(
    'ssl' => array(
        'ciphers' => 'RC4-SHA',
        'verify_peer' => false,
        'verify_peer_name' => false
    )
);

// SOAP 1.2 client
$params = array(
    'encoding' => 'UTF-8',
    'verifypeer' => false,
    'verifyhost' => false,
    'soap_version' => SOAP_1_2,
    'trace' => 1,
    'exceptions' => 1,
    'connection_timeout' => 180,
    'stream_context' => stream_context_create($opts)
);

$client = new SoapClient($wsdl, $params);
If my answer helps you solve your problem don't forget to accept it as a solution.