Since it was always hard to find documentation i ‘ve gathered available noSOAP API documentation source here:
- Getting complex with PHP and NuSOAP
- Programming with NuSOAP
- Programming with NuSOAP Part 2
- Introduction to NuSOAP
- Programming with NuSOAP Using WSDL
- Creating a web service and WSDL using NuSOAP
SOAP Arrays
I had a problem with using arrays with certain WS clients. It seems that nuSOAP uses SOAP array which are deprecated in favor of xml sequences according to WS-I. Here’s a small piece of code to create:
- An array of strings
- A soap structure
- An array of the above structure
$server->wsdl->addComplexType(
'ArrayOfDN',
'complexType',
'array',
$soap_compositor,
'',
array(
'dn' => array('name' => 'dn', 'type' => 'xsd:string',
'minOccurs' => '0', 'maxOccurs' => 'unbounded')
)
);
$server->wsdl->addComplexType(
'RoleDesc',
'complexType',
'struct',
$soap_compositor,
'',
array(
'cn' => array('name' => 'cn', 'type' => 'xsd:string'),
'description' => array('name' => 'description', type => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'ArrayOfRoleDesc',
'complexType',
'array',
$soap_compositor,
'',
array(
'desc' => array('name' => 'desc', 'type' => 'tns:RoleDesc',
'minOccurs' => '0', 'maxOccurs' => 'unbounded')
)
);
UTF-8 encoded values (foreign charsets)
Another thing to keep in mind is UTF-8 encoded values (usually in foreign charsets like greek in my situation). The best approach is to use the iconv() php function to transform native charset (eg ISO-8859-7) to UTF-8 for transport and disable nusoap automatic utf8 decoding. You should also make sure to set the http transport charset to UTF-8 instead of the default iso-8859-1. The corresponding values are:
- var $decode_utf8 = false; in the nusoap_client and nusoap_server classes
- var $soap_defencoding = ‘UTF-8′; in the nusoap_base class
Document/literal instead of RPC/Encoded
Modern web service clients usually request web services to be written in document-literal mode. Thus you should call the configureWSDL() and register() functions this way:
$server->configureWSDL(‘ReaderInterface’,”$url”,false,’document’);
$server->register(‘<function name>’,
array(‘argument” => ‘xsd:string’),
array(‘retval’ => ‘xsd:string’),
false, #namespace
$url . ‘#<function name>’,
‘document’,
‘literal’,
‘<function documentation>’);
In current nuSOAP version there is no way to omit the namespace attribute in the bindings part of the WSDL. That means that you will probably hit on warning such as:
R2716 WSI-BasicProfile ver. 1.0, namespace attribute not allowed in doc/lit for soapbind:body: “SearchUser”
line 370 of file:/C:/temp/NetBeansProjects/testWSDL3/xml-resources/web-service-references/reader/wsdl/<hostname>/ws/reader.php.wsdl
when attempting to parse the WSDL in your client. For now you have to save the WSDL and remove the namespace attributes by hand. Hopefully the nuSOAP people will have it fixed soon.
SOAP faults
One common problem that you may hit on is to get an error when dissecting a soap fault. The usual fault is something like:
“No NamespaceURI, SOAP requires faultcode content to be a QName”
That means that when creating a soap fault with new soap_fault($faultcode, $faultfactor, $faultstring, $faultdetail) the $faultcode should be something like SOAP-ENV:Client or SOAP-ENV:Server instead of just ‘Client’ or ‘Server’ just as it is described in the class prototype in nusoap.php.




4 comments
Comments feed for this article
March 2, 2009 at 7:15 pm
Mike
Just passing by.Btw, you website have great content!
______________________________
Don’t pay for your electricity any longer…
Instead, the power company will pay YOU!
April 16, 2009 at 3:16 am
Mathew Thomas
Recently for a project involving travelport xml api integration, we badly needed the soap requests to be gzip-ped, since the technical support people suggested.
http://www.php-trivandrum.org/tips/gzip-nusoap-requests.html
May 26, 2009 at 9:04 am
Francesco
Hi,
I can confirm that NuSOAP does handle array generally producing WSDL which does not follow the WS-I BP 1.1 specifications.
So, for example, if you want to consume your NuSOAP webservice with the SAP ERP, you probably will get an error message complaining about the arrayType generated by NuSOAP in the service wsdl (at least, this is my experience
).
see:
http://www.ws-i.org/Profiles/BasicProfile-1.1.html (WS-I BP 1.1 definitions)
I don’t know if you can teach the NuSOAP library to return/take in input arrays in a WS-I compliant fashion.
Do you have any idea about that? Thanks in advance
August 25, 2009 at 9:11 pm
daniel
Thanks a lot for putting all this together in one place. I ran into some of the links you had, but your compilation was very helpful.
In particular, the information you posted about the soap array and xml sequences alternatives was very useful as I did not see it anywhere else.
Suggestion: change the $soap_compositor variable to something like sequence or all or whatever else so that new people don’t get confused… I know I did. or you can initialize the variable here inside your examples.
Is there a nusoap documentation site somewhere? I would like to see the API for the function calls and maybe also figure out what else is there.
thanks!