Soap version mismatch in magento - php

I am new to SOAP. Below code works fine in my local environment, my php version is php-5.3.3 and soap client version 1_1.
`
require_once "../app/Mage.php";
Mage::app();
$client = new SoapClient('https://mydomain/api/soap?wsdl&type=soap');
$session_1 = $client->__getFunctions();
echo '<pre>'; print_r($session_1);echo '</pre>';
$session = $client->login('user', 'password');
// If you don't need the session anymore
$client->endSession($session);
`
When I try to execute this code in server(php-5.3.29 and soap client 1_1),
I am getting an error as following
` Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from ..`
Then we tried the code with some changes in server as
require_once "../app/Mage.php";
Mage::app();
$client = new SoapClient('http://mydomain/api/soap?wsdl&type=soap', Array(
'location' => 'http://mydomain/api/soap?wsdl&type=soap',
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version' => SOAP_1_1));
var_dump($client);
$session = $client->login('user', 'password');
I got this error
Fatal error: Uncaught SoapFault exception: [VersionMismatch] Wrong Version in ..
Also when we tried curl http://mydomain/api/soap? wsdl&type=soap , it worked fine.
Can any one help on this?

Not really sure if this is a help to you, but as there's a difference in PHP versions between the local and server environments, I thought it might help.
There's a PHP bug that was fixed in 5.3.11 that caused me to get a Version Mismatch error when trying to connect to the Royal Mail Shipping API in OpenCart.
Here's details of the bug: https://bugs.php.net/bug.php?id=49853
Basically, the stream_context part of the http header is being ignored, and that contains the client ID and secret.
Contained within is a workaround:
ini_set('user_agent', 'PHP-SOAP/' . PHP_VERSION . "\r\n" . $str_auth_header);
where
$str_auth_header = "Authorization: Bearer ". $str_token;
$arr_context = array('http' =>array('header' => $str_auth_header));
$obj_context = stream_context_create($arr_context);

Related

PHP SOAP web service non-wsdl mode not working, "Could not connect to host"

I'm trying to make a simple PHP web service that returns a simple message. I have enabled SOAP in php.ini. I'm getting the following error:
SoapFault exception:
[HTTP] Could not connect to host in D:\AppServ\www\projectName\SOAPWSTest\client.php:11
Stack trace:
#0 [internal function]: SoapClient->__doRequest('__soapCall('flag', Array)
#2 {main}string(494) " "
Line 11 corresponds to the __soapCall. __getLastRequest returns nothing. I tried setting soap_version to SOAP_1_2 or SOAP_1_1 to no avail. I have to set connection_timeout to 1 because if not, the browser takes forever to do a timeout and return the same message. I don't know what I'm doing wrong. Firewalls and whatnot are probably not a problem, as other parts of the project work perfectly.
One of my guesses would be that the namespace is wrong, but I haven't found a good and simple explanation of how the namespace works. Also, all simple web service examples I have tried implementing give me the same problem, which leads me to think this is some kind of configuration problem.
Codes are as follows:
Server:
<?php
function flag(){
return "<img src='http://usa.fmcdn.net/data/flags/w580/ga.png' alt='Georgia'>";
}
$server = new SoapServer(null, array('uri' => "http://localhost:81/projectName/SOAPWSTest/"));
$server->addFunction('flag');
$server->handle();
Client:
<?php
print "<h1>SOAP Client</h1>";
print "<h2>Echo Web Service</h2>";
$client = new SoapClient(null, array(
'connection_timeout' => 1,
'trace' => TRUE,
'exceptions' => FALSE,
'location' => "http://localhost:81/projectName/SOAPWSTest/server.php",
'uri' => "http://localhost:81/projectName/SOAPWSTest/"
));
print $client->__soapCall("flag", array(null));
print "</br></br>Last request:</br></br>" . var_dump($client->__getLastRequest());

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.

Issue in curl connecting with Ip address in zend

Dear Supporter,
$data=array(
"themeName"=>"gghg"
);
$adapter = new Zend_Http_Client_Adapter_Curl();
$adapter->setConfig($curlOption);
//instantiate the http client and add set the adapter
$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");
$client->setAdapter($adapter);
//add the post parameters from our config file (the authentication part)
$client->setParameterPost($data);
//perform the post, and get the response
$response = $client->request(Zend_Http_Client::POST);
Error :
Fatal error: Uncaught exception 'Zend_Uri_Exception' with message 'Invalid URI supplied' in /var/www/html/ursify/Source/ursify.com/library/Zend/Uri/Http.php:
I am trying to create client object "$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");"
Where i am doing wrong ? Help me
Seems everything fine. I've tested your code and there are no errors except timeout in cUrl call. I've tested with ZF 1.12.7

Receive error when running basic nuSOAP tutorial

I am trying to create a website that retrieves data from a Web Service using the site API.
The 'nuSOAP' PHP library seems to be a perfect way to go about this and so I have been trying to run through a basic tutorial by Scott Nichol called 'Introduction to NuSOAP'.
Here is the code for server.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
...and here is the code for the client.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/beehive/server.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'John'));
// Display the result
print_r($result);
?>
I have 'XAMMP' installed and so when I call up client.php via the browser it should bring up a basic page that says 'Hello, John' but instead I get the following error message:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '.../server.php' : Start tag expected, '<' not found in C:\xampp\htdocs\beehive\client.php:7 Stack trace: #0 C:\xampp\htdocs\beehive\client.php(7): SoapClient->SoapClient('http://...') #1 >{main} thrown in C:\xampp\htdocs\beehive\client.php on line 7
I figured I should be loading the client page rather than the server, but if I load server.php then I get the error message 'This service does not provide a Web description'.
I have followed the tutorial exactly and can't figure out why it's throwing this error; can anyone please help?
Thank you!
The error you receive makes perfect sense with your error description. The server isn't responding with the right format and therefor your client breaks.
The same error is discussed here:
nusoap simple server
You need to point the client constructor to your wsdl file...
$client = new soapclient('http://localhost/beehive/server.php');

SOAP error encoding external reference in 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.

Categories