I checked a very strange problem of a colleague today, and now I will list the problems encountered today.
When calling the webservice service of the peripheral system, generally speaking, the other party will provide a wsdl, and then we need to generate the corresponding class according to the wsdl. In this way, a perfect cross-language solution is achieved, but it also brings some complexity. In java, we generally use the wsimport tool that comes with jdk or the wsdl4j tool of other third-party systems to generate the stub implementation of the java version.
- Use the wsimport tool that comes with jdk. The specific usage is as follows:
In the bin folder of the JDK, there is a wsimport.exe. This tool generates corresponding class files based on the wsdl file, and then using these class files, you can call the method provided by WebService just like calling a local class. This tool can be used for non-Java servers, such as WebServices written in C#, and Java client implementations are generated through wsimport.
Use the following command in the command prompt:
wsimport http://localhost:8080/Demo/services/MyService?wsdl
- Use a third-party ws framework, take cxf as an example:
Use the wsdl4j generation that comes with the webservice framework. Due to well-known reasons, there are many java webservice frameworks. Often due to different versions and implementations, there will be some inexplicable problems , so it is recommended to use the one you use here. The framework's wsdl4j tool generates the corresponding stub .
- Download apache-cxf-2.5.11.zip and extract it to D:\apache-cxf-2.5.11, download address: http://mirror.bjtu.edu.cn/apache/cxf/2.5.11/apache-cxf -2.5.11.tar.gz
- Execute the command under the D:\apache-cxf-2.5.11\bin directory: wsdl2java http://xxx.yyy.com:8102/ws/UserRemoteService?wsdl
- After the command is executed, the corresponding code will be generated in the relevant folder, and all the code will be imported into the access system, which is the same as wsimport
Problems encountered during use:
- A problem was found in the process of use. Since jdk6 only supports the ws2.1 specification version at most, when generating under jdk6, add -frontend jaxws21
wsdl2java -frontend jaxws21 http://xxx.yyy.com:8102/ws/UserRemoteService?wsdl
- 发现可以根据wsdl生成java类,java类中的注释有可能是中文,所以要加上encoding参数,例如:-encoding utf-8
http://asialee.iteye.com/blog/1912953