WebService achieved by JAX-WS

Create (a) of the server

First, start by creating a Web project, or create a Web Service Project is also OK (difference is that the latter is set at the beginning of the invocation of the Web Service)

Second, create a class in the project to be published as part of our service (requires non-static public method, I have here is the main method a try)

Third, this project turned into a Web Service Project (the beginning of the project to create a Web Service is also taking this step), select New Web Service in the red part of the plan

Here choose to download JAX-WS Facet, then Strategy (policy deployment) by selecting the following java class to create a web service (JAX-WS version of the best and Myeclipse in the version of the agreement will be mentioned later; Target runtime is that you use tools to run services)

After the next release will enable us to select the category, click on Browse here we write input class, other data is automatically populated. Not familiar with when you can check Generate WSDL in project (generated wsdl file in the project), repeat the operation on the line when there is more than one class.

Fourth, after the completion of the above it is the leader packet. Select the right project to select Properties, then select the build path, and then click Add Library, then select Myeclipse Library, searched last JAX-WS. Here are the results of my search version 2.1, and version 2.0 was previously configured, although can be used, but the best is the same. (Also own package to guide the project which, if it were two --jax-ws runtime and jax-ws api)

Fifth, the lead pack was finished publishing service. Here, too, we choose to publish parts zoned red line service, then select our project and then click Add, select the Publisher service.

发布成功后就运行服务器,运行完成后看下中途是否有报异常、错误。没有错误就看下一步,有和我同样的错误参考:https://blog.csdn.net/weixin_37848710/article/details/79665498(其实就是包有问题,在build path里面选择JAX-WS的包,然后点击Edit把所有的选项都选上)。处理完成后在Servers窗口选中自己的项目重新编译后再启动服务器。

六,没有错误正常启动服务器后就可以查看我们的服务是否正常启用。熟悉的时候就可以直接输入WSDL的地址来查看,不熟悉的话根据之前转换Web Service项目的时候选择的生成的WSDL文件来查看。直接复制XXXPort里面的地址加上?wsdl就可以看到自己发布的服务的WSDL文件,到此服务端完成。

(二)客户端的创建

一,创建一个Java 项目(其他项目也行,这里主要是用来测试的。)然后点击划红线的倒三角选择New Web Service Client,选择刚建的项目就next

接着选择WSDL URL,输入我们前面服务端的wsdl(这里服务端需要处于启动状态)这里如果不指定java source folder和java package就直接用wsdl的文档路径。然后next,finish。会生成如下文件结构。

然后我们新增一个Test类,里面通过main方法来调用Web Service服务端。

main方法的第一行是获取服务的对象;第二行是获取服务的端口;第三行是调用Web Service服务获取返回值;第四行由于我这边返回的是个字符串,所以打印出来看具体结果。

到此,打完收工!

参考文档:https://www.cnblogs.com/lee0oo0/archive/2013/01/25/2876357.html

Guess you like

Origin www.cnblogs.com/flyingorchid/p/11721175.html