I am trying to call a function on a web service defined on a Tomcat server, but I can not make the call due to a credentials failure.
The structure of this web service asks for a Basic Authorization embedded on the envelope (not the header itself). Using the SOAPui tool I have no problem to make this call entering the username and password. But using the PHP client is not possible to access the web service.
I have already tried to use nusoal library which actually works, but it doesn't help with the parameters because I can not filter the query. I mean is like this call doesn't use the parameters at all returning all the results.
I would like to give it a try with the default soapClient.
<?php
$username = "user";
$password = "pass";
$wsdl = 'http://192.168.1.185:8080/msw/gestionSolicitudes?wsdl';
$options = array(
'Username' => $username,
'Password' => $password,
);
$client = new SoapClient($wsdl, $options);
$parametros = array("statusId"=>2, "startDate"=>'2019-01-01', "endDate"=>'2019-09-01', "name"=>'Maria');
$result = $client->__soapCall('getSolicitudesLista', $parametros);
foreach ($result as &$valor) {
foreach ($valor as &$solicitud) {
if (is_object($solicitud)) {
echo nl2br (">>>Solicitud init ============================================\r\n");
....
} else {
echo nl2br (">>>Result ============================================\r\n\r\n");
var_dump($solicitud);
echo nl2br (">>>Result ============================================\r\n\r\n");
}
}
}
?>
Related
I am using a platforme call ideamart to create some sms based applications.
They provide a api called subscription api.
deatils about ideamart subscription API
Guid to work with subscription API
I use below first code to request BaseSize details.is that code is correct.?
can I Display response using PHP echo() Function .? or any other way.?
<?php
include_once "definitions.php";
include_once "subscription.php";
$sub = new Subscription();
$AppId = "APP_00001";
$Password = "yuhst345";
$baseSize = $sub->getBaseSize($AppId,$Password);
?>
here is the getBaseSize function that includes in subscription.php
public function getBaseSize($applicationId, $password){
$arrayField = array(
"applicationId" => $applicationId,
"password" => $password);
$jsonObjectFields = json_encode($arrayField);
$resp=$this->sendBaseRequest($jsonObjectFields);
$response = json_decode($resp, true);
$statusDetail = $response['statusDetail'];
$statusCode = $response['statusCode'];
$status =$response['baseSize'];
return $status;
}
So, it looks like your getBaseSize() is returning an simply the base size. So, you should be able to do a
print $baseSize;
OR
echo $baseSize;
And you'll print out the string.
I would like to create an invoice from the picking but trough and XML-RPC call from a PHP file.
I have tried to call the action_id: 359 like this:
$transfer = $rpc->button_click($uid, $pwd, 'stock.invoice.onshipping', 'invoice_open', array(111));
But it doesn't work... Do some one have any clue on how can I do this?
Below i am posing the code it may help in your case:
In Php you can try ripcord library :
For Basic connection setup/authorization just type this code.
$url = "http://localhost:8072";
$db ="my_db";
$username = "prakashsharmacs24#gmail.com";
$password = "7859884833";
$common = ripcord::client("$url/xmlrpc/common");
$uid = $common->authenticate($db, $username, $password, array());
echo $uid;//1
Now create a model instance and call the work flow by exec_workflow:
$models = ripcord::client("$url/xmlrpc/object");
$models->exec_workflow($db, $uid, $password,'account.invoice' ,'invoice_open',14);
Hope this may help in calling the workflow from php.
I am trying to connect to this WSDL server using PHP:
https://services.PWSDemo.com/CreditCardTransactionService.svc?wsdl
I have tried:
$client = new SoapClient('https://services.PWSDemo.com/CreditCardTransactionService.svc?wsdl');
$result = $client->AuthorizeAndCapture( array( 'credentials' => $credentials, 'authorizeAndCaptureParams' => $acparam));
Where $credentials is an array like this:
$credentials = array();
$credentials['ClientCode'] = "XYZOffice";
$credentials['UserName'] = "Linxtrans";
$credentials['Password'] = "C0de5ample!";
And
$acParem is a similar but much more complicated array I am not posting in full for brevity (see below for more)
I also tried with classes such as:
class ClientCredentials {
public $ClientCode;
public $Password;
public $UserName;
}
Without success, I always get the error: The authorizeAndCaptureParams parameter is required.
In the class example, the acparam is defined this way:
class AuthorizeAndCaptureParams {
public $AddOrUpdateCard;
public $CreditCardTransaction;
public $TerminalIdentifier;
public function __construct(){
$this->TerminalIdentifier = new TerminalIdentifier();
$this->CreditCardTransaction= new CreditCardTransaction();
}
}
In the PHP array attempt, I start this way:
$acParams['CreditCardTransaction'] = array();
$acParams['CreditCardTransaction']['CreditCard'] = array();
$acParams['CreditCardTransaction']['CreditCard']['Cardholder'] = array();
$acParams['CreditCardTransaction']['CreditCard']['Cardholder']['FirstName'] = "John";
$acParams['CreditCardTransaction']['CreditCard']['Cardholder']['LastName'] = "Smith";
$acParams['CreditCardTransaction']['CreditCard']['BillingAddress'] = array();
The company only supplies examples in C# and when asked for PHP support, they reply that PHP is not supported, but "many of their customers implemented their API with PHP".
And so, I am at a loss as to how to proceed....
I have implemented WSDL clients in the past, but with simple data structures, but never with such elaborate data structures!
I have this class to send a SOAP-request (the class also defines the header)
class Personinfo
{
function __construct() {
$this->soap = new SoapClient('mysource.wsdl',array('trace' => 1));
}
private function build_auth_header() {
$auth->BrukerID = 'userid';
$auth->Passord = 'pass';
$auth->SluttBruker = 'name';
$auth->Versjon = 'v1-1-0';
$authvalues = new SoapVar($auth, SOAP_ENC_OBJECT);
$header = new SoapHeader('http://www.example.com', "BrukerAutorisasjon", // Rename this to the tag you need
$authvalues, false);
$this->soap->__setSoapHeaders(array($header));
}
public function hentPersoninfo($params){
$this->build_auth_header();
$res = $this->soap->hentPersoninfo($params);
return $res;
}
}
The problem is that there's something wrong with my function and the response is an error. I'd like to find out what content I am sending with my request, but I can't figure out how.
I've tried a try/catch-block in the hentPersoninfo-function that calls $this->soap->__getLastRequest but it is always empty.
What am I doing wrong?
Before I ever start accessing a service programmatically, I use SoapUI to ensure that I know what needs sent to the service, and what I should expect back.
This way, you can ensure the issue isn't in the web service and/or in your understanding of how you should access the web service.
After you understand this, you can narrow your focus onto making the relevant SOAP framework do what you need it to do.
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)