So i have the following soap function , i call it in my code a few times , but it gives me the notice of an array to string conversion on line 5.
public function soap($login,$functionName,$api_key,$params,$optional = array(),$n=1){
try{
$client = new SoapClient('http://4dealer.ru/soap/?WSDL');
$hash = md5($login . $functionName . md5($api_key));
$result = $client->$functionName($login,$hash,$params,$optional);
}catch (SoapFault $E){
if($n<3){
sleep(1);
return $this->soap($login,$functionName,$api_key,$params,$optional,$n+1);
}
}
return $result;
}
can you put your call code ? the 5 line is:
$client->$functionName
you should see what are you passing to method that make this error
Related
I am having some trouble regarding PHP NATS. I am getting and printing msg body values. Everything is working fine. Just returning result is the problem. Here is the code
function connect(){
require_once __DIR__ . "/../../vendor/autoload.php";
$connectionOptions = new \Nats\ConnectionOptions();
$connectionOptions->setHost('localhost')->setPort(4222);
$c = new Nats\Connection($connectionOptions);
$c->connect();
$c->request('sayhello', 'Marty McFly', function ($response) {
echo $response->getBody();
return $response->getBody();
});
}
echo is working and printing values, while return isn't returning anything if I use like this.
$res = connect():
print_r($res);
You are echoing from the scope of the anonymous function, and returning from the scope of connect() function.
One approach you can take is callback, you can make your function to take a Closure as an argument and run it from within connect() with the result as an argument:
function connect(\Closure $callback){
require_once __DIR__ . "/../../vendor/autoload.php";
$connectionOptions = new \Nats\ConnectionOptions();
$connectionOptions->setHost('localhost')->setPort(4222);
$c = new Nats\Connection($connectionOptions);
$c->connect();
$c->request('sayhello', 'Marty McFly', function ($response) use ($callback) {
echo $response->getBody();
$callback(response->getBody());
});
}
And you would use it as follows:
connect(function ($result) {
// here you've got an access to the $response->getBody() from connect function
});
Hi am trying to run a function from wsdl. How to run this function?
When i am running get functions i am getting this
array(3) { [0]=> string(797) "ClientSoap createClient(string $client_name, string $client_password, string $first_name, string $last_name)" }
I want to run the createClient function .
I already tried using this code
$client = new SoapClient('mywsdl.wsdl');
$data = $client->createClient("samplecustomer", "samplepass", "first", "last");
print_r($data);
I am getting an error that createClient does not exist. Any ides?
Thanks in advance
I don't know if that can help you but you can add a try catch surround the declaration.
try {
$soapClient = new \SoapClient($url. '?wsdl', $options);
} catch (\SoapFault $e) {
print_r($e->getMessage();
}
I want to interact with SOAP (as a client) and am not able to get the right syntax for input parameters. I have a WSDL URL that I have tested it with SoapUI and it returns result properly. There are two functions defined in the WSDL, but I only need one ("FirstFunction" below). Here is the script I run to get information on the available functions and types:
$client = new SoapClient("http://example.com/webservices?wsdl");
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
And here is the output it generates:
array(
[0] => "FirstFunction Function1(FirstFunction $parameters)",
[1] => "SecondFunction Function2(SecondFunction $parameters)",
);
struct Amount {
anyURI Identifier;
Information charge;
string referenceCode;
}
struct Information {
string description;
decimal amount;
string code;
}
According to above result I developed my client with nusoap and php as below:
class Information
{
public $description;
public $amount;
public $code;
}
class Amount {
public $Identifier;
public $charge;
public $referenceCode;
}
$charge = new Information();
$charge->description = "ROUTE=XXX|abc=".$code;
$charge->amount = "NULL";
$charge->code = $chargecode;
$params = new Amount();
$params->Identifier =$num;
$params->charge = $charge;
$params->referenceCode = $refcode;
$header = new SoapHeader('key', $key);
$client->__setSoapHeaders($header);
try
{
$res = $client->__call('charge',array('parametrs'=>$params));
print_r($res->return);
}
catch(PDOException $e)
{
print_r($e->getMessage());
}
I get the following error as result:
Uncaught SoapFault exception: [soapenv:Server] unknown
In my opinion the best way to achieve it is to use a WSDL to php generator such as the PackageGenerator project. It abstracts the whole process so you only deal with objects without really worrying about SOAP.
I'm Using PHP Soap Client function to connect Remote service using this code
try
{
$result = $soapClient->GetData($parameters);
}
catch (SoapFault $fault)
{
echo "Fault code: {$fault->faultcode}" . NEWLINE;
echo "Fault string: {$fault->faultstring}" . NEWLINE;
if ($soapClient != null)
{
$soapClient = null;
}
exit();
}
$soapClient = null;
Finally I'm calling this function,
echo "Return value: {$result->GetDataResult}" . NEWLINE;
But It's not working for me and got warning message like this.
Notice: Undefined property: stdClass::$GetDataResult
You are ASSUMING that the response comes as an object with the property "GetDataResult". What makes you think so? This is not the case, and that's why you get this error message.
Dump the content of $result to see what you really get. You can also look at the WSDL file to see what the service promises to respond with.
I try to use this function in my code: https://developers.google.com/drive/v2/reference/files/list
Here below:
/**
* Retrieve a list of File resources.
*
* #param apiDriveService $service Drive API service instance.
* #return Array List of File resources.
*/
function retrieveAllFiles($service) {
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
array_merge($result, $files->getItems()); // <---- Exception is throw there !
$pageToken = $files->getNextPageToken();
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
return $result;
}
But i got this error:
Fatal error: Call to a member function getItems() on a non-object in
C:\Program Files
(x86)\EasyPHP-5.3.6.1\www\workspace\CPS\class\controller\CtrlGoogleDrive.php
on line 115
Thee array seems to be empty may be but it shouldn't be:
Array
(
[kind] => drive#fileList
[etag] => "WtRjAPZWbDA7_fkFjc5ojsEvE7I/lmSsH-kN3I4LpwShGKUKAM7cxbI"
[selfLink] => https://www.googleapis.com/drive/v2/files
[items] => Array
(
)
)
The PHP client library can operate in two ways and either return objects or associative arrays, with the latter being the default.
The examples in the documentation assume you want the library to return objects, otherwise you would have to replace the following two calls:
$files->getItems()
$files->getNextPageToken()
with the corresponding calls that use associative arrays instead:
$files['items']
$files['nextPageToken']
Even better, you can configure the library to always return objects by setting
$apiConfig['use_objects'] = true;
Please check the config.php file for more configuration options:
http://code.google.com/p/google-api-php-client/source/browse/trunk/src/config.php