Since it was always hard to find documentation i ‘ve gathered available noSOAP API documentation source here:

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')
        )
);

$soap_compositor can have a value of  ‘all’, ‘sequence’ or ‘choice’. In our case the value is sequence.

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.

About these ads