Talk about WebService Development-application (ii)-based on cxf-weather forecast

Source: Internet
Author: User
Tags soap wsdl

We tried to invoke the free WebService service from the source JDK, which we tried to use the Apache WebService Open source framework CXF to develop a client-requested weather forecast.

Development steps:

1. Create client project: weather-cxf-client, download CXF related jar package as tools, such as, need friends can download online or small window me;

2. Using the CXF tool Wsdl2java.bat generate the client code, the tool in the following directory, considering the ease of use, the following bin directory is set to the system environment variables:

3. Find the WSDL address of the free weather Forecast service, find the method that has been provided in the previous article, check the following address:

4. Enter the SRC directory of the project created in step 1th to execute Wsdl2java-keep, Executing this command will report an error such as:

The reason for this problem in the previous comment is that because the server side of this weather forecast is developed with net, there are some problems when Java calls Net development webservice, which can be solved by the following method, now let's verify:

A. First generate the local WSDL document, browser access HTTP://WEBSERVICE.WEBXML.COM.CN/WEBSERVICES/WEATHERWS.ASMX?WSDL will display the contents of the copy saved to a local file weather.wsdl can;

B. Place the weather.wsdl in this local document <s:element ref= "S:schema"/><s:any/> replaced by <s:anyminoccurs= "2" maxoccurs= "2"/>;

C. Generate the client calling code in the local WSDL file using the previously described method, executing and generating the following results:



5. Write the calling test code:

Package;import Java.util.list;import;import;import;public class Weatherquerytest {public static void main ( String[] args) {Weatherws factory = new Weatherws (); Weatherwssoap Wssoap = Factory.getweatherwssoap (); Arrayofstring weather = wssoap.getweather ("Guangzhou", null); list<string> weatlist = weather.getstring (); for (String temp:weatlist) {System.out.println (temp);}}}

Execution Result:

Guangzhou 23502015/05/08 08:54:27 Weather today: temperature: 26 ℃; wind/Wind: South wind 3 level; Humidity: 83% Sunglasses index: Hot. Suitable for summer wear such as T-shirts and short coats. May 8 Cloudy 24 ℃/31 ℃ No continuous wind Breeze 1.gif1.gif5 month 9th to heavy rain 23 ℃/28 ℃ No continuous wind breeze 23.gif9.gif5 month 10th Cloudy 23 ℃/28 ℃ No continuous wind breeze 1.GIF1.GIF5 month 11th Heavy rain Turn thunderstorm 23 ℃/28 ℃ No continuous wind breeze 23.gif4.gif5 month 12th Cloudy 24 ℃/29 ℃ No continuous wind breeze 1.gif1.gif

Note that this client-side engineering call does not require the introduction of CXF's related jar package, and the introduction of the above test code will report the following error:

Exception in thread "main" namespace on "html" element. You must send a SOAP request. At Org.apache.cxf.jaxws.JaxWsClientProxy.invoke ( at Com.sun.proxy. $Proxy 32.getWeather ( Unknown Source) at ( caused by: Org.apache.cxf.binding.soap.SoapFault:No namespace on "html" element. You must send a SOAP request. At Org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.readVersion ( At Org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage ( ) at Org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage ( ) at Org.apache.cxf.phase.PhaseInterceptorChain.doIntercept ( at Org.apache.cxf.endpoint.ClientImpl.onMessage ( at org.apache.cxf.transport.http.httpconduit$ WrappedOutputStream.hAndleresponseinternal ( at org.apache.cxf.transport.http.httpconduit$ Wrappedoutputstream.handleresponse ( at org.apache.cxf.transport.http.httpconduit$ Wrappedoutputstream.close ( at Org.apache.cxf.transport.AbstractConduit.close ( at Org.apache.cxf.transport.http.HTTPConduit.close (

The next article will delve into the analysis and illustration of the WSDL document.

Talk about WebService Development-application (ii)-based on cxf-weather forecast

Related Article

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: 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.