1 Reply Latest reply on Oct 13, 2010 2:25 AM by Richard Opalka


    Steve Jagels Newbie

      I'm trying to have a web service store info to a session that is unique for each consumer.


      private WebServiceContext wsContext;


      public Integer MyMethod(){


         MessageContext mc = wsContext.getMessageContext();
         HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
         Integer count = (Integer) session.getAttribute("count");
         if(null == count){
            count = 0;
            System.out.println("new session id=" + session.getId());
         session.setAttribute("count", count);
         return count;


      The count is supposed to be incremented each time I go through this method, but it does not.


      Is there something I need to add to the consumer code for this?  Any other ideas?


      I'm using Eclipse 3.4.2, jboss 4.2.3.GA, jdk 1.5.0_17.

        • 1. Re: WebServiceContext
          Richard Opalka Master

          Yes, your webservice clients have to be configured to handler sessions properly.

          Here's the sample code:


          QName serviceName = new QName(targetNS, "ServiceName");
          wsdlURL = new URL(wsdlURLString)Service service = Service.create(wsdlURL, serviceName);
          HelloWorldIface proxy = (HelloWorldIface)service.getPort(HelloWorldIface.class);
          ((BindingProvider)proxy).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
          proxy.invokeSomeMethod(); // this will handle/propagate sessions properly