How to debug SOAP connections - php

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.

Related

PHP SOAP Client giving error at the time of calling a method "SoapFault exception: [s:Receiver] Object reference not set to an instance of an object"

I am completely new to PHP SOAP . After doing some R&D for my problem I got some links of stackoverflow but didn't get the perfect solution.
Here is my problem :
I am creating a SOAP client that will execute a method called GetPassword and It will return an encrypted password with response code '100' if the credentials is correct. In case of wrong credential a response code '101' and the response status will receive.
Here is my code (I am hiding the credentials for security purpose):
$url= "http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc?wsdl";
$method = "GetPassword";
$error=0;
$client = new SoapClient($url, array('soap_version' => SOAP_1_2 , 'SoapAction'=>'http://tempuri.org/IStarMFFileUploadService/GetPassword'));
$actionHeader= array();
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'Action',
'http://tempuri.org/IStarMFFileUploadService/GetPassword');
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'To',
'http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc/Basic');
$client->__setSoapHeaders($actionHeader);
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
try{
$info = $client->__call($method, array($param));
}
catch (SoapFault $fault) {
$error = 1;
}
if($error==1) {
$xml=$fault;
}else{
$xml = $info;
}
echo($xml);
Some couples of days ago I got this error and the error was happening due to the mismatch of parameters. But this time I think the parameters are correct. So may be I am doing some small mistakes.. Please help me to find the mistakes.
If any input needed, please let me know in the comment, I will update.
Please Note : I tested the wsdl URL with the SoapUI software and it is returning perfectly.
The Problem was with Parameter . Just analyze the structure of the Method GetPassword and found that it take only one parameter named 'Param' which is an object and inside the Param object it is taking the values of MemberId', 'Password' , 'UserId'.
So just need to change one line of code.
use
$param =array ('Param' => array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX') );
Instead of
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
and the issue resolved.

SOAP java.lang.NullPointerException Error

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.

Php Soap connection refusal

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();
}

PHP XML Soap request

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

PHP SoapClient unable to access webservice using proxy

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();

Categories