I have a problem that a few days my service returns an
[faultstring] => Wrong Version
[faultcode] => VersionMismatch
but also returns and response.
Here is my code:
<?php
$wsdl = "..?wsdl";
$client = new SoapClient($wsdl, array('location' => $URL, 'trace' => 1) );
try {
$req = array("GetTime" =>
// my request
);
$data = $client->__soapCall("GetTime", $req);
$result = json_decode(json_encode($data), true);
} catch (Exception $e) {
echo "<pre>";
print_r($client->__getLastResponse());
echo "</pre>";
}
?>
I try with soap_version' => SOAP_1_1 and soap_version' => SOAP_1_2 but without success.
The strangest is however I'm getting response from the service with "$client->__getLastResponse()".
Does anyone have any idea where it came from this problem? I would be grateful if some an idea how to deal with the problem.
Related
I made a research on web but I couldn't find the exact answer for my question. I am trying to make a request to a SOAP service. I can get a proper response when I try with SOAPUI but I can't get anything when I try it with PHP.
Here is a screenshot of SOAPUI: (Backup URL: http://i.hizliresim.com/qGaOOd.png)
Here is my PHP code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$wsdl = "http://www.estes-express.com/shipmenttracking/services/ShipmentTrackingService?wsdl";
$options = array(
'auth' => array(
'user' => 'myuser',
'password' => 'mypass'
)
);
$request = array(
'search' => array(
'requestID' => '0841824923',
'pro' => '0841824923'
)
);
$client = new SoapClient($wsdl, $options);
echo '<pre>'.print_r($client,true).'</pre>';
try{
$response = $client->__soapCall('trackShipments', array($request));
print_r($response);
} catch(SoapFault $ex){
echo $ex->getMessage();
}
print "\n";
When I run this script, it returns this error: "java.lang.NullPointerException"
Any solutions? Thanks in advance.
Guys I have an issue I have been learning soap the last few days, I've been trying to connect to a web service for online store to verify users tv licenses before they can purchase a tv set.
I have written the following code to test the web service provided by TV licenses company.
<?php
$wdsl = "https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl";
$options = array(
'trace' => true,
'exceptions' => true,
'connection_timeout' => 1
);
try{
$client = new SoapClient($wdsl,$options);
$apiauth = array(
'Rquid' => '3600cd32-28b9-4a4f-a522-4326def4a9c2',
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d',
'AccountIdentifier' => '9211186012088',
'AccountIdentifierType' => 'SaidNumber');
$header = new SoapHeader('http://tempuri.org/','Auth',$apiauth,true);
$client->__setSoapHeaders($header);
$account = $client->GetAccount();
var_dump($account);
echo "<pre>";
var_dump($client);
echo "</pre>";
}catch (Exception $e) {
echo "Error!";
echo $e->getMessage() . "<br>";
echo 'Last response: ' . $client->__getLastResponse();
}
?>
The wdsl does not require a client certificate, the api key above is for testing only.
The problem I always hit
unable to connect to host
But if I write an invalid function I get an error that the function is invalid for this services, When I use __GetFunctions() I do see the functions in the services, but when I try to use one of them I hit could not connect to host, Can guys help me out to connect to this service.
hopefully this should get you going, I assume that the live wsdl will work correctly without having to call __setLocation()
<?php
$wdsl = "https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl";
$options = array(
'trace' => true,
'exceptions' => true,
'connection_timeout' => 1
);
try {
$client = new SoapClient($wdsl, $options);
// use https location - the host for http (http://jhb-tvlicweb2.sabc.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc) dosn't exist
$client->__setLocation('https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc');
// setup parameters
$arrParams = array(
'request' => array(
'Header' => array(
'Rquid' => '3600cd32-28b9-4a4f-a522-4326def4a9c2',
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d'
),
'AccountIdentifier' => '9211186012088',
'AccountIdentifierType' => 'SaidNumber'
)
);
// request parameters passed in the body not the header
$account = $client->GetAccount($arrParams);
var_dump($account);
echo "<pre>";
var_dump($client);
echo "</pre>";
} catch (\Exception $e) {
echo "Error!";
echo $e->getMessage() . "<br>";
echo 'Last response: ' . $client->__getLastResponse();
}
How I can do below soap request in php,
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v="http://incometaxindiaefiling.gov.in/ditws/TaxCredMismatch/v_1_0">
<soapenv:Header/>
<soapenv:Body>
<v:getTaxCredMismatchRequest>
<LoginInfo>
<userName>XXXXXXXXXX</userName>
<password>XXXXXXXXXX</password>
</LoginInfo>
<UserInput>
<panNo>XXXXXXXXXX</panNo>
<asseessmentyear>XXXX-XX</asseessmentyear>
</UserInput>
</v:getTaxCredMismatchRequest>
</soapenv:Body>
</soapenv:Envelope>
I tried below code,
<?php
$url = "https://incometaxindiaefiling.gov.in/e-FilingWS/ditws/getTaxCredMismatchRequest.wsdl";
try {
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient($url,$options);
$requestParams = array(
'userName' => 'AJAPA5855E',
'password' => 'pass123',
'panNo' => 'AJAPA5855E',
'asseessmentyear' => '2014-15'
);
$response = $client->__soapCall("getTaxCredMisMatch", array($requestParams));
var_dump($response);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
but getting the response as
SOAP-ERROR: Encoding: object has no 'LoginInfo' property
I know, I'm sending the parameter in correct way, may I know how to correct it.
I never used that soap client, but I would expect this:
<?php
$url = "https://incometaxindiaefiling.gov.in/e-FilingWS/ditws/getTaxCredMismatchRequest.wsdl";
try {
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient($url,$options);
$requestParams = array(
'LoginInfo' => array (
'userName' => 'AJAPA5855E',
'password' => 'pass123',
),
'UserInput' => array (
'panNo' => 'AJAPA5855E',
'asseessmentyear' => '2014-15'
)
);
$response = $client->__soapCall("getTaxCredMisMatch", array($requestParams));
var_dump($response);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
However as said above, this is just a wild guess. It certainly would make sense to take a look at the documentation of that extension: http://php.net/manual/en/class.soapclient.php. Such things should be explained in there...
Using the WSDL from https://incometaxindiaefiling.gov.in/e-FilingWS/ditws/getTaxCredMismatchRequest.wsdl, you could generate the corresponding package from wsdltophp.com in order to be sure on how to structure your request in PHP as every element will be a PHP object with setters/getters. It uses the native PHP SoapClient class so you'll understand easily and quickly who to send these requests if you're familiar with PHP
Using SoapClient in PHP, I've come across a problem I have not been able to find a solution to.
I'm using a local copy of the wsdl file and I am using this setup:
$this->client = new \SoapClient(__DIR__ . '/../../some.wsdl',
array(
'proxy_host' => $ip,
'proxy_port' => $port,
'trace' => 1,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
This gives error : "Forbidden" when calling :
$this->client->__call($method, $params)
I have tried calling __getFunctions()
$this->client->__getFunctions()
that gives the list of all function in my WSDL file.
Am I missing something?
Debug code with like this :
<?php
try{
$client = new SoapClient($wsdl, $params);
$out = $client;
}catch(Exception $e){
$out = array('error' => $e, 'libxml' => libxml_get_last_error());
}catch(SoapFault $s){
$out = array('error' => $s, 'libxml' => libxml_get_last_error());
}
var_dump($out);
exit();
Setting up my first SOAP connection. Code below. I can pull down AvailableContent method but cant seem to access any other objects. Is there anything immediately wrong with my code, or is there something I can ask the service provider.
$soapClient = new SoapClient('http://contentcafe2.btol.com/contentcafe/contentcafe.asmx?wsdl', array("trace" => 1, "exception" => 0));
$auth = array(
'userID' => 'XXXXXXX',
'password' => 'XXXXXXX',
'key' => '9781608198214',
'content' => 'AvailableContent'
);
try{
$response = $soapClient->Single($auth);
echo "<pre>";
print_r($response);
echo "</pre>";
}catch (Exception $e) {
}
I think you should use a SOAP client such as SoapUI - http://www.soapui.org/ - to test your soap handshake instead of writing a code to do same.