LibraryLink ToToggle FramesPrintFeedback

Working with Dispatch Objects

To use a Dispatch object to invoke a remote service the following sequence should be followed:

  1. Create a Dispatch object.

  2. Construct a request message.

  3. Call the proper invoke() method.

  4. Parse the response message.

To create a Dispatch object do the following:

Example 19.2 shows the code for creating a Dispatch object that works with DOMSource objects in payload mode.


When working with Dispatch objects, requests must be built from scratch. The developer is responsible for ensuring that the messages passed to a Dispatch object match a request that the targeted service provider can process. This requires precise knowledge about the messages used by the service provider and what, if any, header information it requires.

This information can be provided by a WSDL document or an XML Schema document that defines the messages. While service providers vary greatly there are a few guidelines to be followed:

For more information about how services use XML messages see, the WS-I Basic Profile.

For consumers that make synchronous invocations that generate a response, use the Dispatch object's invoke() method shown in Example 19.3.


The type of both the response and the request passed to the invoke() method are determined when the Dispatch object is created. For example if you create a Dispatch object using createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE), both the response and the request are SOAPMessage objects.

[Note]Note

When using JAXB objects, both the response and the request can be of any type the provided JAXBContext object can marshal and unmarshal. Also, the response and the request can be different JAXB objects.

Example 19.4 shows code for making a synchronous invocation on a remote service using a DOMSource object.


Dispatch objects also support asynchronous invocations. As with the higher level asynchronous APIs discussed in Developing Asynchronous Applications, Dispatch objects can use both the polling approach and the callback approach.

When using the polling approach, the invokeAsync() method returns a Response<t> object that can be polled to see if the response has arrived. Example 19.5 shows the signature of the method used to make an asynchronous invocation using the polling approach.


For detailed information on using the polling approach for asynchronous invocations see Implementing an Asynchronous Client with the Polling Approach.

When using the callback approach, the invokeAsync() method takes an AsyncHandler implementation that processes the response when it is returned. Example 19.6 shows the signature of the method used to make an asynchronous invocation using the callback approach.


For detailed information on using the callback approach for asynchronous invocations see Implementing an Asynchronous Client with the Callback Approach.

[Note]Note

As with the synchronous invoke() method, the type of the response and the type of the request are determined when you create the Dispatch object.

When a request does not generate a response, make remote invocations using the Dispatch object's invokeOneWay(). Example 19.7 shows the signature for this method.


The type of object used to package the request is determined when the Dispatch object is created. For example if the Dispatch object is created using createDispatch(portName, DOMSource.class, Service.Mode.PAYLOAD), then the request is packaged into a DOMSource object.

[Note]Note

When using JAXB objects, the response and the request can be of any type the provided JAXBContext object can marshal and unmarshal.

Example 19.8 shows code for making a oneway invocation on a remote service using a JAXB object.