I'm fairly new to SOAP and PHP and I'm having some troubles, that I hope someone here on Stack Overflow can help me with.
I'm trying to use this code to post a xml file (retursvar.xml).
I'm using this code to post the file:
<?php
$url = "https://someserver/somefunction";
$options = array(
'login' => 'someusername',
'password' => 'somepassword',
'trace' => 1
);
$client = new SoapClient($url.'?wsdl', $options);
$document = file_get_contents('retursvar.xml');
$params = array('SubmitDocument' => $document);
$response = $client->__soapCall('submitDocument', $params);
but I get this error in the Apache error log:
PHP Fatal error: Uncaught SoapFault exception: [bpws:forcedTermination] business exception in /var/www/html/soaptest.php:15\nStack trace:\n#0 /var/www/html/soaptest.php(15): SoapClient->__soapCall('submitDocument', Array)\n#1 {main}\n thrown in /var/www/html/soaptest.php on line 15
If i call:
var_dump($client->__getFunctions());
immediately after:
$client = new SoapClient($url.'?wsdl', $options);
I get this output:
array(1) { [0]=> string(62) "SubmitDocumentResponse submitDocument(SubmitDocument $payload)" }
What am I doing wrong?
It says that you haven't caught an exception. Try wrapping your code inside try catch block.
Related
i'm a new using soap services, so i have a problem when i consume a soap service using soapclient in php. this is the request at soap:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sia="https://misite.com/">
<x:Header/>
<x:Body>
<sia:cuis>
<SolicitudCuis>
<codigoAmbiente>2</codigoAmbiente>
<codigoModalidad>1</codigoModalidad><codigoPuntoVenta>0</codigoPuntoVenta>
<codigoSistema>79612597C2915E</codigoSistema>
<codigoSucursal>0</codigoSucursal>
<nit>6409401</nit>
</SolicitudCuis>
</sia:cuis>
</x:Body>
</x:Envelope>
ok, and this is my code php to consult an a function of the soapservice:
<?php
$token_to_access="apikey: TokenApi eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJqb2VfZW1wcmVzYSIsImNvZGlnb1Npc3RlbWEiOiI3MUU4NzY1QTk2MTI1OTdiOiJTRkUifQ.xh5SF_yeo0II_wabdK_dTRTe9LSdBmfMUursWwiNx9UUdTpAhF6nkqoxzSTxTV1NlqFqauAG7LLgCdWw5ug8ew";
$wsdl="``https://pilotomysite/v2/genCodes?wsdl``";
$context = array(
'http' => array(
'header' => $token_to_access //user token catured in your sesuite account details
));
$client = new SoapClient(
$wsdl,
array(
"trace" => 1, // enable trace
"exceptions" => 1, // enable exceptions
"stream_context" => stream_context_create($context)
));
$parameters=['codigoAmbiente'=>'2','codigoModalidad'=>1,'codigoPuntoVenta'=>0,'codigoSistema'=>'79612597C291','codigoSucursal'=>0,'nit'=>'6409401'];
//$response=$client->__soapCall('cuis',$parameters);
$client->solicitudCuis(2,1,0,'79612597C2915E',0,6409401);
//var_dump($client->__getTypes());`
?>
additional, this is the result of __getTypes()
[25]=>
string(45) "struct cuis {
solicitudCuis SolicitudCuis;
}"
[26]=>
string(145) "struct solicitudCuis {
int codigoAmbiente;
int codigoModalidad;
int codigoPuntoVenta;
string codigoSistema;
int codigoSucursal;
long nit;
}"
i dont know how to must send the parameters to fill the request... or maybe i'm writing bad my array or i dont know xd
when i do php myclientsoap.php at terminal, i have this error:
jose#jose-Lenovo-V14-ADA:~/projects/soapclient$ php soapclient.php PHP Fatal error: Uncaught SoapFault exception: [Client] Function ("solicitudCuis") is not a valid method for this service in /home/jose/projects/soapclient/soapclient.php:22 Stack trace: #0 /home/jose/projects/soapclient/soapclient.php(22): SoapClient->__call() #1 {main} thrown in /home/jose/projects/soapclient/soapclient.php on line 22
Your problem is when you call the soap method.
$respuestaSoap = $WebService->__soapCall('solicitudCuis',array($parameters));
Your client canĀ“t find the method that you are calling.
Edit: you should have the soap extension enabled, see here
This is my code:
$this->options = [
"login" => $username,
"password" => $password
];
try {
$this->request = new SoapClient('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl', $this->options);
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
And this is the error message:
Fatal error: Uncaught Exception: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl' : failed to load external entity "https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl"
Any idea how I can fix this error?
[UPDATE]
I can get functions with this code:
$wsdl = file_get_contents('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl');
But this code still gets error:
SoapClient('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl', $this->options);
try from command line:
wget https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl
or
php -r '$a = new SoapClient("https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl"); var_dump($a);'
Maybe resource id not available from tour host
To handle SOAP exceptions, you can give this answer a try. Following code is standalone code which is returning a SOAP response.
$params = array(
"login" => "USERNAME",
"password" => "PASSWORD"
);
try {
$client = new SoapClient('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl', array($params));
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
To List all available SOAP functions:
echo " List of available SOAP functions <br/><pre>"; var_dump($client->__getFunctions()); echo "</pre>";
To List all available SOAP types:
echo "List of SOAP types <br/><pre>"; var_dump($client->__getTypes()); echo "</pre>";
This answer has an explanation about how to access any available SOAP function.
Im new to Five9 i got some sample code in GitHub (https://github.com/kielerrr/Five9 ) which i went though the code and i passed the credentials into API but i get the following error
"Fatal error: Uncaught Error: Class 'SoapClient' not found in C:\xampp\htdocs\Five9-master\includes\Five9.php:20 Stack trace: #0 C:\xampp\htdocs\Five9-master\contacts\getContactRecords.php(12): f9->__construct() #1 {main} thrown in C:\xampp\htdocs\Five9-master\includes\Five9.php on line 20"
$wsdl_five9 = "https://api.five9.com/wsadmin/v4/AdminWebService?wsdl&user=User_ID";
//$wsdl_five9 = "https://api.five9.com/wsadmin/v4/AdminWebService?wsdl";
try {
$soap_options = array('login' => 'uer_name', 'password' => 'mypassword', 'trace' => true);
$this->_connection = new SoapClient($wsdl_five9, $soap_options);//20th line
} catch (Exception $e) {
$error_message = $e->getMessage();
echo $error_message."ERROR";
exit;
}
Please help me to go through this ...
The Above code works fine need to enable soap in your system .
locate your php.ini file and Un-comment(remove semicolon before soap extension)as below.
change from :
";extension=php_soap.dl"
to :
"extension=php_soap.dll" .
I am working on TNT SOAP based API, I am using below code but gets only error, I can`t understand what I am doing wrong ?
ini_set("default_socket_timeout",120);
$client = new SoapClient('https://uat.tntexpress.com.au/Webservices/Conservice/ConsignmentService.svc?wsdl');
$params = array(
'payingAccount' => '20003191',
'UserName' => 'NEX-APIT',
'Password' => 'NEX_APIPWT'
);
$response = $client->__soapCall('ProcessConsignmentRequest',$params);
print_r($response);
I am getting this error :
Fatal error: Uncaught SoapFault exception: [s:Client] The creator of this fault did not specify a Reason. in D:\xampp\htdocs\tnt\soap.php:11
Stack trace:
#0 D:\xampp\htdocs\tnt\soap.php(11): SoapClient->__soapCall('ProcessConsignm...', Array)
#1 {main} thrown in D:\xampp\htdocs\tnt\soap.php on line 11
I found here the working code tnt-express
I am doing the following to expose the functions of an object via soap but it gives me as error
Server:
$soap_wrapper = new my_geo_soap_wrapper();
$soap_wrapper->set_geo_app($my_geo);
$server = new SoapServer(null, array('uri' => "urn://localhost/firstmobile"));
$server->setObject($soap_wrapper);
$server->handle();
Client:
$client = new SoapClient(null, array(
'location' => "http://127.0.0.1/firstmobile/simple_server.php",
'uri' => "http://127.0.0.1/firstmobile/"
));
$result = $client->__soapCall("geolocate",array($lat,$lng));
print $result;
Error:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Call to a
member function geolocate() on a non-object in
/home/imran/projects/firstmobile/simple_client.php:15 Stack trace: #0
/home/imran/projects/firstmobile/simple_client.php(15):
SoapClient->__soapCall('geolocate', Array) #1 {main} thrown in
/home/imran/projects/firstmobile/simple_client.php on line 15
I think the error is somewhere in the my_geo_soap_wrapper class. If I read your code, and the error, correctly, the SOAP call ($client->__soapCall("geolocate",array($lat,$lng));) is mapping to $soap_wrapper->geolocate($lat,$lng) on the SOAP server end.
Based purely on the name of the class, I wonder if this "my_geo_soap_wrapper" class is delegating to some other object, which also has a method called geolocate, and this is where the bug is? e.g.
class my_geo_soap_wrapper
{
function geolocate($lat,$lng)
{
// Will blow up if $this->delegated_object hasn't been set correctly
return $this->delegated_object->geolocate($lat,$lng);
}
}
Pure speculation, but might suggest a route to investigate.