Writing Servers that Support Web Services

From RAD Studio
Jump to: navigation, search

Go Up to Using Web Services Index

In addition to the invokable interfaces and the classes that implement them, your server requires two components: a dispatcher and an invoker. The dispatcher (Soap.WebBrokerSOAP.THTTPSoapDispatcher) receives incoming SOAP messages and passes them on to the invoker. The invoker (Soap.SOAPHTTPPasInv.THTTPSoapPascalInvoker) interprets the SOAP message, identifies the invokable interface it calls, executes the call, and assembles the response message.

Note: THTTPSoapDispatcher and THTTPSoapPascalInvoker are designed to respond to HTTP messages containing a SOAP request. The underlying architecture is sufficiently general, however, that it can support other protocols with the substitution of different dispatcher and invoker components.

Once you register your invokable interfaces and their implementation classes, the dispatcher and invoker automatically handle any messages that identify those interfaces in the SOAP Action header of the HTTP request message.

Web services also include a publisher (Soap.WSDLPub.TWSDLHTMLPublish). Publishers respond to incoming client requests by creating the WSDL documents that describe how to call the Web Services in the application.

Building a Web Service server

RAD Studio provides a wizard to speed development of a Web Service server application.

Use the following steps to build a server application that implements a Web Service:

  1. Choose File > New > Other, and on the WebServices page, double-click the Soap Server Application icon to launch the SOAP Server Application Wizard. The wizard creates a new Web server application that includes the components you need to respond to SOAP requests.
  2. When you exit the SOAP Server Application wizard, it asks you if you want to define an interface for your Web Service.If you are creating a Web Service from scratch, click yes, and you will see the Add New Web Service wizard. The wizard adds code to declare and register a new invokable interface for your Web Service. Edit the generated code to define and implement your Web Service. If you want to add additional interfaces (or you want to define the interfaces at a later time), choose File > New > Other, and on the WebServices page, double-click the SOAP Web Service interface icon. For details on using the Add New Web Service wizard and completing the code it generates, see Adding New Web Services.
  3. If you are implementing a Web Service that has already been defined in a WSDL document, you can use the WSDL importer to generate the interfaces, implementation classes, and registration code that your application needs. You need only fill in the body of the methods the importer generates for the implementation classes. For details on using the WSDL importer, see Using the WSDL Importer.
  4. If you want to use the headers in the SOAP envelope that encodes messages between your application and clients, you can define classes to represent those headers and write code to process them. This is described in Defining and Using SOAP Headers.
  5. If your application raises an exception when attempting to execute a SOAP request, the exception will be automatically encoded in a SOAP fault packet, which is returned instead of the results of the method call. If you want to convey more information than a simple error message, you can create your own exception classes that are encoded and passed to the client. This is described in Creating Custom Exception Classes for Web Services.
  6. The SOAP Server Application wizard adds a publisher component (TWSDLHTMLPublish) to new Web Service applications. This enables your application to publish WSDL documents that describe your Web Service to clients. For information on the WSDL publisher, see Generating WSDL Documents for a Web Service Application.

See Also