in the bin folder of the JDK , There is a wsimport.exe tool that can generate corresponding class files based on wsdl files, copy these class files that exist locally to the project that needs to be used, and then call the methods provided by webService just like calling local classes. This tool can be used for non-Java servers, such as WebService written in C#, and generate Java client implementations through wsimport.
Common commands are as follows :
This command must run cmd as an administrator under windows Command window, and then execute this command.
- wsimport-keep-d D:\temp\d-s D:\temp\s-p com.map-verbose http: //ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
-keep: whether to generate java Source file
-d: Specify the output directory of the .class file
-s: Specify the output directory of the .java file
-p:defines the package name of the generated class, not If defined, there is a default package name
-verbose: display output information on the console
-b: Specify jaxws/jaxb binding files or additional schemes p>
-extension: Use extension to support SOAP1.2
wsimport example
Here, recommend a website,provides a comprehensive WebService interface for Reference: http://www.webxml.com.cn/zh_cn/web_services .aspx
Generate the webService of the place where the query number belongs locally h3>
(1 ) Enter the website to find
Among them, the .asmx URL describes the calling method, input parameters, and return data,.wsdl is the URL we want to use to generate the code.
(2) Create a new Java Project. After the project is created, generate the src directory
(3) cmd command, enter the bin directory of jdk and run the command:
- wsimport-keep-s D:\Workspaces -p com.cn.phone -verbose http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
The path after -s if It is not the src directory of the project, you need to copy the generated package to the src directory
Refresh the project and you will see the files we generated
When we click on a few java files, do we find Chinese comments are garbled. If you want to change the encoding of the source code to UTF-8, you can download a tool: UTFCastExpress
< span style="margin:0px; padding:0px; font-family:"Microsoft YaHei"; font-size:14px">http://download.csdn.net/detail/aqsunkai/9535166
(4) Write the test class under this path:
- < li class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> packagecom.cn.phone;
- publicclassPhoneWsClient{
- publicstaticvoid
main(String[]args){ - //Create a MobileCodeWS factory
- MobileCodeWS factory = new span>MobileCodeWS();
- //root According to the factory, create a MobileCodeWSSoap object
- MobileCodeWSSoap mobileCodeWSSoap=factory.getMobileCodeWSSoap();
- //call The getMobileCodeInfo method provided by WebService to query the attribution of the mobile phone number
- String searchResult= mobileCodeWSSoap.getMobileCodeInfo(“18512155752”, null);
- System.out.println(searchResult);
- }< /li>
p>
Run main After the method:
in Local generation query weather forecastwebService
- wsimport -keep -s D:\Workspaces -p com.cn.weather -verbose C:\Users\sun\Desktop\WeatherWS.xml
(4) 把生成的包拷贝到src目录下
- package com.cn.weather;
- import java.util.List;
- public class WeatherWsClient {
- public static void main(String[] args) {
- //创建一个WeatherWS工厂
- WeatherWS factory = new WeatherWS();
- //根据工厂创建一个WeatherWSSoap对象
- WeatherWSSoap weatherWSSoap = factory.getWeatherWSSoap();
- //调用WebService提供的getWeather方法获取南宁市的天气预报情况
- ArrayOfString weatherInfo = weatherWSSoap.getWeather(“钓鱼岛”, null);
- List
lstWeatherInfo = weatherInfo.getString(); - //遍历天气预报信息
- for (String string : lstWeatherInfo) {
- System.out.println(string) ;
- System.out.println(“————————“);
- }
- //获得中国省份、直辖市、地区和与之对应的ID
- ArrayOfString s = weatherWSSoap.getRegionProvince();
- List
list = s.getString(); - for (String string : list) {
- System.out.println(string);
- System.out.println(“————————“);
- }
- }
- }
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3525 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC