php code not working for SOAP API, TNT - php

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

Related

I always get an error when trying to create a crawler in goutte

The error:
Fatal error: Uncaught TypeError: Return value of
Symfony\Component\DomCrawler\Crawler::createSubCrawler() must be an
instance of Symfony\Component\DomCrawler\object, instance of
Symfony\Component\DomCrawler\Crawler returned in
/Users/local/web.com/vendor/symfony/dom-crawler/Crawler.php:1215 Stack
trace:
#0 /Users/local/web.com/vendor/symfony/dom-crawler/Crawler.php(969): Symfony\Component\DomCrawler\Crawler->createSubCrawler(NULL)
#1 /Users/local/web.com/vendor/symfony/dom-crawler/Crawler.php(189): Symfony\Component\DomCrawler\Crawler->filterRelativeXPath('descendant-or-s...')
#2 /Users/local/web.com/vendor/symfony/dom-crawler/Crawler.php(169): Symfony\Component\DomCrawler\Crawler->addHtmlContent('', 'utf-8')
#3 /Users/local/web.com/vendor/symfony/browser-kit/Client.php(535): Symfony\Component\DomCrawler\Crawler->addContent('', 'text/html;
char...')
#4 /Users/local/web.com/vendor/symfony/browser-kit/Client.php(425): Symfony\Component\BrowserKit\Client->createCrawlerFromContent('https://stackov...',
'', 'text/html; c in
/Users/local/web.com/vendor/symfony/dom-crawler/Crawler.php on line
1215
here is my code:
$guzzle = new \GuzzleHttp\Client(['proxy' => 'http://91.205.174.26:80']);
$goutte = new \Goutte\Client();
$goutte->setClient($guzzle);
$crawler = $goutte->request('GET', 'https://stackoverflow.com/questions/35806758/setting-proxy-in-goutte');
the last line is the line that is giving the error. I have tried lots of things like changing $goutte = new \Goutte\Client(); to $client = \Symfony\Component\Panther\Client::createChromeClient(); which is using panther to create a client because everything works fine when I use panther, but when I integrate panther and other libraries I get this error:
Fatal error: Uncaught Error: Call to undefined method
Symfony\Component\Panther\Client::setClient()
none of the methods have worked.
Does anyone know a solution?

Uncaught SoapFault exception: [HTTP] Forbidden

I am new to SOAP API and WSDL. I had this project to use the SOAP API and I used this code from one of the stackoverflow answers. But when I am running this, I am getting this error.
Fatal error: Uncaught SoapFault exception: [HTTP] Forbidden in 'directory' Stack trace: #0 [internal function]: SoapClient->__doRequest('...') #1 directory): SoapClient->__call('method', Array) #2
Here is my code:
<?php
try{
$wsdl_url = 'API';
$client = new SoapClient($wsdl_url);
} catch (SoapFault $e) {
echo 'Error in Soap Connection : '.$e->getMessage();
}
$params = array(
'LBID' => '1',
'YearID' => '23',
'SectorId' => '3',
'Password' => 'password'
);
$result= $client->getProjectDetails($params);
print_r($result);
?>
I am able to access the api by directly putting it on address bar. The soap connection is established, no errors there. But this error is showing on the method calling line, $result= $client->getProjectDetails($params);
I don't know what this error is, I tried searching the forums but couldn't get any idea about this. Can anyone help?

can't access a web server using soap and wsdl

I wrote the following code:
<?php
$url = "https://ops.isignmedia.com/iSign-ear-iSign-ejb/DownloadServices4?wsdl";
$client = new SoapClient($url);
$fcs = $client->__getFunctions();
var_dump($fcs);
$res = $client->downloadData(array('startDateTime' => 'null', 'endDateTime' => 'null','accountCode' => 'xxxx', 'userName' => 'xxxx', 'password' => 'xxxx'));
print_r($res);
?>
The error that I get is the following:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/gsapte/public_html/grupsapte/test_webservice/isign.php:10 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://ip-172-3...', '', 1, 0) #1 /home/gsapte/public_html/grupsapte/test_webservice/isign.php(10): SoapClient->__call('downloadData', Array) #2 /home/gsapte/public_html/grupsapte/test_webservice/isign.php(10): SoapClient->downloadData(Array) #3 {main} thrown in /home/gsapte/public_html/grupsapte/test_webservice/isign.php on line 10
If I punt another wsdl address then using this method I can access all information I need. Question: what can be the reasons that I can't access that wsdl? can it be that is https instead of http?
If you open this WSDL then on the bottom you will see:
<port binding="tns:DownloadWebServices4Binding" name="DownloadWebServices4Port">
<soap:address location="http://ip-172-31-46-241.us-west-2.compute.internal:8080/iSign-ear-iSign-ejb/DownloadServices4"/>
</port>
This host might not be available. This is also visible in error message.
If you know other endpoint to this service try to use location or uri parameter to SoapClient.

SOAP, functions with in an object

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.

how do i call a method from a wsdl

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

Categories