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
Related
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.
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
Fatal error: Uncaught SoapFault exception: [Client] Function ("AuthenticationHeader") is not a valid method for this service in D:\xampp\htdocs\soap\index_2.php:132 Stack trace: #0 D:\xampp\htdocs\soap\index_2.php(132): SoapClient->__call('AuthenticationH...', Array) #1 D:\xampp\htdocs\soap\index_2.php(132): SoapClient->AuthenticationHeader(Array) #2 {main} thrown in D:\xampp\htdocs\soap\index_2.php on line 132
There are must be only one request, you send three. You must create something like this:
1) Set header for authentication:
$auth = $auth = new SOAPAuth('USERNAME', 'PASSWORD');
$header = new SOAPHeader('urn:example.org/auth', 'AuthenticationHeader', $auth);
$client->__setSoapHeaders($header);
2) Create create request with message text and contacts.
$result = $client->SendSMSToContacts(array("MessageText" => "some text", "contactIDs" => array(123456789, 123456789));
P.S. For the debugging create client with:
$client = new SoapClient($url, array('trace' => 1,
'exceptions' => 1,));
and after sending request, look on request that was sended and resopnse on it:
var_dump("REQUEST=", $client->__getLastRequest());
var_dump("RESPONSE=", $client->__getLastResponse());
if you look at the error code you will see AuthenticationHeader is not a method! the error is very clear!
use this
or download soap ui. (google it!)
and you will see what method are available!
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.
i am trying to call a method from a wsdl and getting an error. i am new to soap and learning all i can. i know rest is better but i really want to learn soap. this is what i have so far:
ini_set('soap.wsdl_cache_enable', '0');
$client = new SoapClient('http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl');
$data = $client->__soapCall('GetQuote', array('GetQuote' => 'aapl'));
print $data;
the error i get is
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /Volumes/www/public/soap/s.php:5 Stack trace: #0 /Volumes/www/public/soap/s.php(5): SoapClient->__soapCall('GetQuote', Array) #1 {main} thrown in /Volumes/www/public/soap/s.php on line 5
thanks
You can see all required parameters for the GetQuote request in http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl
You should pass a StockSymbol and LicenseKey. Example of request:
ini_set('soap.wsdl_cache_enable', '0');
$client = new SoapClient('http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl');
$data = $client->GetQuote(array('StockSymbol' => 'TEST_STR','LicenseKey' => 'TEST_STR'));
print_r($data);
Replace TEST_STR with your data