//接口层
@WebService
public interface JobService {
public String getJob();
}
//实现层
@WebService(endpointInterface="cn.ws.b.JobService")//指定要发布的的接口对象
public class JobServiceImpl implements JobService {
@Override
public String getJob() {
// TODO Auto-generated method stub
return "JEE研发工程师|Androd研发工程师|数据库工程师|前端工程师";
}
public void say(){
System.out.println("Hello Word!");
}
}
//新建测试类 发布服务
public static void main(String[] args) {
JobService job=new JobServiceImpl();
String address="http://127.0.1.0:8889/ws/jobService";
Endpoint.publish(address, job);
System.out.println("the servie is runing..."+address+"?WSDL");
}
在浏览器输入http://127.0.1.0:8889/ws/jobService?WSDL 显示如下
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://b.ws.cn/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://b.ws.cn/" name="JobServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://b.ws.cn/" schemaLocation="http://127.0.1.0:8889/ws/jobService?xsd=1"/>
</xsd:schema>
</types>
<message name="getJob">
<part name="parameters" element="tns:getJob"/>
</message>
<message name="getJobResponse">
<part name="parameters" element="tns:getJobResponse"/>
</message>
<portType name="JobService">
<operation name="getJob">
<input wsam:Action="http://b.ws.cn/JobService/getJobRequest" message="tns:getJob"/>
<output wsam:Action="http://b.ws.cn/JobService/getJobResponse" message="tns:getJobResponse"/>
</operation>
</portType>
<binding name="JobServiceImplPortBinding" type="tns:JobService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getJob">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="JobServiceImplService">
<port name="JobServiceImplPort" binding="tns:JobServiceImplPortBinding">
<soap:address location="http://127.0.1.0:8889/ws/jobService"/>
</port>
</service>
</definitions>
应用wsimport 导出客户端的需要调用的服务代码 wsimport -s F:\myworkspace\TheClient\src -p com.java.client -keep http://http://127.0.1.0:8889/ws/jobService?wsdl 说明:wsimport -s 发布的路径 -p 包名 -keep 服务地址
或者生成jar包 引入到客户端 jar -cvf 包名 路径 例如 jar -cvf test.jar ./cn 表示将当前路径下面的cn导出的包和文件 打包成test.jar文件
生成的代码如下:
客户端调用:
public static void main(String[] args) {
cn.ws.server.JobService server=new cn.ws.server.JobServiceImplService().getJobServiceImplPort();
String job=server.getJob();
String[] arr=job.split("\\|");
for(String str:arr){
System.err.println(str);
}
}