WebServices Wars: "The Phantom Menace": Creating the WebService WSDL file


Posted by: Andrea Benini in Servers on July 02 2009

Tagged in: webservices


WebServices Wars: "The Phantom Menace": Creating the WebService WSDL file


Now if you've followed the introduction "WebServices Wars: Creating a basic webservice using Eclipse, php and apache" you're now ready for Episode I

Intro

This webservice saga begins with the base of every good project: the planning and design phase.
Here's what I'm going to do:

This example will use SOAP techniques, SOAP is quick and easy to use, PHP already provide native SOAP classes, they're fast and well written in low level, not an external php library for SOAP. Personally I don't like NuSoap or third party libs for PHP, native support is reliable, fast, documented and stable.

I'll assume you already know what a webservice is, what you can do with it and how to use it in a real environment, please read this intro if you need it, it's a nice starting point.

As W3C suggests you can create a webservice with or without WSDL definition file, but if you're planning a big project or you just want to make things easy and well documented I suggest you to use WSDL files from the beginning, it's more easy to understand internals and speeds up your programming

Interface

Our sample webservice will provide these methods:

Method 1

twostringinput

input:

(string) param1

input:

(string) param2

output

(boolean) reply


Method 2

noinput_stringoutput

input:

(void: nothing)

output

(string) reply


These two methods are just samples to understand how you can use them, some sort of Hello World service.

Let's start

Now we need to write the webservice definition file (sample.wsdl), this file defines these two methods and their interfaces, the webservice url and other useful things, more documentation on WSDL can be found here from the official site.
You can obviously write this sample by hand, it's not difficult but when you do it the first time you can run into roubles if you don't know W3C documentation well. If you use Eclipse you already have a powerful tool called "The WSDL Editor", this amazing toy can create your WSDL files from a GUI interface in few minutes without orrying too much about WSDL internals, it's fast, intuitive and easy.
I'll suggest you to install the Eclipse Web Standard Tools (WST plugin) as well as WSDL tools and editors (WSDL), hese packages provides you HTML validators, html code completition, debugging tools, editors (web and wsdl) and lot of other useful functions.

Next episode will require PDT (PHP Development Tools) (Eclipse PDT plugin) so if you collect eclipse and these extensions you'll have a complete PHP/WebServices development tool, check out requirements from introduction article

When you're a beginner and you want to create a WSDL file with Eclipse you're probably looking for something good, already working and editable with WSDL Editor with no hassles, when I was googling around for wsdl files the first time I've found a lot of non-W3C compliants, malformed, wrong files and I've lost a lot of time to understand where errors were located, here's my sample for you.

According to my example and the two methods planned above here's the good W3C Compliant WSDL file:



























































transport="http://schemas.xmlsoap.org/soap/http" />


soapAction="http://my.website.com/twostringinput" />









soapAction="http://my.website.com/noinput_stringoutput" />













Create a new wsdl file (Eclipse: File, New, File) and name it sample.wsdl
Save the file and close it so you've this working sample.

When WSDL Editor is installed you can directly open it in GUI mode (WSDL Editor Itself),
it's easy to read, maintain, rewrite and modify, take a look at the following picture:


Amazing, isn't it ?
With this tool you can see in a nice gui mode your webservice, easy for a newbie and for an expert as well. When you select an item you can select and modify its properties in the properties window, take a look at my sample data and see where they are located


If you click on the arrows in the right side you can open another window with input parameters for the two methods, take a look at the picture below

Here are the methods



Play with the file, it's a good starting point for future projects, it was created with Eclipse 3.4 Ganymede and latest tools synced from Eclipse central repository, you can easily open it with outdated eclipse versions or without WSDL editor as well; Eclipse doesn't have backwards compatibility issues (like other IDEs)

When finished just put this file in your webserver and make it accessible from outside, in my example this file it's located in /var/www/htdocs/sample.wsdl, according to my current Apache2 config this file is available from the following url: http://my.website.com/sample.wsdl, sample.php (webservice server) and client.php (webservice client) will refer to this url for getting WSDL properties

For a closer look at WSDL Editor take a read at the WSDL Editor Documentation, it's THE starting point for everything, refer to W3C for reliable SOAP and WSDL documentation


Stay tuned for the next episode...

Introduction: "WebServices Wars: Creating a basic webservice using Eclipse, php and apache"

Episode I "The Phantom Menace": Creating the WebService WSDL file"

Episode 2 "Attack of the Clones": Creating the WebService php Server (coming soon)