NuSoap doesn't work - php

i'm trying to connect my page to a webservice soap. My hosting doesn't support soap so SoapClient isn't recognized. I have a working example to connect to that ws but uses SoapClient. This is:
$params = array('location'=>"www.wssite.com/test.php",
'trace'=>1,
'exceptions'=>1);
$client = new SoapClient("url_of_wsdl",$params);
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
$pars = array('ipcInvocationName' => 'wsinvokeservice',
'ipcMethodNamespace' => 'svcmsgxml.bldximsgin',
'ttIn' => array(
'ttInRow' => array( array('ParPos' => '0','ParNam' => 'MethodName',
'ParVal' => POST),
array('ParPos' => '1','ParNam' => 'XMLDocumentIn',
'ParVal' => 'LoginXmlValue'))),
'ttOut' => array('ttOutRow' => array(array('ParPos' => '0',
'ParNam' => 'ContentType','ParVal' => ''),array('ParPos' => '1',
'ParNam' => 'Result','ParVal' => ''),
array('ParPos' => '2','ParNam' => 'XMLDocumentOut','ParVal' => '')));
$return = $client->wssigateway($pars);
It works good!
I used NuSoap in this way:
require_once 'soap/nusoap.php';
$wsdl = 'url_of_wsdl';
$client = new soapclient($wsdl,true);
$err = $client -> getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
exit();
}
$pars = array()//the same as above
$result = $client -> call('wssigateway',$pars);
The script works for too much time and does get me nothing.. why? can someone help me?

Try $client = new nusoap_client($wsdl,true);
instead of $client = new soapclient($wsdl,true);

Related

SOAP Client error list array read

When I try to read from a function returning a list array or map array I have an error, can anyone help me? This is my code:
<?php
$serverAddress = "YOUR_SERVER_IP";
$serviceUrl = "http://127.0.0.1/soap-live/";
$wsdlUrl = $serviceUrl . 'wsdl/';
$clientParams = array(
'login' => 'admin',
'password' => 'paris',
'location' => $serviceUrl,
'trace' => true,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
);
$client = new SoapClient($wsdlUrl, $clientParams);
echo "===== Get_api_version( ) =====<br/>\n";
$response = $client->Get_input_info(1);
echo $response->return . "<br/>\n";
?>
Best Regards.

SOAP-ERROR: Encoding: object has no 'FinalBookingDate' property

Before starting, I know, this errors means that I should have defined the property FinalBookingDate, but just keep reading and you will understand my point of view.
The url is: http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?op=getBookingList
I was testing first with SoapUi, and I successfull get the list that I need:
And on php, I only can get this response:
The SoapClient from php is:
$params = array('soap_version' => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new \SoapClient('http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?wsdl', $params);
And then, the code to retrieve the data:
/*
$query = array(
'InitialServiceDate' => '2015-01-20',
'InitialBookingDate' => '2015-01-20',
'FinalBookingDate' => '2015-01-20',
'FinalServiceDate' => '2015-01-20',
'CreationUserId' => 1338,
'CityId' => 4166,
'ServiceTypes' => array('eServiceType' => 'HOTEL')
);
*/
$query = array(
'InitialBookingDate' => '2015-01-20',
'ServiceTypes' => array('eServiceType' => 'HOTEL')
);
$args = new \stdClass;
$args->credential = new \stdClass;
$args->credential->UserName = $conn['userPass']['usr'];
$args->credential->Password = $conn['userPass']['pass'];
$args->searchBookingCriteria = new \stdClass;
$args->searchBookingCriteria->InitialBookingDate = '2015-01-20';
$args->searchBookingCriteria->ServiceTypes = new \stdClass;
$args->searchBookingCriteria->ServiceTypes->eServiceType = 'HOTEL';
//$args = array('credential'=>$credentials, 'searchBookingCriteria' => $query);
$data = $conn['client']->getBookingList($args);
print_r($data);
exit;
As you can see, I tried 2 ways to send the $args to getBookingList, as far I know both of then is valid and yet both of then (with array or object) return the same error. On the code commented at first you can see that I tried to define all does properties that the web service asks but after defining all of then I get a empty result.
My question is, there is some extra param to define on SoapClient that I should do? Why the SoapUI can do it with success? What I have missing here?
Bonus: A print of SoapUI full screen with the default request including the optional params https://www.evernote.com/shard/s14/sh/fb5ac276-8147-4e09-95bb-afa0be66d7a6/d273441c74186bf1e600b42ab3303899/deep/0/SoapUI-5.0.0.png
Can you try this more direct approach:
try {
$params = array('soap_version' => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new SoapClient('http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?wsdl',$params);
} catch (SoapFault $E) {
echo $E->faultstring;
}
if ($client) {
$req_params = array('credential' =>
array('userName' => 'XXXXXXX',
'Password' => 'XXXXXXX'),
'searchBookingCriteria' =>
array('BookingNumber' => array('int' => 'XXXXXXXXX'),
'ServiceTypes' => array('eServiceType' => 'HOTEL'),
'PassengerName'=> 'XXXXXXXX',
'InitialBookingDate'=> '2015-01-16',
'FinalBookingDate'=> '2015-01-16',
'InitialServiceDate' => '2015-01-18',
'FinalServiceDate' => '2015-01-18',
'BookingStatus'=> array('eStatus' => 'ACTIVATED'),
'PaymentStatus'=> array('ePaymentStatus' => 'Payed'),
'CreationUserId'=> 'XXX',
'CityId'=> 'XXXX',
'ExternalReference'=> '')
);
$response = $client->__soapCall('getBookingList',array($req_params));
var_dump($response);
}
Try (and add) this approach:
$args->searchBookingCriteria->FinalBookingDate = '2015-01-22';
$args->searchBookingCriteria->InitialServiceDate = '2015-01-22';
$args->searchBookingCriteria->FinalServiceDate = '2015-01-22';
$args->searchBookingCriteria->CreationUserId = 'abc';
$args->searchBookingCriteria->CityId = 'abc';

error in calling soap function in php

how can i get soap data in php from this site
http://www2.rlcarriers.com/freight/shipping-resources/rate-quote-instructions
they have "GetRateQuote(string APIKey, RequestObjects.RateQuoteRequest request)"
this function how can i call this from php soap
$client = new SoapClient('http://api.rlcarriers.com/1.0.1/RateQuoteService.asmx?WSDL');
//print_r($client);
//$result = $client->GetRateQuote('xxxxxxxxxxxxxxxxxxxxxx.......',);
print_r($result);
?>
what should i have to pass in second parameter
Try the following:
$client = new SoapClient("http://api.rlcarriers.com/1.0.1/ShipmentTracingService.asmx?WSDL", array("trace" => 1));
$request = array(
"APIKey" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"request" => array(
"TraceNumbers" => array(
0 => "xxxxxxxxx"
),
"TraceType" => "PRO",
"FormatResults" => "true",
"IncludeBlind" => "true",
"OutputFormat" => "Standard"
)
);
try {
$response = $client->TraceShipment($request);
print_r($response);
}
catch (SoapFault $exception) {
print_r($exception);
}

Getting my SOAP application to work

I am making a start on SOAP but can't get past the first hurdle of authenticating myself...
Here is my code...
$login = array(
'loginWebRequest' => array(
'Username' => 'myuser',
'Password' => 'mypass'
)
);
$url = 'https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl';
$client = new SoapClient($url);
$result = $client->Login('Login',$login);
print_r($result);
I hope someone can see a mistake I have obviously made!
print_r($client->__getFunctions());
tells me this...
Array
(
[0] => LoginResponse Login(Login $parameters)
[1] => LogoutResponse Logout(Logout $parameters)
)
Thanks in advance
Paul
Try this:
$options = array(
"trace" => 1,
"exception" => 1
);
$login = array(
'loginWebRequest' => array(
'Username' => 'myuser',
'Password' => 'mypass'
)
);
$url = 'https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl';
$client = new SoapClient($url,$options);
$result = $client->call('Login',$login);
echo "<pre>";
print_r($client->__getLastRequest());
echo "<hr />";
print_r($result);
I recomend the use of soapui before any code, is importante to test de wsdl functions and permissions. In SOAPUI you can do a call for login function and it is more fast and easy to check for example login and password information.

OAuth Google Analytics Authentication with PHP

I am trying to get OAuth to work with Google Analytics, but I'm not having any luck. My code looks like this:
require_once('common.inc.php');
$consumerKey = "my.url.net";
$consumerSecret = "nzZ....TX";
$sig_method = "HMAC-SHA1";
$oauth_token = $token ? new OAuthToken($token, $token_secret) : NULL;
$token_endpoint = '/accounts/OAuthGetRequestToken';
$scope = 'https://www.google.com/analytics/feeds/';
$callback_url = "http://my.url.net/pete/oauth/";
$privKey = NULL;
$params = array('scope' => $scope, 'oauth_callback' => $callback_url);
$url = $token_endpoint . '?scope=' . urlencode($scope);
$consumer = new OAuthConsumer($consumerKey, $consumerSecret);
$req = OAuthRequest::from_consumer_and_token($consumer, $oauth_token, 'GET',
$url, $params);
//$req->sign_request($sig_method, $consumer, $oauth_token, NULL);
echo "<PRE>";
print_r($req);
// Fill response
echo json_encode(array(
'html_link' => '',
'base_string' => $req->get_signature_base_string(),
'response' => send_signed_request('GET', $url, array($req->to_header())),
'authorization_header' => $req->to_header()
));
So when this code runs it prints this:
OAuthRequest Object
(
[parameters:OAuthRequest:private] => Array
(
[oauth_version] => 1.0
[oauth_nonce] => 5f....11
[oauth_timestamp] => 1306433873
[oauth_consumer_key] => my.url.net
[scope] => https://www.google.com/analytics/feeds/
[oauth_callback] => http://my.url.net/pete/oauth/
)
[http_method:OAuthRequest:private] => GET
[http_url:OAuthRequest:private] => /accounts/OAuthGetRequestToken?scope=https%3A%2F%2Fwww.google.com%2Fanalytics%2Ffeeds%2F
[base_string] =>
)
When I uncomment this line:
//$req->sign_request($sig_method, $consumer, $oauth_token, NULL);
The script just fails to load showing Server Error. What am I doing wrong? Any advice would help, thanks!
Thanks for your comment Mark, this was actually because my "$sig_method" variable was actually just a string containing "HMAC..." when it actually needed to be an object called this:
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
Hope this helps someone in the future!

Categories