Programming With NuSOAP Using WSDL
Programming With NuSOAP Using WSDL
http://www.scottnichol.com/nusoapprogwsdl.htm
Now for some magic. Point a Web browser at this service, which in my environment is at http://localhost /phphack/hellowsdl.php. The HTML that is returned to your browser gives you links to view the WSDL for the service or view information about each method, in this case the hello method. The screen should look something like this.
hellowsdl
View the WSDL for the service. Click on an operation name to view it's details.
hello
Displaying the details for the hello operation looks something like this.
1 sur 6
09/02/2012 09:57
http://www.scottnichol.com/nusoapprogwsdl.htm
hellowsdl
Close
View the WSDL for the service. Click on an operation name to view it's details.
hello
Name: hello Binding: hellowsdlBinding Endpoint: http://localhost/phphack/hellowsdl.php SoapAction: urn:hellowsdl#hello Style: rpc Input: use: encoded namespace: urn:hellowsdl encodingStyle: http://schemas.xmlsoap.org /soap/encoding/ message: helloRequest parts: name: xsd:string Output: use: encoded namespace: urn:hellowsdl encodingStyle: http://schemas.xmlsoap.org /soap/encoding/ message: helloResponse parts: return: xsd:string Namespace: urn:hellowsdl Transport: http://schemas.xmlsoap.org/soap/http Documentation: Says hello to the caller
So, with just a little code added to the service, NuSOAP provides browsable documentation of the service. But, that is not all. By either clicking the WSDL link on the documentation page, or by pointing the browser at the service with a query string of ?wsdl (e.g. http://localhost/phphack/hellowsdl.php?wsdl), you get the following WSDL.
Return to top.
2 sur 6
09/02/2012 09:57
http://www.scottnichol.com/nusoapprogwsdl.htm
Adding a few NuSOAP WSDL calls to the service allows it to generate WSDL and other documentation. By comparison, client support for WSDL is anti-climactic, at least for this simple example. The simple client shown below is not much different than the non-WSDL client. The only difference is that the constructor for the soapclient class is provided the URL of the WSDL, rather than the service endpoint.
Here are the request and response for this WSDL implementation.
Return to top.
3 sur 6
09/02/2012 09:57
http://www.scottnichol.com/nusoapprogwsdl.htm
Besides the additional code to support WSDL, the code for the service method itself is changed slightly. With WSDL, it is no longer necessary to use the soapval object to specify the name and data type for the return value. Similarly, the WSDL client does not need to use a soapval to specify the name and data type of the parameter, as shown in the following code.
4 sur 6
09/02/2012 09:57
http://www.scottnichol.com/nusoapprogwsdl.htm
WSDL enables one more capability on the client. Instead of using the call method of the soapclient class, a proxy can be used. The proxy is a class that mirrors the service, in that it has the same methods with the same parameters as the service. Some programmers prefer to use proxies because the code reads as method calls on object instances, rather than invocations through the call method. A client that uses a proxy is shown below.
Regardless of whether the "regular" or proxy coding style is used, the request and response messages are the same.
5 sur 6
09/02/2012 09:57
http://www.scottnichol.com/nusoapprogwsdl.htm
Return to top. You can download the source for these examples as well. Return to top.
Resources
Join the NuSOAP mailing list to learn more and ask questions. The home of the NuSOAP project. NuSOAP home of Dietrich Ayala, the author of NuSOAP. Return to top.
Copyright 2003-2004 Scott Nichol. 03-Nov-2004
6 sur 6
09/02/2012 09:57