October 25, 2016
Hot Topics:

Accelerate Your Java Web Service Development with XFire

  • July 5, 2007
  • By Dominic Da Silva
  • Send Email »
  • More Articles »

Coding the StockQuote Web Service Client

You create a Java class file called XFireClientTest in the 'src' directory. The 'src' directory should now look like this:

Figure 3:XFireClientTest Java class

Fill in the XFireClientTest.java file with the following Java code:

import net.xmethods.services.stockquote.StockQuoteClient;
import net.xmethods.services.stockquote.StockQuoteSoap;

public class XFireClientTest
   public static void main(String[] args) {
      StockQuoteClient client = new StockQuoteClient();
      StockQuoteSoap service = client.getStockQuoteSoap();
      String quote = service.getQuote("HOT");

Your client gets the client proxy for the StockQuote service. It then uses it to get the StockQuote service and call the 'getQuote()' service method, passing in the company symbol of 'HOT'. It then prints out the result to the console. That is all there is for you to code; XFire has generated all the other marshalling code that will convert your input parameter into a SOAP request.

Compiling the XFireDemo Project

Now that you have your Stock Quote web service client, you can go ahead and compile your project using Ant. Running 'ant build.xml' produces the following output, indicating that it compiled your source code and created your XFireClientTest and supporting class files in the 'bin' directory:

Buildfile: C:Documents and SettingsdominicworkspaceXFireDemo
   [delete] Deleting 8 files from C:Documents and Settingsdominic
   [wsgen] Jun 30, 2007 5:02:46 PM
           org.codehaus.xfire.gen.Wsdl11Generator generate
   [wsgen] INFO: Generating code for WSDL at
           http://www.webservicex.net/stockquote.asmx?WSDL with a
           base URI of http://www.webservicex.net/stockquote.asmx?WSDL
   [wsgen] Jun 30, 2007 5:02:51 PM
   [wsgen] INFO: Creating class
   [wsgen] Jun 30, 2007 5:02:51 PM
   [wsgen] INFO: Creating class
   [wsgen] netwebservicexGetQuote.java
   [wsgen] netwebservicexGetQuoteResponse.java
   [wsgen] netwebservicexObjectFactory.java
   [wsgen] netwebservicexpackage-info.java
   [wsgen] netxmethodsservicesstockquoteStockQuoteClient.java
   [wsgen] netxmethodsservicesstockquoteStockQuoteImpl.java
   [wsgen] netxmethodsservicesstockquoteStockQuoteSoap.java
   [javac] Compiling 8 source files to C:Documents and Settings
   [javac] Note: C:Documents and Settingsdominicworkspace
           StockQuoteClient.java uses unchecked or unsafe operations.
   [javac] Note: Recompile with -Xlint:unchecked for details.
Total time: 14 seconds

Running the StockQuote Service SOAP Client Test

You can run your client directly from Eclipse by right-clicking the XFireClientTest class and selecting 'Run As->Java Application':

Click here for a larger image.

Figure 4:Running XFireClientTest in Eclipse

When you run the SOAP client test class, XFireClientTest, using a company symbol of 'HOT' (Starwood Hotels and Resorts), you will get the following response from the Stock Quote web service, indicating a successful test:

      <AnnRange>49.68 - 74.35</AnnRange>
      <Name>STARWOOD HOTELS&R</Name>


This article took a look at XFire, a Java SOAP framework that makes working with web services fast and simple. You created a SOAP client and saw how easy it is to use XFire. In the next article in this XFire series, you will create your own SOAP web service using XFire.


About the Author

Dominic Da Silva (http://www.dominicdasilva.com/) is the President of SilvaSoft, Inc., a software consulting company specializing in Java- and Ruby-based web and web services development. He has worked with Java since the year 2000 and is a Linux user from the 1.0 days. He is also Sun Certified for the Java 2 platform. Born on the beautiful Caribbean island of Trinidad and Tobago, he now makes his home in sunny Orlando, Florida.

Page 3 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel