ZF2 SOAP "Procedure not present" Error - php

I'm having serious trouble to solve this issue. I got an APP with 3 modules that got different services to provide by SOAP. What happens is that 2 of them are getting this response:
SoapFault
File:
/var/www/empreendimentos/vendor/zendframework/zendframework/library/Zend/Soap/Client.php:10
Message:
Procedure not present
I already double checked, and the names of the functions are right and I use the method getFunctions. This is the return from getFunctions():
array
0 => string 'Array getCliAll(anyType $filter)' (length=32)
1 => string 'Array insertCli(anyType $data)' (length=30)
2 => string 'Array editCli(anyType $data, anyType $id)' (length=41)
3 => string 'void setServiceLocator(anyType $serviceLocator)' (length=47)
4 => string 'void getServiceLocator()' (length=24)
My handle methods look like this:
public function handleWSDL() {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('\Cli\Service\CliService');
$autodiscover->setUri($this->_URI);
$wsdl = $autodiscover->generate();
$wsdl = $wsdl->toDomDocument();
// geramos o XML dando um echo no $wsdl->saveXML()
echo $wsdl->saveXML();
}
public function handleSOAP() {
$soap = new \Zend\Soap\Server($this->_WSDL_URI);
$soap->setWSDLCache(false);
$classHandle = new CliService();
$classHandle->setServiceLocator($this->getServiceLocator());
$soap->setClass($classHandle);
$soap->handle();
}
I get no errors on the server side. Only this response for all the methods. What is wrong?
UPDATE:
Turns out it's a "Problem" of the ZF2 config. overload. I had my modile.config.php to hold my WSDL and URI information, but used the same label for the config on the file. The overload was making every WSDL and URI the same, and giving me the problem.
Like this:
Emp Module modile.config.php
'service_url' => array(
"wsdl" => 'http://localhost/empreendimentos/public/emp/service?wsdl',
"return" => 'http://localhost/empreendimentos/public/emp/service',
),
Emp Module modile.config.php
'service_url' => array(
"wsdl" => 'http://localhost/empreendimentos/public/cli/service?wsdl',
"return" => 'http://localhost/empreendimentos/public/cli/service',
),
Anyone know why this is like this? is it suposed to mix module configs?

Had this problem yesterday, found the answer was in the server wsdl call.
The server calls its own wsdl to introspect the available methods. If your wsdl url is wrong, it sees what methods are available in another server and says 'Procedure not present'.
In my case the AdmintoolsController had the line
$wsdl_url = 'http://' . $_SERVER['HTTP_HOST'] . '/news/?wsdl';
so it was looking in the News service for the method.
Change it to
$wsdl_url = 'http://' . $_SERVER['HTTP_HOST'] . '/admintools/?wsdl';
and it works fine.
I searched Google for hours looking for this fix, and my colleague looked at the code and spotted it straight away.
Hope this helps
John

Also try to do the below changes and then check if it works:
Remove the files starting with "wsdl-" in the tmp folder of your zend server.
Make a php setting: phpSettings.soap.wsdl_cache_enabled = 0 in your application.ini file.

Related

Unable to use Memcached in PHP Fat free framework

I have been trying to implement memcached in my application built in fat free framework. I have read that it should be explicitly defined as "memcached=192.168.--.---:11211" but no matter how I implement it, it uses "folder=tmp/cache/"
Tried and failed approaches
config.ini
CACHE="memcached=192.168.--.---:11211"
index.php
$f3->config('config/config.ini');
$f3->run();
code
$cache = \Cache::instance();
var_dump($cache);
Output
Object(Cache)#7 (3) {
["dsn":protected] => string(17)"folder=tmp/cache/"
["prefix":protected] => string(12)"randomString"
["ref":protected] => NULL
}
code
$cache = \Cache::instance();
$cache->load("memcached=192.168.--.---:11211");
var_dump($cache);
Output
Object(Cache)#7 (3) {
["dsn":protected] => string(17)"folder=tmp/cache/"
["prefix":protected] => string(12)"randomString"
["ref":protected] => NULL
}
code
$cache = new Cache("memcached=192.168.--.---:11211");
var_dump($cache);
Output
Object(Cache)#7 (3) {
["dsn":protected] => string(17)"folder=tmp/cache/"
["prefix":protected] => string(12)"randomString"
["ref":protected] => NULL
}
index.php
$f3->config('config/config.ini');
$f3->set('CACHE',"memcached=192.168.--.---:11211");
var_dump($f3->get('CACHE'));
Output
string(17)"folder=tmp/cache/"
What am I missing?
Do you have installed the proper php extension? Or is the connection secured? Because when there’s an error, the cache engine will just fall back to folder mode.

Active Collab API: How to get projects

I'm trying out the ActiveCollab API for my first time. I had to use StackOveflow to figure out how to get the API token since the docs don't tell me this.
Below is my code:
/* GET INTENT */
$url = 'https://my.activecollab.com/api/v1/external/login';
$fields = array(
'email' => "email#email.com",
'password' => "****"
);
$intent = curl_post_connector($url, $fields);
$intent = $intent->user->intent;
/* GET TOKEN */
$url = 'https://app.activecollab.com/my_app_id/api/v1/issue-token-intent';
$fields = array(
'intent' => $intent,
'client_name' => 'My App Name',
'client_vendor' => 'My Company Name'
);
$token = curl_post_connector($url, $fields);
$token = $token->token;
Everything above works and get's the token properly. What I find really weird is that I have to use API v1 to get this, and the docs on ActiveCollab's site don't mention any URL for API v5. It seems like this is the approach everything is taking here on StackOverflow.
Now with the token, I try to get my list of projects:
/* GET PROJECT */
$url = 'https://app.activecollab.com/my_app_id/api/v1/users';
$headers = array (
"X-Angie-AuthApiToken" => $token
);
$projects = curl_get_connector($url, $headers);
var_dump($projects);
But this does not work. There is no error returned - it instead returns an array of languages for some reason! I don't want to paste the massive json object here, so instead I'll link you to a photo of it: https://www.screencast.com/t/7p5JuFB4Gu
UPDATE:
When attempting to use the SDK, it works up until I try getting the token (which is just as far as I got without the SDK). I'm getting Server Error 500, and when looking at the logs, it says:
/home/working/public_html/ac/index.php(21): ActiveCollab\SDK\Authenticator\Cloud->issueToken(123456789)
#1 {main}
thrown in /home/working/public_html/ac/SDK/Authenticator/Cloud.php on line 115
This is line 115 of Cloud.php:
throw new InvalidArgumentException("Account #{$account_id} not loaded");
I honestly don't think I did anything wrong... there must be something wrong with my account ID.
Just for kicks, I commented out that line, and the error disappears and the page loads fine - except now I have no token...

Plivo Rent a number Api not Working for me

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "My AUTH_ID";
$auth_token = "My AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
$params = array(
'number' => '12512077502' # Phone number to buy
);
$response = $p->get_number($params);
print_r ($response);
It Will Give me Error Message
Array (
[status] => 404
[response] => Array (
[api_id] => 0b6214ee-aec4-11e5-ae4f-22000ac69a0d
[error] => not found
) )
See here https://www.plivo.com/docs/getting-started/phone-number-api/#rent-a-number
You seem to be using the wrong function (get_number) from the python helper library. The correct one is "buy_phone_number" function which uses PhoneNumber API.
Reference - https://github.com/plivo/plivo-python/blob/master/plivo.py#L175
I was using the Python plivo module and had the same problem.
From Plivo Support: "Use the new API: https://www.plivo.com/docs/api/number/phonenumber/#buy-number "
What I found that the the plivo module uses the wrong URL when renting a phone number. My work around is to make the call without the helper library. The following is Python code but it might help give you an idea what to do.
import requests
params = {
'number' : phone_number # Phone number to buy
}
host = 'https://api.plivo.com/v1/Account/%s/PhoneNumber/%s/' % \
(account_sid, phone_number)
r = requests.post(host, timeout=5, json=params, auth=(account_sid, auth_token))
assert r.status_code == 201, 'r.status_code=%s' % `r.status_code`
Update: The above might not be necessary after all. I just got an update from Plivo support. The new method name is buy_phone_number() instead of get_number(). That solved the problem for me. I assume the same is true for the PHP library.

Getting an error trying to pass data to web service method using PHP

I'm trying to use PHP to pass submitted form fields to a web service that will create a user record in our database. I know the web service is working because I have ColdFusion code that is able to successfully create a user account with submitted parameters from my local machine. However, I need to get this working in php since our site is built in Drupal (php). I also tried the wsclient (drupal module) but to no avail.
I came accross this post (How to make a PHP SOAP call using the SoapClient class) which is similar to what I'm trying to do, but I keep getting an error. Here is the code I'm working with. Also, I need to pass the security password to use the web service in order to use it.
class Create {
function Create($securityPassword)
{
$this->securityPassword = $securityPassword;
}
}
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$create = new Create("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); //web service password
$params = array(
"Create" => $create,
"Prefix" => "Mr",
"FirstName" => "John",
"LastName" => "Doe",
);
//print_r($params);
$response = $client->__soapCall('Create', array($params));
var_dump($response);
Here is the error I'm getting:
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\wamp\www\sandbox\webservice2.php:23 Stack trace: #0 C:\wamp\www\sandbox\webservice2.php(23): SoapClient->__soapCall('Create', Array) #1 {main} thrown in C:\wamp\www\sandbox\webservice2.php on line 23
The method I'm trying to call is the "Create" method. You can see it exists in the wsdl url
I'd appreciate help in trying to successfully create a record using the web service via php.
This should allow it work.
XML
<Create xmlns="http://ibridge.isgsolutions.com/Account/">
<securityPassword>string</securityPassword>
<account>
<Id>string</Id>
<Status>string</Status>
<MemberType>string</MemberType>
<JoinDate>string</JoinDate>
<Prefix>string</Prefix>
<FirstName>string</FirstName>
<MiddleName>string</MiddleName>
<LastName>string</LastName>
<Suffix>string</Suffix>
<Designation>string</Designation>
<InformalName>string</InformalName>
<MajorKey>string</MajorKey>
<Title>string</Title>
<ExcludeFromDirectory>string</ExcludeFromDirectory>
<WebSite>string</WebSite>
<Company>string</Company>
<CompanyID>string</CompanyID>
<OrgCode>string</OrgCode>
<SourceCode>string</SourceCode>
<ExcludeFromMail>string</ExcludeFromMail>
<Category>string</Category>
<Gender>string</Gender>
<BirthDate>string</BirthDate>
<WorkPhone>string</WorkPhone>
<Fax>string</Fax>
<TollFree>string</TollFree>
<HomePhone>string</HomePhone>
<Email>string</Email>
<Chapter>string</Chapter>
<FunctionalTitle>string</FunctionalTitle>
<PaidThru>string</PaidThru>
<WebLogin>string</WebLogin>
<Password>string</Password>
<SecurityGroup>string</SecurityGroup>
<ExpirationDate>string</ExpirationDate>
<StaffUser>string</StaffUser>
<WebUser>string</WebUser>
<Demographics>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
</Demographics>
</account>
</Create>
code
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$params = [
"Create" => [
'securityPassword' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'account' => [
'Prefix' => 'Mr',
'FirstName' => 'John',
'LastName' => 'Doe'
]
]
];
$response = $client->__soapCall('Create', $params)->CreateResult;
var_dump($response);

Twitter API upload with PHP OAuth

I've been trying to find the best OAuth PHP lib for Twitter for hours. the TmhOAuth by Matt Harris seems kinda bloated (no offence) and started shooting PHP Warnings and Strict Standards notices right after I "installed" it.
All I want is to update my bg photo through the API. Just mine, so there is no need for any login and callbacks of any kind, all the keys are hard-coded.
In the end I found out about PHP's own thing: http://php.net/manual/en/book.oauth.php
Seemed cool because everything has 4 lines of code. The auth works and I can push stuff through the API, I just can't seem to send the image parameter though. This is the method: https://dev.twitter.com/docs/api/1/post/account/update_profile_background_image
I've found some examples that were using upload forms, but I have the photo already saved in a file, so how do I provide the, quote, base64-encoded image as raw multipart data?
$oauth->fetch
(
'https://api.twitter.com/1/account/update_profile_background_image.json',
array
(
'image' => '#' . $img_path . ';type=image/jpeg'
),
'POST'
);
Doesn't work, instead I get
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 500, expected HTTP/1.1 20X or a redirect)'
You can encode the image like this:
<?php
$im = imagecreatefromjpeg('file.jpg');
$im_Data = base64_encode($im);
?>
Then you should be able to add $img_Data into the api call.
I don't know if it is an open issue yet but the "image" key must start with "#" too.
$oauth->fetch
(
'https://api.twitter.com/1/account/update_profile_background_image.json',
array
(
'#image' => '#' . $img_path . ';type=image/jpeg'
),
'POST'
);
In case anyone is interested I ended up using TmhOAuth in the end. Bloated but it did the job.
$image = array
(
"#$path",
'type=image/jpeg',
"filename=$name"
);
$params = array
(
'image' => implode(';', $image),
'use' => 'true'
);
// Request
$code = $tmhOAuth->request('POST', $tmhOAuth->url
(
'1/account/update_profile_background_image'
),
$params, true, true);

Categories