views:

515

answers:

5

Hello,

My question is needed for some basic understanding off webservices and more specificly in conjunction with php

I would like to know, if it is neccasary to have a wsdl file for the creation off a webservice or is that just something that is usefull to third party's that want to access the webservice? Also, it's generated automaticly in .net environments, but for php it's a bit more difficult.

What are my options?

The thing I am after is to create a jm2ee application on my mobile that sends data to the webservice from time to time. I read somewhere that you have to supply the arguments when there is no wsdl file. What is meant by that? and/or what are the implications off that?

Thanks in adv, Richard

+1  A: 

WSDL file documents in a machine readable (XML) format what the methods (and args for methods) offered by a web service. You do not need a WSDL file if you know what the methods and args are - though WSDL is very good to have as a means of making the web service public interface more 'contractified', if you will.

To the best of my knowledge the PHP library does not have functions to automagically generate a WSDL file for you.

Eric M
but if you don't use it, it will not suffer any delays or be less efficient?
Richard
It appears that you are right about wsdl's, but there are alternatives. see http://www.brainbell.com/tutorials/php/Creating_A_Web_Service_With_PHP_5%27s_SOAP_Extension.htm
Dana the Sane
@Richard using wsdl's tends to be *less* efficient. These files can become large quite quickly, so retrieval and parsing time become non-trivial.
Dana the Sane
Any retrieval or parsing issues would only be issues when the WSDL is retrieved, or am I missing something? Most SOAP tools do not read the WSDL every time the service is called, but only once.
John Saunders
A: 

Web service support is built into php5, your best starting place is the documentation.

Dana the Sane
+3  A: 

I would like to know, if it is neccasary to have a wsdl file for the creation off a webservice

No, it is not necessary (at least, not in PHP) : it helps others know how to access your webservice (which methods, objects, ... should be used), but a WS can be called even if it doesn't export a WSDL

For PHP, yes, it is a bit difficult to get a WSDL (many classes don't generated them :-( ) ; still, you can generatd it with another tool (there are tools in Eclipse to write WSDL files, for example).

There was PEAR::Soap that was able to generate WSDL from PHP code (but you had to write down many lines of code to get it right) -- considering there is a class included in PHP 5 to work with SOAP, I wouldn't recommend using this one, anyway.

For more informations, you can have a look at :

Pascal MARTIN
Well, let me add something to what I said : maybe with Zend_Soap, you can generate a WSDL after all ; see http://framework.zend.com/manual/en/zend.soap.wsdl.html about that : it says "The Zend_Soap_Wsdl package contains both a parser and a builder of WSDL documents. " (I haven't try, though, and don't know how well it's working)
Pascal MARTIN
That seemed to be one off the limited options. Zend studio is a paid software. That was one off the reasons for stating my question.
Richard
I did not talk about Zend Studio : I talked about Eclipse (which is free ; as well as Eclipse PDT), and about Zend Framework (which is free too). Zend Studio is an IDE that costs money, yes ; but Zend Framework is a PHP-Framework that is free (costs no money, and BSD licence)
Pascal MARTIN
sorry, was to quick in giving an answer. I like the comments where they said I don´t need it at all. Saves me some work. It´s supposed to be a service that is not publicly accessible anyway. I have to make an app in netbeans that will comunicate with the webservice. That way it will only work if the app is installed.
Richard
(no problem :-) ) Well, if you can do whatever you want, maybe, yes, SOAP is a bit much and complicated (would I dare saying bloated ?) ; but it's can be quite useful when communicating when other langages / applications you have nothing to say about. Anyway, have fun ;-) (that's always the most important part ^^ )
Pascal MARTIN
I did not inmediatley meant not using soap att all. I was just referring to the not having to use wsdl files. I am not completely off the train off using soap for my purposess. But I did got some suggestions about setting up a webservice making use off REST. But I have not explored that all too much yet.
Richard
Oh, sorry, I misunderstood you ; my opinion is that if you are the one using the WS you're developping, you don't need to exports it's API. So, SOAP in non-WSDL is OK (and REST is too). Still, you definitly should write down somewhere what this API is (or, at least, comment it using phpdoc, like required by Zend_Soap_Server and Zend_Rest_Server)
Pascal MARTIN
Thanks, I should read the manual you provided. Diddn´t know about requirements to give comments off any sorts with phpdoc.
Richard
There is a note on http://framework.zend.com/manual/en/zend.soap.html saying "You should completely describe each method using method docblock if you plan to use autodiscover functionality to prepare corresponding Web Service WSDL" -- so, maybe not always necessary, but at least in some case ; and writing phpdoc is definitly something you should do, especially if this is a big project, or one many people will work on.
Pascal MARTIN
Even if you're the only one using the service, if you expect tools to know about the service (netbeans, maybe), then you need a WSDL. If you are creating and parsing the XML by hand, and if you are the only one accessing the service, and the only one who will ever access the service, then you won't need the WSDL.
John Saunders
A: 

If you are creating both the client and the web service, then there is no particular need to futz with SOAP, WSDL, or any of that jazz.

Just use the basics of the web: the client can use GET to fetch information, and POST to send it. You can format the data any way you like, but JSON and XML are common, well-defined approaches.

If you'd like inspiration for your API design, check out some popular examples:

That's enough to get you started, but if you're curious about the design philosophy, you can read up on Representational State Transfer or REST.

William Pietri
Ok, now I am confused again I started off reading netbeans tutorials, because I want to send gps data to the site for display. A webservice seemed to be the right way to do it. Anyway, I want to expand my knowledge of webservices so It will be usefull. If not for this then for something else. Thank you for the links.
Richard
Did you meant, that all off those example api are based on REST arcitecture??
Richard
Hi, Richard. There are a bunch of different ways to do web services. Using WSDL and SOAP is one way. But especially if you're already familiar with building things for the web, going with a simple RESTful approach can be much easier. I don't know how RESTful all of those APIs are; Google and Yahoo get up to a lot. Some of them definitely have both REST and SOAP versions. But Twitter and Flickr are pretty good REST examples. I also forgot to mention Amazon; many of their APIs are good REST examples.
William Pietri
Thanks, I definitley have to get into that. I will have to come back with other questions if I have any.
Richard
A: 

Some sources will use the term "webservice" as synonymous with SOAP. That is a misnomer. SOAP is a particular protocol - It is one way to create a web service. There are other technologies available. In general SOAP is the preferred standard with in Java and .net, but it is a bad fit outside of this sphere. If you have the option, I would strongly suggest that you consider either xml-rpc (Which is simpler and has better direct support on php) or a http-based service (Also called REST based).

troelskn
How do you mean, it´s better supported by php. Because I thought it was a predeccessor off the native soap functions as off php5.xxx? and they are all sending there data over the http layer slash protocol?
Richard
The SOAP protocol is immensely complex. The current soap extension only implements a subset of it (In particular the server side is rather patchy). xml-rpc is a much simpler protocol, so the extension covers it pretty well. It is correct that soap evolved from xml-rpc, but that doesn't mean that xml-rpc is obsolete.
troelskn
The SOAP protocol is not complex. "Complex" relative to what? Relative to TCP/IP? And the complexity is usually hidden by tools. If there are no free tools to hide the "complexity" form PHP, then I understand why it's considered "complex".
John Saunders
Not complex? You have got to be kidding me. Have you ever tried to implement against it? The fact that you need to wrap the protocol in an abstraction layer to be able to use it, should be a hint about something. Yes there are such abstraction layers available for PHP - They just don't cover all the myriad of variations of the protocol that exists, and they are - not surprisingly given the complexity - full of bugs.
troelskn