X

Geertjan's Blog

  • August 1, 2005

Another Prague? In the U.S.?

Geertjan Wielenga
Product Manager
NetBeans IDE has taught me a lot, but not that there's another Prague. You would've thought that one would be more than enough. Well, here's the proof -- thanks to a web service that Lukas Jungmann helped me with, I typed a random zip code in a web page:

When I clicked "Find the City!", a new web page popped up and this is what I saw:

Of course, NetBeans didn't do this on its own -- it used this WSDL file:

http://www.innergears.com/WebServices/CityStateByZip/CityStateByZip.asmx?WSDL

NetBeans IDE includes a cool template that very quickly generates a web service client for you. There's even a built-in client, which means that you need not do any coding -- you can test your web service right away. Then, knowing that the WSDL works as expected, you can add a very small bit of code to a servlet and bob's your uncle. This was the important part that I had a little trouble with, it's part of the processRequest method in the servlet:

String zipCode = request.getParameter("zipCode");
out.println("<b>Zip:</b>");
out.println(zipCode);
out.println("<p><b>City and State:</b>");
String[] s = getCityStateByZipSoap().getCityStateByZip(zipCode).getString();
out.println(Arrays.asList(s));

Now that I know how to work with complex types, working with web services is going to be much easier, since many (if not most) web services seem to use complex types.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha