||Mohammed:

The JAX-WS support in CXF makes creating client proxy for your web
services quite straight-forward.   You can create the client dynamically
at run time without any elaborate setup.

This is done using pure JAX-WS code so it works with a number of
compliant runtimes:  CXF, Metro, JBossWS, etc. (though you do need set
up a META-INF/services ws provider hook to use JBossWS).

In any case, I suggest you stick with the CXF runtime, but use it
through GroovyWS "client" jar.    http://groovy.codehaus.org/GroovyWS

Download the "client" WS jar, the second (obscure) "here" link under
"Distributions".  Trust me.  Its Groovy, but it is a simplification,
even if you don't want to run Groovy.  This jar is a convenient
packaging of CXF's client support.  But note, you can run Groovy which,
as you can see, is a simple client.. 

To run Grooby, you will need the Groovy jar as well in your classpath.
   All you need to do for Groovy is to modify the sample Groovy client
code putting in the URL string that fetches your service's WSDL.

Make sure the GroovyWS jar appears early in the runtime classpath, ahead
of the JRE runtime jars.   If you fail to do this, the Sun JRE (for
instance) will try to use the Sun JAX-WS implementation, but this is not
included in the Sun JSE support.

Since you need a Java client (instead of Groovy), then you need a
slightly more complex setup.   There are 3 inputs (which may be hard
coded):  1) a URL (object) constructed  using the string that was used
in the Groovy client,, 2) a service name (as QName object) as it appears
in this WSDL and 3) a port name (another QName object) port within the
service definition, again in conformance with the WSDL.   Then you
construct a proxy for the web service, where the proxy implements your
Service Endpoint Interface (interface class for the service).   This
proxy is your client.   the code is something like this (illustrated
here as JUnit set up).   Fairly straight-forward.   The WSDL is
interpreted as runt time.

-----------------------------------------------------------------------------------------------------------------------------
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import junit.framework.TestCase;
import my.services.Worker;

import org.junit.Before;
import org.junit.Test;


public class TestGWSonJAX extends TestCase {
   
    private Worker worker;
   
    @Before
    public void setUp() throws Exception {
        URL url = new URL("http://127.0.0.1:8080/gws/WorkerImpl?wsdl";);
        QName serviceName = new
QName("http://services.my/","WorkerService";);
        QName portName = new QName("http://services.my/","WorkerImplPort";);
        Service service = Service.create(url,serviceName);
        worker = service.getPort(portName,Worker.class);
    }
   
    @Test
    public void testBasic( ) throws Exception {
        assertNotNull(worker);
        String result = worker.doWork();
        assertNotNull(result);
    }

}
-------------------------------------------------------------------------------------------------------
       -- Dan Connelly

Mohammad Shamsi wrote:
> hi,
>
> i want to use some JAX WS in a Java EE application.
>
> the web service has been developed. and i just have to write client to use
> this services.
>
> some of web services are Servlet Base and others are EJB based.
>
> question : can i use CXF for developing web service client for this project
> ?
>
>   

Reply via email to