How to create Web services

In this topic ...

Creating Schemas for Complex Argument and Return Types

Creating Composite Web Services

Related Topics ...

Overview: Services

How to Consume Web Services

How to Publish Web Services

How to Use the Web Service Enable Builder

We can create web services by simply adding a Web Service Enable builder call to a model and choosing a method to expose a Web service.

If you expose more than one method in a model as a service, simply add additional Web Service Enable builders to the model.

See "How to Use the Web Service Enable Builder," for information about adding a Web Service Enable builder call to your model.

 

Create Schemas for Complex Argument and Return Types

If the method you want to expose as a Web service takes one or more XML arguments or returns an XML structure, we need to create a schema that describes the structure for the argument and return types and then add a Schema builder call to your model to add the schema to the model. The WSDL document generated by the "getWSDL" action includes any schemas needed for describing the inputs and outputs of a service.

The Schema Builder will accept only XML Schema 2001 XSD which we can create with third-party tools such as "XML Spy." Alternately, the Simple Schema Generator Builder will build a schema into the model from simple XML such as that shown below.

For example, if the method takes an IXml argument with the following structure:

<customers>

   <customer>

       <name></name>

       <id></id>

   </customer>

   ...

</customers>

The corresponding schema would be:

<?xml version="1.0" ?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

              targetNamespace="http://www.acme.com"

              xmlns="http://www.acme.com">

  <xsd:element name="customers">

     <xsd:complexType>

        <xsd:sequence>

           <xsd:element name="customer" minOccurs="1" maxOccurs="unbounded">

              <xsd:complexType>

                 <xsd:sequence>

                    <xsd:element name="name" type="xsd:string" />

                    <xsd:element name="id" type="xsd:string" />

                 </xsd:sequence>

              </xsd:complexType>

           </xsd:element>

        </xsd:sequence>

     </xsd:complexType>

  </xsd:element>

</xsd:schema>

This schema requires the developer calling this service to pass a <customers /> structure that contains at least one <customer /> element.

 

Create Composite Web Services

We can create composite Web services by setting the inputs of one service to be the output from another service, by configuring the appropriate service call to use the output from the first service as its input and creating a method that invokes the two services. The following steps describe the process in more detail:

  1. Determine which service(s) return the inputs to the subsequent service call.

  2. Configure the service call that uses the output from one or more services as its inputs.

  3. Write a wrapper method that invokes the "input" services and then invokes the "consumer" service.

  4. Web service enable the wrapper method.