XFireHome DocumentationJavadocs QuicklinksAegis Binding DevelopersDeveloper Space |
This guide leads you through the steps of creating a client for a service. The full example can be found in "examples/geoip-client" in the distribution. Note this is Java 5.0 only at this point since it takes advantage of the JSR 181 annotations and JAXB 2.0 The service we're goign to use takes an IP address then supplies us with a country name. Generating a client is relatively easy. Here is an example build file runs the WSGen task from XFire: <goal name="generate-jaxb-client"> <!-- Setup WSGen classpath and taskdef --> <ant:path id="wsgen.path"> <ant:path refid="maven.dependency.classpath"/> <ant:pathelement path="${maven.build.dest}"/> <ant:pathelement path="${maven.test.dest}"/> <ant:pathelement path="${maven.build.dir}/client-xmlbeans"/> </ant:path> <ant:taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="wsgen.path"/> <!-- Run the client generator --> <wsgen outputDirectory="${maven.build.dir}/client" wsdl="${basedir}/src/wsdl/geoip.wsdl" package="net.webservicex.geoip.jaxb"/> <!-- Add the client directory to the list of directories to compile --> <ant:path id="services" location="${maven.build.dir}/client"/> <maven:addPath id="maven.compile.src.set" refid="services"/> </goal> Now using the client is relatively simple: package net.webservicex.geoip; import net.webservicex.GetGeoIP; import net.webservicex.geoip.jaxb.GeoIPServiceClient; import net.webservicex.geoip.jaxb.GeoIPServiceSoap; import junit.framework.TestCase; public class GeoIPClientTest extends TestCase { public void testClient() throws Exception { GeoIPServiceClient service = new GeoIPServiceClient(); GeoIPServiceSoap geoIPClient = service.getGeoIPServiceSoap(); System.out.println("The country is: " + geoIPClient.GetGeoIP("216.73.126.120").getCountryName()); } } XMLBeans ClientYou can also use XMLBeans as the binding instead of JAXB 2.0. Simply set the binding paramter on the task: <wsgen outputDirectory="target/services" wsdl="${basedir}/src/wsdl/echoW.wsdl" package="com.acme.echo" binding="xmlbeans"/> LimitationsThere are a couple limitations on the client generator.
|