Version 2

    Dynamic Invocation Interface - DII

     

    If the recommended J2EE Application Client methodology cannot be used by your application, there is a less portable alternative available. Instead of looking up a preconfigured javax.xml.rpc.Service object from JNDI, a client can use the dynamic invocation interface (DII) to connect to a remote web service.

     

       private final String WSDL_LOCATION = "http://localhost:8080/ws4ee/services/HelloWsService?wsdl";
       private String NAMESPACE = "http://test.jboss.org/ws4eesimple";
       private final QName SERVICE_NAME = new QName(NAMESPACE, "HelloWsService");
    
       public void testSayHello() throws Exception
       {
          ServiceFactory serviceFactory = ServiceFactory.newInstance();
          Service service = serviceFactory.createService(new URL(WSDL_LOCATION), SERVICE_NAME);
          Call call = (Call) service.createCall(new QName(NAMESPACE, "HelloPortComponent"), "sayHello");
          String retstr = (String) call.invoke(new Object[]{"Hello"});
          assertEquals("'Hello' to you too!", retstr);
       }
    

     

    Note, in the example above we use a plain JAXRPC javax.xml.rpc.ServiceFactory which has no notion of WS4EE deployment artifacts like jaxrpc-mapping.xml.

    As a result mapping meta data is missing and some complex types may not have

    serializers/deserializers associated with them.

     

     

    We provide a proprietary createService method in org.jboss.webservice.client.ServiceFactoryImpl that can take the additional ws4ee descriptors.

     

       /**
        * Create a Service instance.
        *
        * Note, this method is not in the {@link ServiceFactory} interface, it provides the service
        * with additional ws4ee wsdl/java mapping information
        *
        * @param wsdlLocation    URL for the WSDL document location
        * @param jaxrpcLocation  An optional URL for the jaxrpc-mapping.xml location
        * @param ws4eeLocation   An optional URL for the ws4ee-deployment.xml location
        * @param serviceName     QName for the service.
        * @param portName        An optional port name
        * @return Service.
        * @throws ServiceException If any error in creation of the
        *                          specified service
        */
       public Service createService(URL wsdlLocation, URL mappingLocation, URL ws4eeMetaData, QName serviceName, String portName) throws ServiceException
    

     

    Applying this to the example above, the code would change to

     

       public void testSayHello() throws Exception
       {
          ServiceFactoryImpl serviceFactory = (ServiceFactoryImpl)ServiceFactory.newInstance();
          Service service = serviceFactory.createService(wsdlURL, jaxrpcURL, ws4eeURL, SERVICE_NAME, null);
          Call call = (Call) service.createCall(new QName(NAMESPACE, "HelloPortComponent"), "sayHello");
          String retstr = (String) call.invoke(new Object[]{"Hello"});
          assertEquals("'Hello' to you too!", retstr);
       }