java webService的简单应用

//接口层
@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);
			
		}
	}

转载于:https://my.oschina.net/mclongyi/blog/799429

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值