Get Started with SOAP Server Applications

From HTML5 Builder
Jump to: navigation, search

A SOAP server application is a server web application that provides services from a web server. Services are functions that can be called from a client application from anywere, no matter which programming language was used for the client or server sides.

HTML5 Builder makes it possible to easily create a server-side SOAP application to provide services to other client-side applications.

To start a SOAP server application, create a new project from Home > New > Other Projects > Soap Server Application.

Service Registration

Now is time to register the services your webservice is going to publish to the world, to do that, generate the OnRegisterServices event and call the register() function of your webservice component, here are some samples:

function MyWebServiceRegisterServices($sender, $params)
{
  //Register the echo service
  $this->MyWebService->register(
  "serviceEcho",
  array('input'=>'xsd:string'),
  array('return'=>'xsd:string'),
  'http://localhost/'
  );
 
 
  //Register the conversion service
  $this->MyWebService->register(
  "StringArrayToIntArray",
  array('input'=>'tns:ArrayOfstring'),
  array('return'=>'tns:ArrayOfinteger'),
  'http://localhost/'
  );
}

This can be read as we want to publish a service called "serviceEcho", which has one input parameter of time string and returns a string. Also, we register another service called "StringArrayToIntArray" which gets an array of strings as input and outputs the same array, but converted to integers.

You should write the code for that functions in PHP code, here is the code for them:

/*
* Returns the input
*/
function serviceEcho($input)
{
  return $input;
}
 
/*
* Converts the input array, which are strings, to an array of integers
*/
function StringArrayToIntArray($inputarray)
{
  $result=array();
  foreach($inputarray as $val)
  {
    $result[]=(int)$val;
  }
 
  return $result;
}

In the first function, it returns the input as an echo service and in the second one, returns an array of integers from the string array of the input.

Adding Complex Types

The second function we have added used complex types, that is, types are not single or native ones for the language we are working on, so we need to specify how to handle them, both by the webservice and the client.

To do that, we have the OnAddComplexTypes event, in which we must call the addComplexType function of the webservice, now we are going to register the types, ArrayOfinteger and ArrayOfstring:

function MyWebServiceAddComplexTypes($sender, $params)
{
  //Add the complex type array of strings
  $this->MyWebService->addComplexType
  (
    'ArrayOfstring',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]')),
    'xsd:string'
   );
 
   //Add the complex type array of integers
   $this->MyWebService->addComplexType
   (
     'ArrayOfinteger',
     'complexType',
     'array',
     '',
     'SOAP-ENC:Array',
     array(),
     array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'integer[]')),
     'xsd:integer'
   );
}

Basically we are setting the name of the type, the type class, usually "complexType", the PHP type, the last parameters are the WSDL type and the base type of the array, an integer or an string.

Note: When using a complex type registering services, you need to refer to qualify it as "tns:", not as "xsd:"

See Also

Personal tools