Through the previous record, we know that after the release of a service, if others need to call, we must know our WSDL address, in the same way, we want to invoke the weather forecast interface, we must also get the corresponding WSDL, the following gives a more complete WSDL URL, you need to check:/http Www.webxml.com.cn/zh_cn/web_services.aspx
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/DE/wKiom1S_IhvieP_4AADi1iy0uko001.jpg "title=" mv%82~ 0451m2o3ln6xa{9xa.jpg "alt=" Wkiom1s_ihviep_4aadi1iy0uko001.jpg "/>
Today's example will explain how to invoke the interface to the national television tv
Through the lookup, you can get the WSDL address as:
http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl
(i), Wsimport generation Agent class
Wsimport has been introduced in Jax-WS using WebService, and is used directly here.
Create a new Web project, cmd into the project path
Ready to build all the proxy classes into the Com.xj.service package
D:\workspace\hangban\src>wsimport-p Com.xj.tv-keep http://webservice.webxml.com.cn/webservices/ chinatvprogramwebservice.asmx?wsdl
Compiling an error using JDK6
[WARNING] src-resolve.4.2:Error resolving component ' S:schema '. It was detected
that ' S:schema ' was in namespace ' Http://www.w3.org/2001/XMLSchema ', but Compone
NTS from this namespace is not referenceable from schema document ' File:/e:/wor
kspace/practical/webserviceweather/src/com/weather/wsdl.xml#types?schema1 '. If T
the incorrect namespace, perhaps the prefix of ' s:schema ' needs to be cha
nged. If this was the correct namespace, then an appropriate ' import ' tag should
Be added to ' file:/e:/workspace/practical/webserviceweather/src/com/weather/wsdl
. Xml#types?schema1 '.
.............
This should be a bug.
Workaround: Save the WSDL locally and all
<s:element ref= "S:schema" /> Changed to <s:any minoccurs= "2" maxoccurs= "2"/> and the rear
<s:any/> deleted.
Execute the wsimport command again, change the WSDL address to the local address as follows
Wsimport-p Com.xj.service-keep E:/hangban.xml
if it is still an error, the WSDL file inside the <wsdl:documentation all nodes are deleted. It should be fine.
After a good Java file is generated. You can call it.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/E1/wKiom1S_T77wBCnqAAK0hemBV1o789.jpg "title=" ds09g@ct05xc}~ ' EG '%6]7h.png "alt=" Wkiom1s_t77wbcnqaak0hembv1o789.jpg "/>
You can see that the proxy classes generated by Wsimport are com.xj.tv and can be used directly
There are many classes, already corresponding response, we are going to find a class with soap
(b), the client calls the proxy class directly
Chinatvprogramwebservice service = new Chinatvprogramwebservice (); Chinatvprogramwebservicesoap soap = Service.getchinatvprogramwebservicesoap (); Arrayofstring arrayofstring = soap.gettvchannelstring (80); list<string> list = arrayofstring.getstring (); for (String string:list) {System.out.println (list);}
Give Tvchannel any ID, for example 80, to see the output
[[email protected] Putian TV station]
Other calls are similar in the same way
This article is from the "Bulajunjun" blog, make sure to keep this source http://5148737.blog.51cto.com/5138737/1606622
WebService calls domestic flights, weather forecasts and other external interfaces