Java API for XML-Based Web Services (JAX-WS) provides support for the dynamic invocation of service endpoint operations.
JAX-WS provides a new dynamic Dispatch client API that is more generic and offers more flexibility than the existing Java API for XML-based RPC (JAX-RPC)-based Dynamic Invocation Interface (DII). The Dispatch client interface, javax.xml.ws.Dispatch, is an XML messaging oriented client that is intended for advanced XML developers who prefer to work at the XML level using XML constructs. To write a Dispatch client, you must have expertise with the Dispatch client APIs, the supported object types, and knowledge of the message representations for the associated Web Services Description Language (WSDL) file.
The Dispatch API can send data in either PAYLOAD or MESSAGE mode. When using the PAYLOAD mode, the Dispatch client is only responsible for providing the contents of the <soap:Body> and JAX-WS includes the input payload in a <soap:Envelope> element. When using the MESSAGE mode, the Dispatch client is responsible for providing the entire SOAP envelope.
String endpointUrl = ...; QName serviceName = new QName("http://com/ibm/was/wssample/echo/", "EchoService"); QName portName = new QName("http://com/ibm/was/wssample/echo/", "EchoServicePort"); /** Create a service and add at least one port to it. **/ Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointUrl); /** Create a Dispatch instance from a service.**/ Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE); /** Create SOAPMessage request. **/ // compose a request message MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); // Create a message. This example works with the SOAPPART. SOAPMessage request = mf.createMessage(); SOAPPart part = request.getSOAPPart(); // Obtain the SOAPEnvelope and header and body elements. SOAPEnvelope env = part.getEnvelope(); SOAPHeader header = env.getHeader(); SOAPBody body = env.getBody(); // Construct the message payload. SOAPElement operation = body.addChildElement("invoke", "ns1", "http://com/ibm/was/wssample/echo/"); SOAPElement value = operation.addChildElement("arg0"); value.addTextNode("ping"); request.saveChanges(); /** Invoke the service endpoint. **/ SOAPMessage response = dispatch.invoke(request); /** Process the response. **/
In this information ...Related tasks
Related reference
| IBM Redbooks, demos, education, and more(Index) |