Java calls the free WebService example "weather forecast" "Domestic mobile phone number attribution to search"

Source: Internet
Author: User
Tags wsdl

1. Free WebService Address: http://www.webxml.com.cn/zh_cn/index.aspx

There are many Web services such as weather forecast, cell phone attribution query and so on.

2. Invoke the Weather forecast service example:

Generate the client code using the Wsimport command that comes with the JDK:

Wsimport-keep http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl  

The discovery throws the following exception:

And then I found it on the Internet.http://blog.sina.com.cn/s/blog_4c925dca01014y3r.htmlThis blog solves the problem of saving the WSDL file on the network first to local such as E:\WSDL\WEATHER.WSDL and then all the files in the file <s:element ref= "S:schema"/><s:any/>replaced by<s:any minoccurs= "2" maxoccurs= "2"/>Can.

Use the Wsimport command again to generate the client code, this time using a locally modified WSDL file to generate the command as follows:

Wsimport-keep E:\WSDL\weather.wsdl

You can see that many Java classes are generated in the current directory, and these classes are copied to the Eclipse project

Write a test class below to invoke the generated client code to get the weather forecast information

Package cn.com.weatcher;

Import java.util.List;

Import cn.com.webxml.ArrayOfString;
Import Cn.com.webxml.WeatherWS;
Import Cn.com.webxml.WeatherWSSoap;

public class Weatherclient {

public static void Main (string[] args) {
WEATHERWS fs = new Weatherws ();
Weatherwssoap soap = Fs.getweatherwssoap ();
Arrayofstring astring = Soap.getweather ("Shenzhen", null);
list<string> String = astring.getstring ();
System.out.println (string);
}
}

The console input results are as follows:

[Guangdong Shenzhen, Shenzhen, 2419, 2015/01/31 16:15:18, today's weather: temperature: 16 ℃; Wind/Wind: 2 in the Northeast; Humidity: 62%, air quality: no; UV intensity: weak, sunglasses index: Required. Sunglasses are worn during the day, depending on outdoor light conditions.
Clothing index: more comfortable. Wear clothing such as a thin coat or jeans is recommended.
Tourism index: suitable. The weather is better, the slightest will not affect the mood of your trip.
Movement Index: more suitable. If the temperature is low, you are recommended for indoor sports.
Car Wash Index: more appropriate. No rain and less wind, easy to maintain cleanliness.
Makeup index: Moisturizing. Please choose a neutral moisturizing cream type cosmetics.
Cold index: more prone to hair. Days cooler, increase clothing, pay attention to protection.
Air Pollution index: not currently.
UV index: weak. The radiation is weak, rub spf12-15, pa+ skin care product.
Comfort Index: comfortable. The daytime is lukewarm and the wind is small.
, January 31 Cloudy, 13 ℃/18 ℃, no continuous wind breeze, 1.gif, 1.gif, February 1 Cloudy, 13 ℃/21 ℃, no continuous wind breeze, 1.gif, 1.gif, February 2 Cloudy, 14 ℃/22 ℃, no continuous Wind, 1.gif, 1.G If, February 3 Cloudy, 14 ℃/19 ℃, no continuous wind breeze, 1.gif, 1.gif, February 4 Cloudy, 15 ℃/21 ℃, no continuous wind breeze, 1.gif, 1.gif]
3. Domestic mobile phone number attribution to query Web services :http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl

Execute the following command:

Wsimport-keep http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl

Copy the generated client code into the Eclipse project

Write Test class tests:

Package cn.com.mobile;

Import Cn.com.webxml.MobileCodeWS;
Import Cn.com.webxml.MobileCodeWSSoap;

public class Mobiletest {

public static void Main (string[] args) {
Mobilecodews mobilecodews = new Mobilecodews ();
Mobilecodewssoap Mobilecodewssoap = Mobilecodews.getmobilecodewssoap ();
String mobilecodeinfo = Mobilecodewssoap.getmobilecodeinfo ("18617054380", null);
System.out.println (Mobilecodeinfo);
}
}

The console enters the following information:

13430448863: Guangdong shenzhen Guangdong mobile Shenzhou Travel Card

Java calls the free WebService example "weather forecast" "Domestic mobile phone number attribution to search"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.