Netbeans 5.5 Tip: Create a Webservice client to find Latitude & Longitude of your city

Using Netbeans 5.5 IDE, it is as easy as 1..2..3 to develop a Webservice client to find the Latitude and Longitude of your city. The webservice I used here is from Microsoft Terra Server called TerraService.

Here are the  steps

  • Using Netbeans 5.5 IDE, create a General Java Application project called LocationService
  • Right click on the project select New -> New Webservice Client
  • In the New Webservice Client dialog, select WSDL URL and provide http://terraserver.microsoft.com/TerraService2.asmx?WSDL
  • Also specify "locationsvc" as package name

The TerraService Webservice client will be added to the project as shown below.

Drag and drop the method ConvertPlaceToLonLatPt from the webservice client on to the main() method of Main.java. Necessary code will be added. Modify as shown below to display the location (blue lines are modified by me)

        try { // Call Web Service Operation
            locationsvc.TerraService service = new locationsvc.TerraService();
            locationsvc.TerraServiceSoap port = service.getTerraServiceSoap();
            // TODO initialize WS operation arguments here
            locationsvc.Place place = new locationsvc.Place();
            place.setCity("Menlo Park");
            place.setState("California");
            place.setCountry("United States");
            // TODO process result here
            locationsvc.LonLatPt result = port.convertPlaceToLonLatPt(place);
            System.out.println("City: " + place.getCity() + ", " + place.getState() + ", " + place.getCountry()); 
            System.out.println("Latitude = " + result.getLat() + "  Longitude: " + result.getLon());
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }

Compile and run the application. Bingo!, the result is the Latitude and Longitude of your city.

run:
City: Menlo Park, California, United States
Latitude = 37.45000076293945  Longitude: -122.16999816894531
BUILD SUCCESSFUL (total time: 3 second
Comments:

Hi Winston,
If you're more into RESTful stuff, there's Google's equivalent: http://blogs.sun.com/alexismp/entry/mashup_explanation_part_i

Posted by A` on January 05, 2007 at 08:17 PM PST #

It's so cool...

Posted by cpark on January 06, 2007 at 03:06 AM PST #

Hi, this seems like a great tutorial, but I can't drag and drop the method. When I try typing locationsvc.TerraService service = new locationsvc.TerraService(); NetBeans creates a slew of empty methods, non of which are mentioned here. It seems like a simple task, yet somehow it is beyond me. What am I doing wrong???

Posted by Eric on January 12, 2007 at 09:23 AM PST #

hkv,;

Posted by guest on March 05, 2007 at 09:13 PM PST #

Your example worked great! However, when I try a different Web Service, specifically one created by someone using .NET, I get the following error: [WARNING] src-resolve.4.2: Error resolving component 's:schema'. It was detected that 's:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document ... Apparently, I'm not the only one having a problem. See: http://forums.java.net/jive/message.jspa?messageID=201229 If you can guide me on how to fix this problem without changing the Web Service (since I didn't write it), I would appreciate it. Thank you.

Posted by Sam Lalani on March 25, 2007 at 10:28 AM PDT #

Hi,
I am trying to write a Java wbservice client for a .NET webservice. The .NET service required a Ticket number and a logon parameter to be passed in for Authentication.

I am unable to write this code. I am using Netbeans and am not able to create a Stub for my service. Typecasting does not work either. Please help......

Posted by Sucheta Lele on September 17, 2007 at 06:19 AM PDT #

comment

Posted by guest on September 18, 2007 at 06:15 AM PDT #

Hi,

I am trying to access .Net webservice through Java client using Netbeans 6.0. Initially everything worked correctly. Ysterday I re installed my websrvice again after which I started gtting an error "Operation Undefined" for a particular operation though the operation is present in the wsdl and corresponding java class is formed.

Could anyone help me out? I am new to .net.

Thanks & Regards,
Sneha

Posted by Sneha on February 18, 2008 at 06:04 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today