Version 2

    Web component clients


    The service client programming model for web components is about how to access a remote web service from any kind of web component (i.e. servlets, jsp pages). The web service client is deployed as a standard war archive plus additional <service-ref> elements in the web.xml deployment descriptor.


    Service Endpoint Interface


    The SEI declares the methods through which to access the remote web service.

    We use the same service endpoint interface as for the EJB service endpoint.


    Web Service Description Language


    Any web service client must have access to the wsdl that describes the remote webservice. The wsdl can be part of

    the web deployment or may be obtained at runtime before the servlet accesses the remote web service.


    JAX-RPC Mapping Files


    The web service client must have access to the same mapping information as described for the

    EJB service endpoint or the Java service endpoint. The jaxrpc mapping file must be

    part of the deployment, it cannot be obtained at runtime.


    Packaging the web service client


    The standard deployment descriptor for web components web.xml, declares the service reference.


      <web-app xmlns="" version="2.4"


    Service Interface


    It is possible to provide a typed service interface to web service clients that extends the standard

    javax.xml.rpc.Service interface. In this way the client looks up a service from JNDI that already

    has application specific semantics.


       public interface OrganizationEndpointService extends javax.xml.rpc.Service
          public OrganizationEndpoint getOrganizationPort() throws javax.xml.rpc.ServiceException;


    Deploy the Web Service client to JBoss


    This follows the normal deployment procedure for web components in JBoss. There are no web service specific info



    Accessing the remote web service


    Here is a simple example, that shows how a servlet does a lookup of the service interface, then obtains the

    desired port, and finally invokes getContactInfo on the service endpoint interface.


    public class OrganizationClientServlet extends HttpServlet
          // provide logging
          private static final Logger log = Logger.getLogger(OrganizationClientServlet.class);
          protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
             String organization = req.getParameter("organization");
             String info = getContactInfoJSE(organization);
             PrintWriter out = res.getWriter();
          /** Get the contact info from the JSE service */
          public String getContactInfoJSE(String organization) throws ServletException
                InitialContext iniCtx = new InitialContext();
                OrganizationEndpointService service = (OrganizationEndpointService)iniCtx.lookup("java:comp/env/service/OrganizationServiceJSE");
                OrganizationEndpoint endpoint = service.getOrganizationPort();
                String info = endpoint.getContactInfo(organization);
                return info;
             catch (NamingException e)
                throw new ServletException(e);
             catch (Exception e)
                throw new ServletException("Cannot invoke webservice", e);