3 Replies Latest reply on Jun 21, 2006 11:37 AM by acxjbertr

    How to acess Web service with complex parameters without ser

    tnfink

      Hi,

      maybe this is a silly question, but nevertheless:

      The question in the short version:

      If I want to access a Web service with a complex signature I need the jaxrpc-mapping file. If I do not use service-reference, how can I configure my code to use the jaxrpc-mapping?

      Now the longer version:

      If I try to access a Web service without using a service-reference, it will look more or less like this:

       String urlstr = "http://localhost:8080/testpurchaseservice?wsdl";
       URL url = new URL(urlstr);
       QName qname = new QName(
       "http://de.akquinet.fws.jboss.webservices.pojo/purchasews/rpcstyle",
       "PurchaseService");
       ServiceFactory factory = ServiceFactory.newInstance();
       Service service = factory.createService(url, qname);
       PurchaseServiceSEI purchaseService = (PurchaseServiceSEI) service
       .getPort(PurchaseServiceSEI.class);
      


      If the signature of my SEI is more complex, e.g. contains this method

       PurchaseResult purchase(Customer customer, Product product) throws RemoteException;
      


      I need to map the XML parts to Java objects.

      This mapping is declared in the jaxrpc-mapping.xml file.
      But I do not specify this file in the code above, nor do I see a possibility to do this.

      I thought about using the type mapping registry. But this seems to complicated, expecially if I already have a jaxrpc-mapping.xml.

      Can anybody give me a hint to the right way of doing this?
      (I know that I can specify the mapping file in the service-ref.)

      Best regards,

      Torsten Fink

        • 1. Re: How to acess Web service with complex parameters without
          acxjbertr

          If your jaxrpc-mapping document is in your classpath then you can just do a getResource() on it and then pass it into the createService() method (since it is overloaded). Here is an example:

          URL wsdlLocation = new URL("http://localhost:8080/testpurchaseservice?wsdl");
          URL mappingLocation = cl.getResource("jaxrpc-mapping.xml");
          QName serviceName = new QName("http://de.akquinet.fws.jboss.webservices.pojo/purchasews/rpcstyle", "PurchaseService");
          ServiceImpl service = (ServiceImpl) factory.createService(wsdlLocation, serviceName, mappingLocation);


          • 2. Re: How to acess Web service with complex parameters without
            acxjbertr

            Oops. I forgot to include a couple of lines in the example. Try this:

            ServiceFactoryImpl factory = new ServiceFactoryImpl();
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            URL wsdlLocation = new URL("http://localhost:8080/testpurchaseservice?wsdl");
            URL mappingLocation = cl.getResource("jaxrpc-mapping.xml");
            QName serviceName = new QName("http://de.akquinet.fws.jboss.webservices.pojo/purchasews/rpcstyle", "PurchaseService");
            ServiceImpl service = (ServiceImpl) factory.createService(wsdlLocation, serviceName, mappingLocation);

            Also, you will need these imports as the Service from javax.xml.rpc does not have the right, overloaded method.
            import org.jboss.ws.jaxrpc.ServiceFactoryImpl;
            import org.jboss.ws.jaxrpc.ServiceImpl;


            • 3. Re: How to acess Web service with complex parameters without
              acxjbertr

              PS - This is mentioned in the JBossWS User Guide (http://labs.jboss.com/portal/jbossws/user-guide/en/html/clients.html) in section 5.2 ("Dynamic Invocation Interface").