There are many free webservice services on the Internet, and we can call these free webservice services to integrate content information from some other sites into our web apps.
Links to some of the commonly used WebService websites: HTTP://WWW.TUICOOL.COM/ARTICLES/IIFQMA
One: Call free Web service to get weather forecast information
1. Third party service address
Http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
2. Generate local piles (automatically generate client code with the Wsimport command tool)
Open a command line window, switch to the project's SRC directory, execute "wsimport-keep http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl" to generate the client code, As shown in the following:
Running results show that using the Wsimport tool to generate the client code directly throws an exception, unable to generate the client code, Just because the webservice we're going to call is written in. NET, this is the problem with the Java call Net WebService, the solution to this problem is as follows:
- Save the corresponding WSDL document to a local
2. Modify part of the WSDL document: replace <s:element ref= "S:schema"/><s:any/> with <s:any minoccurs= "2" maxoccurs= "2"/>
Execute the Wsimport generated code again, this time using a local weatherws.wsdl file to generate it, as shown in:
From the execution results show, this time can generate code normally, refresh the SRC directory, you can see the generated code, as shown in:
3. Write the request code with the generated code
Packageme.gacl.ws.client;Importjava.util.List;Importorg.junit.Test;Importcn.com.webxml.ArrayOfString;ImportCn.com.webxml.WeatherWebService;ImportCn.com.webxml.WeatherWebServiceSoap; Public classweatherwsclient { Public Static voidMain (string[] args) {//Create a WEATHERWS factoryWeatherwebservice factory =NewWeatherwebservice (); //Create a Weatherwssoap object based on the factoryWeatherwebservicesoap Weatherwssoap =factory. Getweatherwebservicesoap (); //call the GetWeather method provided by WebService to get the weather forecast for NanningArrayofstring weatherinfo = Weatherwssoap.getweatherbycityname ("Shanghai"); List<String> Lstweatherinfo =weatherinfo.getstring (); //Traverse weather Forecast information for(String string:lstweatherinfo) {System.out.println (string); System.out.println ("------------------------"); } } //supported by the Executive City@Test Public voidTest () {//Create a WEATHERWS factoryWeatherwebservice factory =NewWeatherwebservice (); //Create a Weatherwssoap object based on the factoryWeatherwebservicesoap Weatherwssoap =factory. Getweatherwebservicesoap (); //call the GetWeather method provided by WebService to get the weather forecast for NanningArrayofstring Weatherinfo =weatherwssoap.getsupportprovince (); List<String> Lstweatherinfo =weatherinfo.getstring (); //Traverse weather Forecast information for(String string:lstweatherinfo) {System.out.println (string); System.out.println ("------------------------"); } }}
Test results:
Municipalities------------------------Shanghai------------------------58367------------------------58367. jpg------------------------2017-6-4 10:50:51------------------------21℃/28℃------------------------June 4 Sunny Turn Cloudy------------------------Dongfeng Breeze------------------------0. gif------------------------1. gif------------------------today's weather fact: air temperature:26 ℃; Wind/Wind: 3 levels in the northeast; Humidity: 53%; UV intensity: strong. Air quality: Medium. ------------------------UV Index: Strong, rub SPF greater than 15, PA+Sunscreen skin care products. Cold index: Less hair, no obvious cooling, cold probability is low. Dress index: Hot, suitable for wearing T-shirts, short-thin jackets and other summer clothing. Car Wash Index: More suitable, no rain and small wind, easy to maintain cleanliness. Exercise index: More appropriate, please reduce the intensity of exercise. Air Pollution Index: In the easy-to-feel population should reduce outdoor activities appropriately. ------------------------22℃/25℃------------------------June 5 Moderate Rain------------------------Southeast Wind Breeze------------------------8. gif------------------------8. gif------------------------21℃/25℃------------------------June 6 Showers Turn Cloudy------------------------The winds of the wind turn northwest------------------------3. gif------------------------1. gif------------------------Shanghai Abbreviation: Shanghai is located in the Yangtze River Delta, east of Donghai, south of Hangzhouwan, west of Jiangsu, Zhejiang Province, the north of the Yangtze into the sea, just as China's north and south coast line of the central, latitude 32°14′, Longitude 121°29.
Area: Total area of 7823.5 square kilometers. Population: Population more than 10 million. Shanghai's rich cultural resources, charming city style, bustling commercial street city and festive activities have formed a unique urban landscape. Visit Shanghai,
Not only can experience the metropolis of the east and west of the wall, business and Confucianism Blend, Happo to wind atmosphere, and can feel the city bustling, busy, bright lights of vitality. Shanghai occupies a very important position in the modern history of China,
She is the birthplace of Chinese xxx. Many of the historical events that shook the Chinese and foreign have taken place here, leaving behind numerous revolutionary ruins, telling you a story that never forgets, and becoming a cultural scene containing folklore.
and memorial Place. In Shanghai, every Autumn festival, a crowd of people here to sacrifice martyrs, the memory of the revolutionary history, has become a custom. The great Shanghai in the modern history of China, has been a place of surging and stirring. In this place
The number of man, scattered in various residential buildings throughout Shanghai, due to the extraordinary owner, contains an intriguing historical significance. The footsteps of many revolutionary martyrs have been left here. The former residence of Sun Yat-sen, Soong Ching Ling and Lu Xun
will make you produce reviewing deep reverie, there are countless dignitaries of the house, visit Li, Chiang Kai-shek and other people's mansion, can associate with the master of the period of eminent history of prosperity. ------------------------
Above, is an instance of a complete third-party invocation of the WebService service.
Java calls third-party WebService application instances