Zend Soap WSDL Generation - Windows permission error - php

I am trying to generate a WSDL for a working Soap web service using the following PHP code (the code is running in Xampp on Windows 7):
<?php
include('Zend/Soap/AutoDiscover');
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('MyService')
->setUri('http://localhost/Public_Web_Service')
->setLocation('http://localhost/Public_Web_Service/server.php')
->setServiceName('MyService');
$wsdl = $autodiscover->generate();
$wsdl->dump("C:/xampp/htdocs/file.wsdl");
?>
However, when I run the code, I run into the following error message:
Warning: include(C:\xampp\php\pear\Zend\Soap\AutoDiscover): failed to open stream: Permission denied in C:\xampp\htdocs\Public_Web_Service\zend-wsdl.php on line 2
Warning: include(): Failed opening 'Zend/Soap/AutoDiscover' for inclusion (include_path='.;C:\xampp\php\PEAR;c:\xampp\php\PEAR\Zend') in C:\xampp\htdocs\Public_Web_Service\zend-wsdl.php on line 2
Fatal error: Class 'Zend_Soap_AutoDiscover' not found in C:\xampp\htdocs\Public_Web_Service\zend-wsdl.php on line 3
I am very new to Zend and my main focus is on creating Soap web services in PHP.
Any help would be greatly appreciated.
Thanks,
John Cleaver

Change:
include('Zend/Soap/AutoDiscover");
To:
include('Zend/Soap/AutoDiscover.php");
include() looks for a physical file on your server - so the file part needs to reflect the exact file name.
You're working with Zend Framework 1 it looks like. In your application you could use something like this in your bootstrap (startup) scripts:
function myAutoload($className)
{
$classArray = explode("_", $className);
foreach ($classArray as $key => $value) {
$classArray[$key] = ucfirst($value);
}
$className = implode('/', $classArray);
require_once($className . ".php");
}
spl_autoload_register("myAutoload");
Then you never need to include() anything - it just automatically loads. But please note that this is legacy functionality. Zend Framework 2 as well as other modern frameworks do not use this feature for a reason. I'm still a big fan of Zend Framework 1 because of its user friendliness - something that most modern frameworks lack. If you want to keep using Zend Framework 1, the above snippet can save you a lot of time.

Related

Include_Path, require once, PHP issues using Zend

I am new to PHP, so I apologize for my inexperience. I am working in a Windows 10 environment and have installed WAMP to serve Apache, PHP, and MySQL. I am creating some remoteObject webservices for an Adobe AIR app that will communicate with Zend using AMF, and I have created an index.php file to get everything in motion, but when I browse to the index.php file, I get all kinds of errors. Here is the index.php file:
index.php
<?php
require_once('Zend/Amf/Server.php');
require_once('HalfService.php');
$server = new Zend_Amf_Server();
//adding our class to Zend AMF Server
$server->setClass("HalfService");
//Mapping the ActionScript VO to the PHP VO
//you don't have to add the package name
$server->setClassMap("VOService", "VOService");
echo($server -> handle());
?>
My File structure is:
C:/wamp64/www/
ZendFramework/library/Zend/Amf/Server.php
zendamf_remote/index.php
HalfService.php
VOService.php
I tried to create a include_path in my php.ini file that looks like this, but it did not work:
include_path = “c:\wamp64\www\ZendFramework\library”
Finally, this is the error that I get when I browse to index.php in a browser:
( ! ) Warning: require_once(Zend/Amf/Server.php): failed to open stream: No such file or directory in C:\wamp64\www\zendamf_remote\index.php on line 2
( ! ) Fatal error: require_once(): Failed opening required 'Zend/Amf/Server.php' (include_path='�c:\wamp64\www\ZendFramework\library�') in C:\wamp64\www\zendamf_remote\index.php on line 2
Any help at all in getting this configured would really be appreciated. Thanks so much!
"In your question you appear to have smart quotes around the path, so that may be it. See if changing that helps. – Tim Fountain"
Thanks to Tim Fountain for answering this question, who noticed something I wouldn't have seen in a million years

Word to HTML conversion not working - PHP + ZEND

Am new to PHP and this is my first time using Zend Framework to convert a Word file to HTML file. I am using this code.
<?php
$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge->setUsername('myUsername')->setPassword('myPassword');
$mailMerge->setLocalTemplate('docs/file.docx');
$mailMerge->assign(null);
$mailMerge->createDocument();
$data = $mailMerge->retrieveDocument('html');
file_put_contents('docs/file.html',$data);
?>
Copied from http://www.phplivedocx.org/2009/08/13/convert-docx-doc-rtf-to-html-in-php/
I've even included the path of Zend in php.ini file.
include_path = ".;c:\php\includes;C:\ZendFramework-1.12.11\library"
But its still showing me the error.
Fatal error: Class 'Zend_Service_LiveDocx_MailMerge' not found in C:\wamp\www\word2html_zend\index.php on line 2
I've googled it and also searched in stackoverflow search.. But no solution worked for me.. What should I do to get the code to work?
EDIT::
Am using Windows 8 operating system and PHP version 5.5.12
it is not enough included the path for Zend. You need to register Zend autoloader before calling any class from Zend library,
like
// Initialize application loader
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->registerNamespace('Zend_');

Soap Client Call to SSL

I am trying to get the content of WSDL from HTTPS Server
<?php
echo file_get_contents("https://zendsoap.lan/Zend_Soap_Server.php?wsdl");
?>
It Return:
Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:1408E0F4:SSL routines:func(142):reason(244) in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
Warning: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl) [function.file-get-contents]: failed to open stream: operation failed in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
AND when I can goto the WSDL Location (https://zendsoap.lan/Zend_Soap_Server.php?wsdl): Everything looks fine.
P.S: Can anybody tell me how can I share the WSDL file
I agree with RockyFord regarding it being an SSL issue (I'm pretty sure you will have a self signed certificate in place and due to using SSL there are a few steps you will need to take in order to minimise security concerns). Regarding the immediate issue you could try fixing it with code similar to this:
$url = 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl';
$contextOptions = array(
'ssl' => array(
'verify_peer' => true,
'CN_match' => 'zendsoap.lan' // assuming zendsoap.lan is the CN used in the certificate
)
);
$sslContext = stream_context_create($contextOptions);
$wsdlContent = file_get_contents($url, NULL, $sslContext);
(UPDATE: It might seem like an easy solution to change the code above to
'verify_peer' => false
while it may be ok for basic development it's not really a good idea and definitely shouldn't be used in a production environment as it introduces serious security concerns - see this excellent article on How to properly secure remote API calls over SSL from PHP code by Artur Ejsmont for more on this subject as well as the Transport Layer Security Cheat Sheet and Securing Web Services by OWASP)
To pick up on your point regarding sharing a WSDL from within a Zend Framework application you could do something like this to get started:
// go to application/configs/application.ini
// if your APPLICATION_ENV is development then add the following line in the development section:
phpSettings.soap.wsdl_cache_enabled = 0
The line above will prevent your wsdl being cached during development. Next you might want to create a SoapController and add this action like this:
public function serverAction()
{
$baseUrl = 'http://zendsoap.lan/soap/server';
if( isset( $_GET['wdsl'] ) ) {
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$server = new Zend_Soap_AutoDiscover($strategy);
$server->setUri($baseUrl);
$server->setClass('Application_Model_Web_Service');
$server->handle();
} else {
$server = new Zend_Soap_Server($baseUrl . '?wsdl');
$server->setClass('Application_Model_Web_Service');
$server->handle();
}
}
The nice thing about the approach above is the WSDL will be generated for you on the fly. You will have noticed the setClass() method is going to be called with 'Application_Model_Web_Service' passed as the only parameter. To test your configuration I recommend you create that class and insert the method below. Testing your configuration with a simple service containing a single method will help you with troubleshooting before you make the service more complex. Here is the example method:
// Note: you should definitely comment your methods correctly in the class so
// the WSDL will be generated correctly - by that I mean use #param and #return
// so the correct input and output types can be determined and added to the WSDL
// when the the ZF component generates it for you
/**
* #return string
*/
public function getMessage()
{
return 'ok';
}
(UPDATE: Also in response to the question you asked regarding using Zend_Soap_Client to access the web service, since it looks like you're intending to make it a secure service I'd suggest you raise a separate question regarding setting up secure soap services with php. If you explain more about what you're trying to do in that question you may get some good input from a range of experts on best practices :-)
)
I know you're new to SO so if you're happy with the answer you can accept it, also generally it's best to just reply to an answer rather than add another answer to reply. Easy when you know how of course and even easier when someone tells you ;-)
I tried your way of defining The Soap Server, only thing was I used my custom class instead of using Application_Model_Web_Service. I am using single files for Client & Server. When I run https://zendsoap.lan/Zend_Soap_Server.php without ?wsdl it result in this:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl' : failed to load external entity "https://zendsoap.lan/Zend_Soap_Server.php?wsdl"
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And When I try file_get_contents() the way you told, I get this:
Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:func(144):reason(134) in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl) [function.file-get-contents]: failed to open stream: operation failed in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Here is link to screenshot of My Certificate:
http://i.stack.imgur.com/bKoVD.png
Loads of thanks for your help.
Problem solved By changing 'verify_peer' => false
Can you (#dkcwd) please tell me what should be the code if I use Zend_Soap_Client without file_get_contents(). I mean is there any option which i can't find on internet to do something similar to 'verify_peer' => false.
Loads of Thanks to #dkcwd
UPDATE: Let me summarise what exactly I am doing, I am trying to create a basic SOAP Server over SSL. Before making Web Services available on my Production website, I have to test it on Development system with has got Self Signed Certificate (Whose authentication is a problem right now).
Following are the problems I am facing in that regard:
When I try to call https://zendsoap.lan/Zend_Soap_server.php?wsdl its works fine I can view the wsdl.
But when I try https://zendsoap.lan/Zend_Soap_server.php, I get this:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl' : failed to load external entity "https://zendsoap.lan/Zend_Soap_Server.php?wsdl"
Is that something I should be
The reason I made verify_peer=>false as I am running it on dev server so no need to verify my own created certificate, but obviously on production I want the Certificate to be verified.
This thing work fine with NuSoap but most of the stuff in NuSoap is deprecated for our server which is running PHP 5.4.6, So the most reliable solution for me using PHP's SOAP extension. And the reason for me using Zend is we're in process of moving our system from some third party framework to Zend Framework and everyday I get requests from client to add this & that new components, I assumed if I develop every new request from Client using Zend libraries then it will be easy for me in later stages to move to Zend Framework.
I hope I made some sense there.
Many Thanks in advance...

Weird Zend Framework issue - include_once is looking in the wrong folder

I've spent a lot of time troubleshooting this myself but none of what I've read solves my issue so I'm hoping I get some help here.
So anyway, I have written a PHP script that provides various functions to connect with Google Calendar. When I run this script directly using some inline test code to call my functions, everything runs fine. However, when I call the function from other scripts using 'require_once' to include it I get the following errors:
Warning: include_once(Zend\Gdata\Calendar\Extension\EventQuery.php) [function.include-once]: failed to open stream: No such file or directory in C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib\Zend\Loader.php on line 134
Warning: include_once() [function.include]: Failed opening 'Zend\Gdata\Calendar\Extension\EventQuery.php' for inclusion (include_path='.;C:\xampp\php\PEAR;C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib;C:\xampp\htdocs\TiersForTea.com\lib') in C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib\Zend\Loader.php on line 134
Your first thoughts might be that I'm not using the correct include path, but I have checked and rechecked this many times. I even tried hard coding the path. I'm quite sure that I'm using the correct path.
Now for the weird bit. If you look at the error you will notice the file Zend is trying to include: Zend\Gdata\Calendar\Extension\EventQuery.php. This file does not actually exist in the 'Extension' folder. It does exist in the parent folder though. If I just copy 'EventQuery.php' into the 'Extension' folder my script runs as expected. Weird, right?
So that does sorta solve my problem, but I would like to know what's going on here in-case it creates further issues. I should also note that I'm calling this script into an OpenCart module.
You might want to see some of my code so here's a snippet of the important bits, if you want more details just let me know:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath('\\lib') . PATH_SEPARATOR . "C:\\xampp\\htdocs\\TiersForTea.com\\lib");
require_once('Zend/Loader.php');
function connect() {
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
I doubt the error exists in any of the Zend files as you have indicated it works correctly in your isolation tests.
The error is thrown from Zend_Loader which means something in your code is making reference to Zend_Gdata_Calendar_Extension_EventQuery.
Check the stack trace for the error if available to pinpoint the location. If that's not available, do a global find for that string. If you find any matches, you will need to change them to Zend_Gdata_Calendar_EventQuery.
Update
Seems this is a known bug(s)
http://framework.zend.com/issues/browse/ZF-7013
http://framework.zend.com/issues/browse/ZF-11959
It's an issue when your code registers an error handler using ErrorException. Apparently it's fixed in the 1.12 branch but hasn't made it to a release yet.
There's a patch in the 11959 bug report that fixes the issue

Open Flash Chart and Zend Framework Autoloader: class not found

I'm trying to upgrade the charts in my zend framework based website to the open flash chart 2 (version: kvasir) library. It used to work just fine with older versions. However, using the new version, when I try to create e.g. lines, I get error messages such as
Warning: include(line\hollow.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\weMatch\library\Zend\Loader.php on line 83
Fatal error: Class 'line_hollow' not found in C:\xampp\htdocs\weMatch\application\default\controllers\FeedbackController.php on line 215
I suspect that the Zend_Loader_Autoloader is replacing the underscore with a backslash. Can I exclude the whole open flash chart library from the Zend_Loader_Autoloader?
It is changing the _ to /. You could just include the file yourself beforehand.
require_once('path/to/line_hollow.php'); or whatever the filename is.
I found out that the API of the open flash library has changed with the new version (kvasir). As in old versions, there's a file you need to include which includes all the other library classes (open-flash-chart.php). I saw that the class line_hollow.php was commented out in this file and I therefore guess it's deprecated. When I tried to include line_hollow.php, there were some follow up errors. Luckily, there are other ways to achieve the same result. Instead of:
$line = new line_hollow();
you go
$line= new line();
$dot = new hollow_dot();
$line->set_default_dot_style($dotTeam);
The latter way gives you more flexibility, because you can give the $dot additional attributes.

Categories