Is using CURL for SOAP a bad practice? - php

There is a piece of software in my company connecting periodically with some webservices via SOAP protocol using curl in PHP. From time to time this fails and the whole system is very unstable. I was a bit surprised seeing curl as a main tool talking to these webservices, because I thought there exist robust and mature high level libraries for most languages (including PHP and python) and curl is relatively low-level and doesn't provide any error handling. Am I right? What is the best solution for communication via SOAP? Is there some enterprise standard I can follow? Please help.

PHPs build in SOAP Client is already very robust and abstracts many of the commonly needed stuff:
$this->soapClient = new SoapClient($wsdl_url);
// What interface is available, which function can you call?
var_dump($this->soapClient->__getFunctions());
// Call
$result = $this->soapClient->someMethodExposedByTheApi();
// Soap Elements (Tags in the XML) are available as properties:
echo $result->someProperty;
// Nested Tags are available as object chain:
echo $result->someNestedTags->nestedTag;
I could not imagine how it can be any simpler ...
If you need to setup a SOAP Service, you may want to use Zend_Soap, a stand alone component in the Zend Framework, that automatically builds a webservice based on a wsdl. It also has a wrapper on top of PHP's SoapClient, but this is mainly used to converge naming and coding conventions to the Zend Framework and does not provide much additional functionality.
However: Curl is ok if you have very specific requierements. If it fails from time to time and your system is unstable, than it's not a problem of curl. It may be a misconfiguration of the service or system.
Basically the SoapClient builds an XML based on the Standard. If you build the XML for yourself (for whatever reason), curl is ok.

Related

Features of PHP SOAP

I am wondering the features that are fully supported within PHP Soap, I have tried researching this, but there is very little documentation to support PHP Soap.
Also how is Soap used during the exchange of data through client machine to web service then server.
I know this is fairly vague, but as I am constantly being asked this myself I thought it was better to find more about it.
PHP has some build in SOAP classes for both client and server. Docs is on here.
But you have to be sure that your PHP build is compilled with SOAP support.
"The features that are fully supported within PHP" are pretty much non-existent.
Built in SOAP client is ok only for basic services. It doesn't support any WS extensions, so you have to add support manually, e.g. including headers for WS-Security.
Also, there are some problems with namespace handling and creating requests.
If you'll be using it and are having trouble with missing parameters or badly formatted requests, you'll probably want to modify requests - this can be done by extending SoapClient class and overriding doRequest function.

wsdl 2.0 support in PHP

If I want to create a web service or consume a web service that is defined as WSDL 2.0, what options do I have in PHP?
As I understand it the in-built SOAP libs in 5.x don't currently support WSDL 2.0 spec, and I can't see future support for this.
One of my former colleagues used to devour SOAP services manually, simply because he disliked the current .net implementation.
The SOAP implementation is based around you posting XML across the web to the service, and you "just" need to build a such XML and parse the results coming back. It is not as simple as it sounds, but it definitely is possible.
The WSDL2PHP project seems very interesting, and im very sure this can lead you in the right direction.

Which tools to build a SOAP server in PHP?

We are investigating options to build a SOAP webservice in PHP. We have some requirements:
Authentication via SOAP Headers
HTTPS
Fine control over XML used in SOAP response
Good documentation and support community.
(Optional) WS Security support
There's the following tools providing such functionality:
Native PHP SoapServer
Zend_Soap
NuSoap
WSO2 WSF/PHP
PEAR::SOAP
Zend_Soap is actually a framework-compatible wrapper for the native PHP Soap-implementation. We have some simple tests running, but SOAP headers are not supported, and we don't have full control over the XML response. For instance, the response XML has a namespace on the root element, but not on it's child elements. Pretty annoying.
NuSoap is not really maintained anymore and I have read it has some issues with PHP 5.3 naming conventions.
WSO2 WSF/PHP uses a php extension which has to be compiled manually. There are some dependencies and the entire compile process is not clearly documented. The documentation is scattered around the website (sometimes outdated) and in the packaged downloads. A linux binary is mentioned, but nowhere provided for download (at least not in the last 5/6 releases).
I don't really know a lot about PEAR::SOAP, but I have some experience with PEAR classes. Usually they are not well-documented and do not catch errors gracefully, leaving you googling every error message, with varying outcomes.
Do you know of any other tools that can help me build a full-fledged SOAP server in PHP, considering our requirements?
If you need WS-Security, then WSO2 might be your only option. Did you install all the prerequisite packages (openssl, libxml2) before compiling. Compilation is simple with ./configure, make && make install (I didn't have any issues with 2.1.0 wrt. compiling). WSO2 offers full control of the payload XML structure.
If you can live without WS-Security, then any of the other options are good. I'd recommend PHP's own SOAP library. It's pretty decent, but doesn't offer very good control over the XML and lacks WSDL autogeneration.
I do not know any other. I used in the past always PEAR SOAP, but unfortunately it seems it is not maintained anymore. There you do not need a documentation, it is pretty easy to use.
But I would go the Zend-SOAP way if I had to build another SOAP client/server, because all others are not up-to-date.

What is the best solution for creating a SOAP Server in PHP?

I need some advice on which library is the best choice when it comes to creating SOAP servers (and eventually SOAP clients) in PHP.
I know there is built-in functions for this, but is that really the best way to go about it?
Also, if you could attach some arguments as to why a certain library/method is the better, i'd be much delighted.
The only requirement i currently have (apart from the obvious client/server part) is that it can generate WSDL.
Does the WSDL version really matter at all? 1.1 or 2.0 what's the real difference/benefit of using 2.0?
I would recommend looking at the Zend_Soap class of Zend Framework.
Its fairly complete and robust and has been available in the framework long enough to have most if not all of its rough spots smoothed out. Plus its part of a framework that is being actively maintained so it will continue to support new standards and any bugs that are found will be fixed.
I use PHP's built-in SoapServer class to serve requests because it's implemented in C so it's faster than any other class implemented in PHP (Zend, nusoap).
The limitation here is that SoapServer can't generate WSDL (as of May'11) so i am using Zend SOAP Autodiscovery to generate it.
I use nuSoap: http://sourceforge.net/projects/nusoap/

Is it necessary to have a wsdl file for the creation of a webservice in php?

My question is needed for some basic understanding of webservices and more specificly
in conjunction with php
I would like to know, if it is necessary to have a wsdl file for the creation of 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 of that?
Thanks in advance, Richard
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 :
SoapServer ; especially, if you look at the documentation of SoapServer::__construct, you will notice it can work both in WSDL and non-WSDL mode
Zend_Soap
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:
Twitter API
Flickr API
all the Google APIs
all the Yahoo APIs
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.
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.
Web service support is built into php5, your best starting place is the documentation.
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).

Categories