0 Replies Latest reply on Nov 10, 2010 4:35 AM by Patrik Jetzer

    Dynamic webservice call with dispatch client using reliable messaging example

    Patrik Jetzer Newbie

      I'm having difficulties to find examples about adding reliable messaging functionality to the webservice client code.

      The Dispatch Client is used to dynamically calling the webservice(s)

       

      This is the way the webservice is called tried to access an example reliable messaging enabled webservice deployed on localhost:

       

      import javax.xml.namespace.QName;
      import javax.xml.soap.MessageFactory;
      import javax.xml.soap.SOAPBody;
      import javax.xml.soap.SOAPBodyElement;
      import javax.xml.soap.SOAPElement;
      import javax.xml.soap.SOAPHeader;
      import javax.xml.soap.SOAPMessage;
      import javax.xml.ws.BindingProvider;
      import javax.xml.ws.Dispatch;
      import javax.xml.ws.Service;
      import javax.xml.ws.WebServiceException;
      import javax.xml.ws.soap.SOAPBinding;

      // -------------

       

      public void sendRM() {
              // String wsdlLocationString = "http://localhost:8080/SimpleWS/SimpleService?wsdl";
              String namespace = "http://ws.example.com/";
              String serviceName = "SimpleService";
              String portName = "SimpleServicePort";
              String methodName = "echoRequest";

       

              try {
                  // Qnames for service as defined in wsdl.
                  QName serviceQName = new QName(namespace, serviceName);

       

                  // QName for Port As defined in wsdl.
                  QName portQName = new QName(namespace, portName);

       

                  // Endpoint Address
                  String endpointAddress = "http://localhost:8080/SimpleWS/SimpleService";

       

                  // Create a dynamic Service instance
                  Service service = Service.create(serviceQName);

       

                  // Add a port to the Service
                  service.addPort(portQName, SOAPBinding.SOAP11HTTP_BINDING,
                          endpointAddress);

       

                  // Create a dispatch instance
                  Dispatch<SOAPMessage> dispatch = service.createDispatch(portQName,
                          SOAPMessage.class, Service.Mode.MESSAGE);

       

                  // Use Dispatch as BindingProvider
                  BindingProvider bp = (BindingProvider) dispatch;

       

                  // Optionally Configure RequestContext to send SOAPAction HTTP Header
                  Map<String, Object> rc = bp.getRequestContext();
                  rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
                  rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, methodName);

       

                  // Obtain a preconfigured SAAJ MessageFactory
                  MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();

       

                  // Create SOAPMessage Request
                  SOAPMessage request = factory.createMessage();

       

                  // Request Header
                  SOAPHeader header = request.getSOAPHeader();

       

                  // Request Body
                  SOAPBody body = request.getSOAPBody();

       

                  // Compose the soap:Body payload
                  QName payloadName = new QName(namespace, methodName, "ns1");

                  SOAPBodyElement payload = body.addBodyElement(payloadName);

                  SOAPElement message = payload.addChildElement("input");

                  message.addTextNode("dummyHelloWorld");

       

                  // Invoke the endpoint synchronously
                  SOAPMessage reply = null;

       

                  try {
                      // Invoke Endpoint Operation and read response
                      reply = dispatch.invoke(request);
                      ((Closeable) dispatch).close();
                  } catch (WebServiceException wse) {
                      wse.printStackTrace();
                  }

             } catch (Exception e) {

                  e.printStackTrace();
              }
        }

       

      The dump of the soap messages show me that the reliable messaging messages are not produced.

      when .invoke() method is called a

      "javax.xml.ws.soap.SOAPFaultException: A required header representing a Message Addressing Property is not present"

      is produced.

       

      Env Setting:

      JBossAS 4.2.2 JRE 1.6.0_20

      Webservice stack jbossws-metro-3.0.5.GA

       

      Does anybody have an example of dynamically calling a webservice with reliable messaging enabled?

      Is there a link i have missed with one of my google searches?

      Is there another approach i can use instead of using client Dispatch class?

      I have to use the dynamical approach because i can't use the generated client artefacts produced by wsconsume/ wsimport,

      since at design time it is not defined what services will be used to callback.

       

      any help is welcomed