For consumers that make synchronous invocations that generate a response, you use the
Dispatch
object's invoke()
method shown bellow.
T invoke(T msg) throws WebServiceException;
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 created a
Dispatch
object using createDispatch(portName, SOAPMessage.class,
Service.Mode.MESSAGE)
the response and the request would both be
SOAPMessage
objects.
Note: When using JAXB objects, 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. The code below makes a synchronous invocation on a remote service using a
DOMSource
object.
// Creating a DOMSource Object for the request
DocumentBuilder db = DocumentBuilderFactory.newDocumentBuilder();
Document requestDoc = db.newDocument();
Element root = requestDoc.createElementNS(
"http://org.apache.cxf/stockExample", "getStockPrice");
root.setNodeValue("DOW");
DOMSource request = new DOMSource(requestDoc);
// Dispatch disp created previously
DOMSource response = disp.invoke(request);