Popular Posts

Saturday, March 15, 2008

Invoking a public web service programmatically using WSO2 WSAS

A Web service is defined as "a software system designed to support interoperable interaction over a network." Web services are referred to as Web APIs that can be accessed over a network and executed on a remote system hosting the requested services.
There are many publicly available web services which can be invoked remotely using client applications. www.webservicex.net is such a site that hosts different types of public web services.
I'm going to demonstrate how such web service is invoked programmaticaly using WSO2 Web services application server (WSO2 WSAS)

WSo2 Web services application server provides set of tools to interact with web services. You can download the latest version from here.

I'll use a public instance of WSO2 WSAS to generate client side code (stub). You will also try out WSAS public instance before downloading the server.

Step 1

First, we may access webservicex to identify a suitable web service which can be invoked remotely.
You may see 'Top Web Services' at the left menu of the home page. Click on 'Stock Quote'
You will get a page with stock quote service details.

Make a note of the followings;
Endpoint http://www.webservicex.net/stockquote.asmx
WSDL Location http://www.webservicex.net/stockquote.asmx?wsdl

Step 2

WSO2 provides a set of shared instances of WSO2 Web services application server at http://wso2.org/tools. You can easily try out several features of web services application server with these instances.

Go to WSAS 2.2 shared instances page and select 'shared WSO2 WSAS Instance 1'. You will be directed to the home page of WSAS management console. Select WSDL2Code from the left navigation menu.
You will see the following page.



Enter 'http://www.webservicex.net/stockquote.asmx?wsdl' as the uri of WSDL. We need to generate a client to invoke the stock quote service. Therefore, you don't want to configure server side settings. Simply click on 'generate' leaving the other fields blank.

Within a few seconds, you will be prompted to save a zip file in your file system. Save it in your machine.

Step 3

Go to the directory where you saved the generated zip file. You will see src directory, pom.xml and build.xml file inside the zip file. src directory contains the StockQuoteStub and StockQuoteCallbackHandler classes which can be considered as proxies used in our client.

Now open a command window and go to the extracted directory where the above pom.xml exists.
Assuming you are using Eclipse as IDE, enter mvn eclipse:eclipse to generate the complete project structure which can be imported in to your IDE. (If Intellij IDEA is used, then use mvn idea:idea)

Depending on your network connection and the contents available in your maven2 repository, the above command takes some time to download the necessary jars to your m2 repo.

If everything is successful, you will see 'BUILD SUCCESSFUL' message.

Step 4

Open eclipse IDE. Select File-->Import.
Select 'Existing projects in to workspace'. In the 'Import Projects' window, browse for the root directory of the above location (where you extracted the generated zip file)
Select the project and click next

The complete project structure will be created with the generated artifacts. You may need to define M2_REPO classpath variable if you have not done it previously.

Step 5

Now use the generated stubs to create a java client under the above project to consume Stock Quote service.

public class StockQuoteClient {

public static void main(String[] args)throws AxisFault {
StockQuoteStub stub = new StockQuoteStub("http://www.webservicex.net/stockquote.asmx");
StockQuoteStub.GetQuote req = new StockQuoteStub.GetQuote();
req.setSymbol("IBM");
try {
StockQuoteStub.GetQuoteResponse response = stub.GetQuote(req);
System.out.println(response.getGetQuoteResult());
} catch (RemoteException e) {
e.printStackTrace();
}

}

}

Run the application. You will get the stock quote for IBM.


19 comments:

Techno Cupid said...

Good one dude..!

Iñaki said...

good, it served for a web service. How ever i did not success invoking a bpel: org.apache.axis2.databinding.ADBException: Unexpected subelement return

do you know why?

Charitha said...

Hi,
What is the BPEL you were trying? Please send me the SOAP message transmitted (You can send the messages through TCPMON and capture them).
Also, It will be better to submit your question in http://wso2.org/forum/886

Iñaki said...

Dear Charita,

in eclipse appears this error:org.apache.axis2.databinding.ADBException: Unexpected subelement return (it seems a data binding problem)

in WSO2 management Console-->soap tracer it appears ok. it works.


why Eclipse does not recognize the returning data?

Im also as inakibalzac user in http://wso2.org/forum/886: i will write my comments there

thanks in advance

crystal said...

Perfect!!You are a outstanding person!Have you ever wore chaussures puma,Here are the most popular puma CAT,Puma shoes store gives some preview of puma speed cat,and casual but no sweat puma basket.
http://www.pumafr.com/blog
http://poloshirtsonline.blogspot.com
http://thediary.org/mensclothing
http://blog.livedoor.jp/dokoma
http://www.itimes.com/my_blog.php

crystal said...

Thank you so much!!polo shirt men'ssweate,Burberry Polo Shirts lacoste sweater, ralph lauren Columbia Jackets,ski clothing. Free Shipping, PayPal Payment. Enjoy your shopping experience on mensclothingus.com.You can find the father who desire fashionable, intellectual mens clothing simultaneously.

crystal said...

God bless you!I really agree with your opinions.Also,there are some new fashion things here,gillette razor blades.gillette mach3 razor bladesfor men.As for ladies,gillette venus razor blades must the best gift for you in summer,gillette fusion blades are all the best choice for you.

crystal said...

Awesome!!!Best wishes for you !!cheap polo shirts is the father of the summer should be prepared to most commonly used item, it has both style and shape of Ralph Lauren Polo, and vest with a random function polo ralph lauren, so that in the short-sleeved apply to both on many occasions, the pink and black color men's polo shirts brought into effect, lightweight cotton, linen texture to demonstrate masculine temperament and sense of fashion exhaustively.

crystal said...

Fantastic!God bless you!Meanwhile,you can visit my China Wholesale,we have the highest quality but the lowest price fashion products wholesale from China.Here are the most popular China Wholesale productsfor all of you.You can visit http://chinaclothes.net.Also the polo clothing is a great choice for you.

srggy said...

The larger that the head size is for your babolat pure drive, the more power you will be provided with. Additionally, a larger wilson k six size means a larger sweet spot which is why beginners as well as intermediate players often prefer to work with a head microgel with a larger head size. Additionally, thicker frames are also capable of generating more power as well. Smaller head sizes on prince-o3-tour on the other hand are capable of providing less power, but significantly more control cheap tennis racquets.new polos men poloswomen polosdiscount polossummer polospolo shirts whosalepolo fashionembroodered polostennis racketsclothing poloclothingedhardyshirtedhardyclothingsummer ed hardy clothingcheap shirtsed hardy brand.

srggy said...

Although many people criticize ed hardy clothing for having nothing but tattoo patterns, being filled with waste and useless things, it is widely acknowledged that ed hardy clothes draws the most attention of both common young people as well as many Hollywood welcomed stars for its punk ed hardy t-shirts rock styles. As a matter of fact, in such a world where all ed hardy shirts are much like each other, ed hardy mens creates yet another totally new global sensation in fashion crowd for ed hardy womens fancy design. An increasing number of people are charmed by the magic of amazing tattoo and impressive color of ed hardy sunglasses.

srggy said...

In this version of the ralph lauren polo, the styling and fabric is advertised as being made out of "playdry" material. Burberry Polo Shirts is another performance fabric which is intended to add luxury Cheap polo shirts, coolness, and moisture wicking qualities. Performance fabrics wholesale polo shirtswere originally created primarily for athletes and other sports enthusiasts who work up a good sweat ralph lauren polo shirts. The moisture wicking fabric in cheap ralph lauren polos draws the moisture away from the body which then evaporates quickly discount ralph lauren polos. ralphlaurenpoloshirts keep the body cooler and drier even when the athlete is under physical duress polo clothing.

srggy said...

polo ralph lauren RED! Series of design criteria - stylish, simple, self-cultivation. For the first time in 2009 in New York Fashion Week debut, RED! Series has a new Polo Shirts On Sale series from the traditional burberry polos LOGO, LOGO traditional crocodile logo at the Ralph Lauren Polo Shirts letter above, and the new series of letters with the cheappolos logo in line to be between a red symbol of Burberry Polo Shirts.

lla said...

http://2009tennis.blogspot.com/
http://www.free-blog-site.com/tennis
http://o3.indiatimes.com/racquet/
http://cid-8c8a918b06ff68fd.spaces.live.com/?lc=2052
http://2009tennis.cocolog-nifty.com/
http://2009tennis.blog.drecom.jp/
http://2009tennis.blog.shinobi.jp/
http://www.actiblog.com/slary/
http://pshirts.blog126.fc2.com/
http://www.free-blog-site.com/shirts
http://nikepuma.blog.shinobi.jp/
http://hardy55.blog126.fc2.com/
http://cid-f80137f6d1a8020b.spaces.live.com/?lc=2052
http://www2.atword.jp/sdgdyhd/
http://kurumaro.com/hardy/
http://hardyclothes.jugem.jp/
http://www.actiblog.com/sfawagfra/
http://thediary.org/cheaphandbags/
http://ameblo.jp/kaowy/
http://sale.edublogs.org/
http://www2.atword.jp/jak/
http://09handbags.blog126.fc2.com/
http://sun15.cocolog-nifty.com/
http://ameblo.jp/ailsa15/
http://junior2tennis.blog.shinobi.jp/

lla said...

Burberry polo shirt the steady, solid, so many young girls also love it. Speaking of people of a ralph lauren polo, think it a sign of nobility elegant waving in the horse club.spyder jacket in the cold in your winter activities can be easily.columbia jacket it is expensive, but here you do not need to consider the price of it. the north face jacket one of my favorite money, I do not know how many in this world of its fans.
ed hardy clothing
ed hardy clothes
ed hardy shirts
ed hardy t-shirts
ed hardy sunglasses
ed hardy mens
ed hardy womens

lla said...

In preparation for the purchase of a tennis racquetbefore, we must consider your financial ability to bear; On this basis, a further comparison, as far as possible, choose your head tennis racquets. Now a lot of babolat pure drive and more mixed materials, the proportion of mixed-use to control the stiffness of the babolat aeropro drive and the shock-absorbing capacity, the more rigid babolat tennis racket, the swing more powerful force; but the relative resilience of the shock-absorbing capacity and wilson k factor performance of talks on the easier it is for the wrist and elbow injury.
Wholesale Handbags
Cheap Handbags
Womens Handbags
Cheap Purses
Designer Handbags

swimingfidh said...

http://sweetygirlbirdylove.blog126.fc2.com/
http://wholesale-from-china-susan.blogspot.com/
http://caihongbao.blog126.fc2.com/
http://alisasweetybabyb.blog.shinobi.jp/
http://kurumaro.com/alisasweetybaby/
http://yahoewholesales.blogspot.com/
http://susanyahoe.blog126.fc2.com/
susanyahoe.wordpress.com
suanyaheo.blogsome.com
http://sexywomenjeans.blogspot.com/
http://eliotkusith.blog126.fc2.com/
http://eliotsmart.edublogs.org/
http://blog.qlep.com/blog.php/eyecatchingjeans
http://uniquejeanscloset.blogspot.com/
http://andrewmirrerredjean.blog126.fc2.com/
http://d.hatena.ne.jp/uniquejeans/
http://blog.goo.ne.jp/uniquejeanslove/
http://www4.atword.jp/unequejeansfans/
http://johnwired123.blog126.fc2.com/
http://d.hatena.ne.jp/johnwired123/
http://ameblo.jp/johnwired123/
http://www.seriousblogging.com/johnwired123/
http://mybrandnewclothes123.blogspot.com/

swimingfidh said...

There are ed hardy shirts
,pretty ed hardy shirt for men,

ed hardy womens in the ed hardy online store

designed by ed hardy ,
many cheap ed hardy shirt ,glasses,caps,trouers ed hardy shirts on sale ,

You can go to edhardyshirts.com to have a look ,you may find one of ed hardy clothing fit for you
Top qualitymen's jacket,
These cheap jacket are on sale now,you can find
north face jackets inmage on our web
Ralph Lauren Polo Shirtsbuberry polo shirts

swimingfidh said...

Do you wannaghd hair straighteners for you own , we have many
cheap ghd hair straightenersin style and great,you can choose one from these
hair straighteners
Authentic chaussure puma
chaussure sport
And chaussure nike shoes
Come here to have a look of our Wholesale Jeans
Many fashionMens Jeans ,eye-catching
Womens Jeans ,and special out standing
Blue Jeans ,you can spend less money on our
Discount Jeans but gain really fine jeans, absolutely a great bargain.
www.crazypurchase.com
China Wholesale
wholesale from china
buy products wholesale
China Wholesalers
http://www.weddingdressseason.com