Okay so I have a Python server running and I've been using "suds" as a client side which has been surprisingly easy, when I tried to run a similar code in PHP I got very confused since I was a beginner with it?
from suds.client import Client
url = 'http://localhost:8080/FlightService?wsdl'
client = Client(url=url)
output = client.service.getFlightList("dxb","ksa")
print(output)
is there something with this ease in php or can anyone show me a sample code which would return the same result?
Considering the server receives this:
class Input(complextypes.ComplexType):
dpt = str
arr = str
and returns a list of flights
class flight(complextypes.ComplexType):
id = int
dpt = str
arr = str
price = float
date = str
tickets = int
this is the webservice:
#webservice(_params=Input,_returns=[flight])
def getFlightList(self, input):
my PHP segment:
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$result = $client->bookFlight("dxb","ksa");
$result2 = $client->handle();
echo($result);
echo($result2);
?>
PHP Error:
Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in C:\wamp\www\soap\soap.php:6 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://172.27.1...', 'http://172.27.1...', 1, 0) #1 C:\wamp\www\soap\soap.php(6): SoapClient->__call('getFlightList', Array) #2 C:\wamp\www\soap\soap.php(6): SoapClient->getFlightList('dxb', 'ksa') #3 {main} thrown in C:\wamp\www\soap\soap.php on line 6
Exception info:
SoapFault Object ( [message:protected] => Error Fetching http headers [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\wamp\www\soap\soap.php [line:protected] => 6 [trace:Exception:private] => Array ( [0] => Array ( [function] => __doRequest [class] => SoapClient [type] => -> [args] => Array ( [0] => ksa [1] => http://172.27.130.98:8080/FlightService [2] => http://172.27.130.98:8080/FlightService/getFlightList [3] => 1 [4] => 0 ) ) [1] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => getFlightList [1] => Array ( [0] => dxb [1] => ksa ) ) ) [2] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => getFlightList [class] => SoapClient [type] => -> [args] => Array ( [0] => dxb [1] => ksa ) ) ) [previous:Exception:private] => [faultstring] => Error Fetching http headers [faultcode] => HTTP [xdebug_message] => ( ! ) SoapFault: Error Fetching http headers in C:\wamp\www\soap\soap.php on line 6 Call Stack #TimeMemoryFunctionLocation 10.0006243160{main}( )..\soap.php:0 20.0758264872getFlightList ( )..\soap.php:6 30.0758265336__call ( )..\soap.php:6 )
this solution worked for me, i instantiated an associative array with the name of variables i'm expecting at server side then used var_dump to get the result of the output
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$trip["dpt"] = "dxb";
$trip["arr"] = "krt";
try{ $output = $client->getFlightList($trip);
}
catch(soapFault $e)
{
print_r($e);
}
var_dump($output);
?>
Related
I'm implementing a simple webservice client in Moodle 3.3 and testing some functions. For some reason, this doesn't seem to be working.
<?php
$token = '.......';
$domainname = 'http://localhost/moodle';
$functionname = 'core_course_get_contents';
$cid = 5;
/// SOAP CALL
$serverurl = $domainname . '/webservice/soap/server.php'. '?wsdl=1&wstoken=' . $token;
////Do the main soap call
$client = new SoapClient($serverurl);
try {
$resp = $client->__soapCall($functionname, array($cid));
} catch (Exception $e) {
print_r($e);
}
if (isset($resp)) {
print_r($resp);
}
I keep getting the error below:
SoapFault Object ( [message:protected] => Invalid parameter value detected | ERRORCODE: invalidparameter [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/html/client.php [line:protected] => 15 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/html/client.php [line] => 15 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ( [0] => core_course_get_contents [1] => Array ( [0] => 5 ) ) ) ) [previous:Exception:private] => [faultstring] => Invalid parameter value detected | ERRORCODE: invalidparameter [faultcode] => Receiver [faultactor] => invalidparameter [detail] => options => Invalid parameter value detected: Only arrays accepted. The bad value is: '' )
The documentation for the webservice is:
REST (POST parameters)
courseid= int
XML-RPC (PHP structure)
[options] =>
Array
(
[0] =>
Array
(
[name] => string
[value] => string
)
)
According to the code: https://github.com/moodle/moodle/blob/ae82333cf25219ba627538f7e8de72f0b4028460/course/externallib.php#L49
The expected params are:
courseid
options (optional)
So, I would expect the call to look something like:
$resp = $client->__soapCall($functionname, array('courseid' => $cid));
If you wanted to specify any of the options, it would look like:
$resp = $client->__soapCall($functionname, array('courseid' => $cid, 'options' => [['name' => 'nameofoption', 'value' => 'valuetoset'], ['name' => 'secondoption', 'value' => 'secondvalue]]));
I am using the UPS courier service for the delivery of the packages. In my website I need to display the delivery status of a particular order using the tracking number, I used the following example,
https://github.com/chetan/php-ups-api
I added the access key, username and password in the config file. and I am using tracking.php file fro this library for testing purpose. But I get the following error,
Fatal error: require_once(): Failed opening required 'XML/Unserializer.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/project/php-ups-api-master/UpsAPI/Client.php on line 119
Can anyone please tell me where can I get this file.
I have also tried using
https://www.ups.com/upsdeveloperkit/downloadresource?loc=en_US
\project\TrackingPACKAGE\TRACKINGWebServices\CodeSamples\Track\PHP\SoapTrackClient.php file
I have added,
$wsdl = "../../../SCHEMAS-WSDLs/Track.wsdl";
as the parameter.
But get the following error,
SoapFault Object ( [message:protected] => An exception has been raised as a result of client data. [string:Exception:private] => [code:protected] => 0 [file:protected] => /home/project/TrackingPACKAGE/TRACKINGWebServices/CodeSamples/Track/PHP/SoapTrackClient.php [line:protected] => 62 [trace:Exception:private] => Array ( [0] => Array ( [file] => /home/project/TrackingPACKAGE/TRACKINGWebServices/CodeSamples/Track/PHP/SoapTrackClient.php [line] => 62 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ( [0] => ProcessTrack [1] => Array ( [0] => ) ) ) ) [previous:Exception:private] => [faultstring] => An exception has been raised as a result of client data. [faultcode] => Client [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ [detail] => stdClass Object ( [Errors] => stdClass Object ( [ErrorDetail] => stdClass Object ( [Severity] => Authentication [PrimaryErrorCode] => stdClass Object ( [Code] => 250002 [Description] => Invalid Authentication Information. ) ) ) ) [xdebug_message] => ( ! ) SoapFault: An exception has been raised as a result of client data. in /home/project/TrackingPACKAGE/TRACKINGWebServices/CodeSamples/Track/PHP/SoapTrackClient.php on line 62 Call Stack #TimeMemoryFunctionLocation 10.0006132036{main}( )../SoapTrackClient.php:0 20.0079240060SoapClient->__soapCall( )../SoapTrackClient.php:62 )
Please help me.
Error message tell that you need install PEAR Serializer package: https://pear.php.net/package/XML_Serializer/
I got converted WSDL to PHP script but something is not working very I am trying to connect http://www.regcheck.org.uk/api/reg.asmx?wsdl, but getting this error
Array ( [RegCheckServiceCheck::Check] => SoapFault Object ( [message:protected] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line:protected] => 32 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => Check [1] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => Check [class] => SoapClient [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) [2] => Array ( [file] => C:\xampp\htdocs\sample-regcheck.php [line] => 46 [function] => Check [class] => RegCheckServiceCheck [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [previous:Exception:private] => [faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [faultcode] => soap:Server [detail] => ) )
I am sure something is missing in config files, mybe someone got idea ?
It's possible to call that web service via a HTTP GET request as follows;
<?php
$username = 'Your username here';
$regNumber = 'SK08KPT';
$xmlData = file_get_contents("https://www.regcheck.org.uk/api/reg.asmx/Check?RegistrationNumber=" . $regNumber ."&username=" . $username);
$xml=simplexml_load_string($xmlData);
$strJson = $xml->vehicleJson;
$json = json_decode($strJson);
print_r($json->Description);
?>
Not as elegant as a SOAP call, but simpler.
Script open source files
You can see all main files
https://www.wsdltophp.com/Wsdls/8a71627601a684624c5694104cce023f/RegCheck-1-0-1-1-1-1-0-0-0-0
i have create yii framework based wsdl service:
from the link :-
http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice
and facing the issues that is their in the comment
http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice#c6656
and server create fine as i am able to see the wsdl file
but when i try to access the method by the code from external file not in yii site folder
below file is inside another folder not in mysite_yii folder hope that not create any issue as it has to call the wsdl file
$client=new SoapClient('http://localhost/mysite_yii/index.php?r=stock/quote');
try
{
echo $client->getPrice('GOOGLE');
}
catch(Exception $e)
{
echo "<pre>";
print_r($e);
}
i am getting the following exception
SoapFault Object
(
[message:protected] => Function ("getPrice") is not a valid method for this service
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/serverclient/stock.php
[line:protected] => 9
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /var/www/serverclient/stock.php
[line] => 9
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => getPrice
[1] => Array
(
[0] => GOOGLE
)
)
)
[1] => Array
(
[file] => /var/www/serverclient/stock.php
[line] => 9
[function] => getPrice
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => GOOGLE
)
)
)
[previous:Exception:private] =>
[faultstring] => Function ("getPrice") is not a valid method for this service
[faultcode] => Client
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)
i have done the same changes as suggested in the comment but not able to call that method
any suggestions ?
Thanks in advance
you must off the server cache for soap, u can off it by adding
ini_set("soap.wsdl_cache_enabled", "0"); to your code
This question already has answers here:
Does this SOAP Fault mean what I think it means?
(3 answers)
Closed 8 years ago.
There is nothing too much to write here other than this error message :
SoapFault Object ( [message:protected] => Wrong Version [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\wamp\www\nsoap\phpclient.php [line:protected] => 10 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\wamp\www\nsoap\phpclient.php [line] => 10 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => getIMIPremium [1] => Array ( [0] => Array ( [imiPolicy] => Array ( [expiryDate] => 23-09-2013 [imiInsured] => Array ( [item] => Array ( [item] => Array ( [age] => 23 [basicSumInsured] => 33233 [coverRageType] => 12 [dateOfBirth] => 26-09-1986 [preExistingDisease] => no ) ) ) [inceptionDate] => 12-09-2009 [noOfInsured] => 1 [partnerCode] => 2121 [stateCode] => 233 ) ) ) ) ) [1] => Array ( [file] => C:\wamp\www\nsoap\phpclient.php [line] => 10 [function] => getIMIPremium [class] => SoapClient [type] => -> [args] => Array ( [0] => Array ( [imiPolicy] => Array ( [expiryDate] => 23-09-2013 [imiInsured] => Array ( [item] => Array ( [item] => Array ( [age] => 23 [basicSumInsured] => 33233 [coverRageType] => 12 [dateOfBirth] => 26-09-1986 [preExistingDisease] => no ) ) ) [inceptionDate] => 12-09-2009 [noOfInsured] => 1 [partnerCode] => 2121 [stateCode] => 233 ) ) ) ) ) [previous:Exception:private] => [faultstring] => Wrong Version [faultcode] => VersionMismatch [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ [xdebug_message] => ( ! ) SoapFault: Wrong Version in C:\wamp\www\nsoap\phpclient.php on line 10 Call Stack #TimeMemoryFunctionLocation 10.0009674576{main}( )..\phpclient.php:0 20.0704702744SoapClient->getIMIPremium( )..\phpclient.php:10 )
Is it possible that there is an error in the client php code for it ? I have tried NuSoap, but it is also generating error that "Call error: Response not of type text/xml: application/wsdl+xmlHTTP/1.1 200 OK Date: Tue, 17 Sep 2013 16:55:39 GMT Server: Apache/2.2.22 (Win64) PHP/5.3.13 Last-Modified: Tue, 17 Sep 2013 13:18:39 GMT ETag: "a0000000a818c-12e9-4e69428b54054" Accept-Ranges: bytes Content-Length: 4841 Connection: close Content-Type: application/wsdl+xml ".
Do you know any fix for it ?
PHP Code :
<?php
try{
$client = new SoapClient("http://mysite.com/nsoap/IMIPremiumWebService.wsdl");
$args= array("imiPolicy" => array("expiryDate" => "23-09-2013", "imiInsured" =>array("item" => array("item" => array("age"=>'23', "basicSumInsured"=>'33233', "coverRageType"=>'12',"dateOfBirth"=>'26-09-1986',"preExistingDisease" => 'no'))), "inceptionDate"=>"12-09-2009" ,"noOfInsured"=>'1',"partnerCode" => '2121', "stateCode" => '233'));
$something = $client->getIMIPremium($args);
echo $client->responseData;
print_r($something);
}
catch (Exception $e)
{
echo "*****************";
print_r($e);
}
?>
You can find wsdl here (in my question related to NuSOAP:
WSDL Client Not Working
A little bit of googling with that particular error message reveals that it might be related to the Soap server answering in Soap version 1.2, while the default setting in PHP is Soap version 1.1.
Try adding an options array to the SoapClient with array('soap_version'=> SOAP_1_2) as the second parameter (see http://de1.php.net/manual/en/soapclient.soapclient.php for details).