3 Replies Latest reply on Sep 7, 2006 3:42 AM by dirkschmitz

    Newbie question: Just a first webservice client

    nautilusiii

      Hi!

      I have developed my very first webservice with JSR181:

      /**
       * SimpleWebServiceImpl.java
       *
       * This file was auto-generated from WSDL
       * by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
       */
      
      package ws;
      
      import javax.jws.WebMethod;
      import javax.jws.WebService;
      import javax.jws.soap.SOAPBinding;
      
      @WebService
      @SOAPBinding(style = SOAPBinding.Style.RPC)
      public class SimpleWebService
      {
       @WebMethod
       public int add(int a, int b)
       {
       return a+b;
       }
      
       @WebMethod
       public int sub(int a, int b)
       {
       return a-b;
       }
      
       @WebMethod
       public int mul(int a, int b)
       {
       return a*b;
       }
      
       @WebMethod
       public double div(int a, int b)
       {
       return a/b;
       }
      }
      


      The webservice is deployed and I can fetch the wsdl via specifying the appropriate URL in the browser.

      http://localhost:8080/ws2/webservices/SimpleWebService?wsdl
      


      But I cannot manage it to develop a simple standalone client...

      I tried this here:

      package ws;
      
      import javax.xml.ws.WebServiceRef;
      
      public class SimpleWebServiceClient
      {
       @WebServiceRef(wsdlLocation = "http://localhost:8080/ws2/webservices/SimpleWebService?wsdl")
       static SimpleWebService service;
      
       public static void main(String[] args)
       {
       System.out.println(service.add(2,3));
       }
      }
      


      I doing all these from within Eclipse with Lomboz...
      I referenced the project containg the service from within my client project and just executed the client from within Eclipse...

      But I always get a NullPtrExc because the variable service is always null in

      System.out.println(service.add(2,3));
      


      What am I doing wrong?

        • 1. Re: Newbie question: Just a first webservice client
          thomas.diesler

          http://jira.jboss.org/jira/browse/JBWS-1156

          Note, it is scheduled for jbossws-2.0

          Have a look how the clients in the sample download do it.

          • 2. Re: Newbie question: Just a first webservice client
            dirkschmitz

            Hi!

            i have a similar problem with my webservice test client using the dynamic invocation interface (DII). When I try to run the client within Eclipse I get the following Exception

            Exception in thread "main" javax.xml.rpc.ServiceException: Provider com.sun.xml.rpc.client.ServiceFactoryImpl not found
            at javax.xml.rpc.FactoryFinder.newInstance(FactoryFinder.java:44)
            at javax.xml.rpc.FactoryFinder.find(FactoryFinder.java:137)
            at javax.xml.rpc.ServiceFactory.newInstance(ServiceFactory.java:58)
            at de.mtag.ws.samples.client.WebServiceClient.main(WebServiceClient.java:29)

            The classpath of the webservice testclient contains the following JBoss-Client-Jars

            activation.jar
            commons-logging.jar
            javaassist.jar
            jbossall-client.jar
            jbossws-client.jar
            log4j.jar
            mail.jar



            Web Service Test Client

            public class WebServiceClient {
            
             /**
             * @param args
             */
             public static void main(String[] args) throws Exception
             {
             String urlstr = args[0];
             String argument = args[1];
            
             System.out.println("Contacting webservice at " + urlstr);
            
             URL url = new URL(urlstr);
            
             String ns = "http://xx.xxx.ws.samples.services/simple";
             QName qname = new QName(ns, "SimpleWS");
             QName port = new QName(ns, "SimpleService");
             QName operation = new QName(ns, "echo");
            
             ServiceFactory factory = ServiceFactory.newInstance();
             Service service = factory.createService(url, qname);
             Call call = service.createCall(port, operation);
            
             System.out.println("SimpleService.echo(" + argument + ")");
             System.out.println("output:" + call.invoke(new Object[] {argument}));
            
             }
            
            }
            


            Service Endpoint Interface

            public interface SimpleService {
            
             public String echo(String echo);
            
            }
            


            Service Endpoint Implementation

            @WebService(
             name = "SimpleWS",
             targetNamespace = "http://xx.xxx.ws.samples.services/simple",
             serviceName = "SimpleWS"
             )
            @SOAPBinding(style = SOAPBinding.Style.RPC)
            public class SimpleEndpoint implements SimpleService {
            
             @WebMethod
             public String echo(String theEcho) {
             return theEcho;
             }
            
            }
            


            • 3. Re: Newbie question: Just a first webservice client
              dirkschmitz

              Hi all,

              i found out what the problem was. You have to set the following jars of the Java Webservice Development Pack into the classpath.

              jaxrpc-impl.jar
              saaj-impl.jar
              FastInfoset.jar

              Then it works!