1 Reply Latest reply on Jun 15, 2005 4:49 AM by thomas.diesler

    Created Session Bean as Web Service, Passing SOAP message

    stevechang

      Hi,

      I have created a stateless session bean and published as Web Service, this web service has one hello method, it expects the SOAP message coming from the client. When I use the client program to test, the hello got invoked
      and return the "Hello World" to the client as expected, but the Session Bean did not get the SOAP message correctly, it shows the null value. Can someone advise how to implement this ?

      1. Session Bean code

      public String hello(SOAPElement doc) throws RemoteException, SOAPException {

      System.out.println("---- Client request the service ---");
      return "Hello World";
      }


      2. Client code

      JAXBContext jc = JAXBContext.newInstance( Ratelock.class.getPackage().getName() );
      Marshaller m = jc.createMarshaller();
      ObjectFactory objfactory = new ObjectFactory();

      m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
      Ratelock rateLock =objfactory.createRatelock();
      USAddress address=objfactory.createUSAddress();
      address.setCity("Miami");
      address.setState("FL");
      address.setZip(new BigDecimal(12345));
      rateLock.setAddress(address);

      SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
      SOAPConnection connection = soapConnectionFactory.createConnection();
      SOAPFactory soapFactory = SOAPFactory.newInstance();

      MessageFactory factory = MessageFactory.newInstance();
      SOAPMessage message = factory.createMessage();

      SOAPHeader header = message.getSOAPHeader();
      SOAPBody body = message.getSOAPBody();
      header.detachNode();

      Name bodyName = soapFactory.createName("hello", "", "http://localhost:8080/Residentialws-ejb/RateLockEndpoint");
      SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      DocumentBuilder docBuilder = dbf.newDocumentBuilder();
      Document doc=docBuilder.newDocument();

      m.marshal( rateLock, doc );
      body.addDocument(doc);

      System.out.println("\n ------ Request message ---\n");
      message.writeTo(System.out);

      URL endpoint = new URL("http://localhost:8080/Residentialws-ejb/RateLockEndpoint");
      SOAPMessage response = connection.call(message, endpoint);

      connection.close();

      SOAPBody soapBody = response.getSOAPBody();

      System.out.println("\n\nReceived reply from: " +
      endpoint);
      System.out.println("\n---- Reply Message ----\n");
      response.writeTo(System.out);