I'm working on a Webservice using PHP SoapClient.
The webservice url is: http://web.abaseguros.com/AutoConnect/ACCatalogos.svc?wsdl
And here is my code:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
$pin = new SoapClient("http://web.abaseguros.com/AutoConnect/ACCatalogos.svc?wsdl");
class Token {
var $usuario;
var $password;
function Token($user,$pass) {
$this->usuario = $user;
$this->password = $pass;
}
}
//User and Password for the token object
$Token = new Token('usuarioWCF','Pa$$w0rd');
//XML 'Entrada' String
$Entrada = "<CAT><NEG>5786</NEG></CAT>";
$result = $pin->ObtenerMarcas($Token,$Entrada);
But PHP prints out the following error message:
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed] when i execute the script.
The company gave me a sample code written on C#
private void Obtener_Catalogo_ABASeguros()
{
string strEntrada, strSalida;
strEntrada = “<CAT><NEG>5786</NEG></CAT>“; +
ACCatalogosClient proxy = new ACCatalogosClient();
Token token = new Token();
token.usuario = "usuarioWCF";
token.password = "Pa$$w0rd";
try
{
strSalida = proxy.ObtenerMarcas(token, strEntrada);
}
catch (FaultException<Error> ex)
{
txtCotSalida.Text = string.Format("Ocurrio un error en el WCF:\n " +
"Origen: {0}\n "+
"Mensaje: {1}\n "+
"Stack: {2}", ex.Detail.Origen, ex.Detail.Mensaje, ex.Detail.StackTrace);
}
But I'm still unabled to understand how parameters are sent on both languages.
Any Help?
Your Soap client does not know how to deserialize the object Token. You need to convert that token object into a associate array and use that array as parameter to the operation instead.
$pin->ObtenerMarcas(get_object_vars($Token),$Entrada);
I am afraid even you get this error cleared, you will not be successful in working with the service yet. It looks like the a token is required in the soap header instead. the C code you put does not show you everything, it has the implementation encapsulated inside the Proxy class. You need to have a read the documentation is there's any, otherwise you will have to read the imported wsdl files embedded in your provided global wsdl link.
Related
public function request_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$this->load->library('dropbox', $params);
$data = $this->dropbox->get_request_token(base_url());
$this->session->set_userdata('token_secret', $data['token_secret']);
redirect($data['redirect']);
}
//This method should not be called directly, it will be called after
//the user approves your application and dropbox redirects to it
public function access_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$this->load->library('dropbox', $params);
$oauth = $this->dropbox->get_access_token($this->session->userdata('token_secret'));
$this->session->set_userdata('oauth_token', $oauth['oauth_token']);
$this->session->set_userdata('oauth_token_secret', $oauth['oauth_token_secret']);
redirect('welcome/test_dropbox');
}
//Once your application is approved you can proceed to load the library
//with the access token data stored in the session. If you see your account
//information printed out then you have successfully authenticated with
//dropbox and can use the library to interact with your account.
public function test_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$params['access'] = array('oauth_token'=>urlencode($this->session->userdata('oauth_token')),
'oauth_token_secret'=>urlencode($this->session->userdata('oauth_token_secret')));
$this->load->library('dropbox', $params);
$dbobj = $this->dropbox->account();
print_r($dbobj);
}
Blockquote
i have used Dropbox library https://github.com/jimdoescode/CodeIgniter-Dropbox-API-Library
When i call to function request_dropbox() it gives me error in api "Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\reports\application\libraries\Dropbox.php on line 478"
please help me how to access dropbox files.
Please look at your errors more carefully, it turns out that curl is not enabled on your Xampp environment.
This should help you out to enable CURL and get you going again.
How to enable curl in xampp?
I am trying to connect to webservice using SOAP / wsdl, but I constantly get the error. I am new in soap-api in php. I have a document of api detail, it shows:
public WSGetCalendarFareResponse GetCalendarFare(WSGetCalendarFareRequest calanderFareRequest)
I made my code accordingly but still found error/exception. Please review my php code in following:
$wsdl = "http://api.abc.com/xyz/service.asmx?wsdl"; // This is a test Web Service URL
$h = array();
$opta["GetCalendarFare"]["request"]= array(
"Origin"=>"DEL",
"Destination"=>"IXR",
"DepartureDate"=>"2015-05-01T00:00:00",
"ReturnDate"=>"2015-05-01T00:00:00",
"Type"=>"OneWay",
"CabinClass"=>"All",
"PreferredCarrier"=>"",
"AdultCount"=>1,
"ChildCount"=>1,
"InfantCount"=>"0",
"SeniorCount"=>"0",
"PromotionalPlanType"=>"Normal",
"IsDirectFlight"=>false
);
$client_header = new SoapHeader('http://192.168.0.0/TEST/BookingAPI','AuthenticationData',$hparams,false);
$cliente = new SoapClient($wsdl, array('trace' => 0));
$cliente->__setSoapHeaders(array($client_header));
try{
$h= (array)$cliente->__call('GetCalendarFare',$opta);
}catch(Exception $e)
{
echo '<pre>';
var_dump($e);
}
When I execute my code, it returns following error:
"System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at BookingAPI.WSCalendarFareInput(WSGetCalendarFareRequest calanderFareRequest) in c:\inetpub\wwwroot\api.tektravel.com\TboApi_V7\App_Code\Service.cs:line 4544
at BookingAPI.GetCalendarFare(WSGetCalendarFareRequest calanderFareRequest) in c:\inetpub\wwwroot\api.tektravel.com\TboApi_V7\App_Code\Service.cs:line 4360
Can anyone please suggest that where problem exists? It hit & try many times but couldn't get the error point.
Can you debug the execution of your POST on the server side? It is heavy guessing from my side, but I assume that you do not set a mandatory value in the request, which the server needs to deserialize your object. Hence the NullReferenceException.
Problem has resolved.
The Request array should be like this:
$opta["GetCalendarFare"]["calanderFareRequest"]= array(
"Origin"=>"DEL",
"Destination"=>"IXR",
"DepartureDate"=>"2015-05-01T00:00:00",
"ReturnDate"=>"2015-05-01T00:00:00",
"Type"=>"OneWay",
"CabinClass"=>"Economy",
"PreferredCarrier"=>"",
"AdultCount"=>1,
"ChildCount"=>1,
"InfantCount"=>"0",
"SeniorCount"=>"0",
"PromotionalPlanType"=>"Normal",
"IsDirectFlight"=>false
);
I am trying to setup an Oauth server using the pecl-php oauth library http://php.net/manual/en/book.oauth.php
This code assumes that the client has already received a user verified access token, for simplicity sake I've not included any database calls and have hardcoded matching values into my client and provider.
Class OauthVerify
{
private static $consumer_secret = 'f63ed7f7a8899e59d3848085c9668a0d';
private static $token_secret = '72814e6059441037152eecef2e8559a748b84259';
private $provider;
public function __construct()
{
$this->provider = new OAuthProvider();
$this->provider->consumerHandler(array($this,'consumerHandler'));
$this->provider->timestampNonceHandler(array($this,'timestampNonceHandler'));
$this->provider->tokenHandler(array($this,'checkAccessToken'));
}
//Check the client request
public function checkRequest()
{
try {
$this->provider->checkOAuthRequest();
} catch (Exception $Exception) {
return OAuthProvider::reportProblem($Exception);
}
return true;
}
public static function timestampNonceHandler($Provider)
{
//I'm leaving out this logic now, to keep it simple and for testing purposes
return OAUTH_OK;
}
public static function consumerHandler($Provider)
{
//I'm leaving out this logic now, to keep it simple and for testing purposes
$Provider->consumer_secret = self::$consumer_secret;
return OAUTH_OK;
}
public static function checkAccessToken($Provider)
{
$Provider->token_secret = self::$token_secret;
return OAUTH_OK;
}
}
The above code should give me the barebones I need to authenticate an Oauth request.
Before any particular route is executed I call the $OauthVerify->checkRequest() method which checks if the client request is valid, however the server keeps throwing a 'signatures do not match' error. I don't think that the problem is with the clients as I've tried both postman (for chrome) and a PHP implementation and they both generate the same signature. I have however for interest sake included my client call.
$consumer_key = '87d6d61e87f0e30d8747810ae40041d1';
$consumer_secret = 'f63ed7f7a8899e59d3848085c9668a0d';
$token= 'b9d55b3ec4b755d3fe25d7a781da1dfd044b5155';
$token_secret = '72814e6059441037152eecef2e8559a748b84259';
$timestamp = '1417515075';
$nonce = '9QV4rn';
$version = '1.0';
$method = 'GET';
$url = 'https://localhost/micro/v1/nappi';
try {
$oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->disableSSLChecks();
$oauth->setNonce($nonce);
$oauth->setTimestamp($timestamp);
$oauth->setToken($token, $token_secret);
$oauth->setVersion($version);
$oauth->fetch("$url");
$json = json_decode($oauth->getLastResponse());
print_r($json);
}
catch(OAuthException $E) {
print_r($E);
}
I've burned a good couple of hours trying to figure this out, someone please help!
I finally managed to solve it, my .htaccess file had a rewrite rule that was processing a _url parameter for my framework. This parameter was ofcourse being included in the signature that the server generated. I simply instructed OAuth Provider to ignore the the _url parameter in my constructor:
$this->provider->setParam('_url',NULL);,
that was all it took, everything runs perfectly now.
I'm using PHP 5.3, and trying to develop a simple web service that gets some parameters with POST method and has a response.
function start(){
getAndValidateParams();
global $response;
echo json_encode($response);
}
function getAndValidateParams(){
// token (mandatory)
if(isset($_POST[PARAM_TOKEN])){
echo 'got your token';
}else{
$response[ERROR_CODE] = ERR2_INVALID_TOKEN;
$response[DESCRIPTION] = CODE2_DESC;
}
}
I'm trying to test that with Postman:
The problems:
1. About the Xdebug HTML I saw the following question, If I turn the var_dump off, will it disable usage of var_dump() inside my php code? (I want to be able use it for debugging but not seeing that in the response).
2.Also I have a problem to pass the parameter 'token', I don't see it in getAndValidateParams().
Any help will be appreciated.
I have used your function to just get insight in this and for tesing you can use also there is Advanced REST client in chrome similar to postMAN that you are using --
use the below lines to debug this --
function start(){
$response = getAndValidateParams();
return json_encode($response);
}
// calling function ends here
// statrt another function that is being called
function getAndValidateParams(){
// token (mandatory)
// print_r($_POST);die; // just for debug purpose
if(isset($_POST[PARAM_TOKEN])){
$response[ERROR_CODE] = 0;
$response[DESCRIPTION] = "Success";
$response[DEtail] = $yourdetailarr; // array of data that you want to retuen
}else{
$response[ERROR_CODE] = ERR2_INVALID_TOKEN;
$response[DESCRIPTION] = CODE2_DESC;
}
return $response;
}
/// ends here
check the response here by calling start function .
When trying to instantiate my nuSoap method authenticateUser, it says:
Fatal error: Uncaught SoapFault exception: [Client] Function ("authenticateUser") is not a valid method for this service in /Applications/MAMP/htdocs/projo/dev/home.php:14
But when I replace that method name for one that already works, everything works just fine. So I think the instantiation syntax isn't wrong.
/*-----------
Authenticate User
------------*/
$server->register(
// method name
'authenticateUser',
// input parameters
array('sessionUserName' => 'xsd:string', 'sessionHash' => 'xsd:string', 'user' => 'xsd:string', 'pass' => 'xsd:string'),
// output parameters
array('return' => 'xsd:string'),
// namespace
$namespace,
// soapaction
$namespace . '#authenticateUser',
// style
'rpc',
// use
'encoded',
// documentation
'authenticates a user and returns a json array of the user info'
);
function authenticateUser($sessionUserName, $sessionHash, $user, $pass)
{
//Check to see if a countryCode was provided
if ($sessionUserName != '' && $sessionHash != '' && $user == $GLOBALS['wsUser'] && $pass == $GLOBALS['wsPass'])
{
$suid = 'AUTH'.$GLOBALS['guid'].'SESSION';
$database = new SQLDatabase();
$database->openConnection();
$database->selectDb();
//Query
$sql = "SELECT * FROM members WHERE member_email='" . $sessionUserName . "' LIMIT 1";
//Query MySQL
$return = $database->query($sql);
$userDetails = $database->fetch_array( $return );
if(!empty($userDetails)) {
$userDetails[0]['authSession'] = $suid;
$newArr = $userDetails[0];
$response = json_encode($newArr);
}
/*print $sql.'<br /><pre>';
print_r($response);
echo '</pre>';*/
//Throw SQL Errors
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
//Return on Success
return $response;
//Close Connection
mysql_close($con);
}
else
{
return 'Error: You must supply all of the inputs!x';
}
}
There are two things I can think of that would cause this error:
More likely: my registration of the function is somehow incorrect, even though the wsdl gui shows that the function is registered correctly and I've been able to successfully consume the method via the SoapUI program.
Less likely: somehow, the function isn't broken anymore, but its cached and so I'm seeing an old error.
The Question: When trying to consume this soap service method via PHP, why do I get an output error stating that this function doesn't exist in the service, when it clearly is?
Set
ini_set("soap.wsdl_cache_enabled", "0");
In every file you use soap from, or set wsdl_cache_enabled
to 0 in your php.ini file.
[soap]
; Enables or disables WSDL caching feature.
soap.wsdl_cache_enabled=0
If you are on Linux, you can also directly delete the cached wsdl file from /tmp/ dir
It was the CACHE!!! stupid. All I had to do was close my computer and go to bed. When I woke up, I ran the file again and it worked like a charm.
This is the second time this has happened with a function in a SOAP service.
Now I need to know how to clear the cache of a soap service. (nuSoap)