基于Java的webservice创建与jax-ws方式调用

一、创建(服务端)

建立普通类,代码:

package com.XXX.controller.sys;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class TestwebService {
		@WebMethod(operationName="sayHello")
		public String sayHello(){
			return "Hello world!";
		}
		
		@WebMethod(operationName="getSum")
		public int getSum(int a,int b){
			return a+b;
		}
		
		
	public static void main(String [] args){
		Endpoint.publish("http://localhost:8083/HelloWorld", new TestwebService());
		System.out.println("success!");
	}
	

}

浏览器键入http://localhost:8083/HelloWorld

二、调用(客户端)

利用jax框架生成的客户端

1、选择new->Other->web service client

2.选择所依赖的工程,选择JAX-WS框架,点击下一步

3.将WSDL的地址填入下面界面的URL栏里,选择或者新建一个包,其他默认

4.点击确认后即可生成相应的文件如下

5、建立测试类Test.java

package webservice;

public class Test {
	public static void main(String[] args) {
		 TestwebServiceService test = new TestwebServiceService();
		 TestwebService hello = test.getTestwebServicePort();
		 
		 String a  = hello.sayHello();
		 System.out.println(a);
		 System.out.println("2 + 5 = "+hello.getSum(2, 5));
	}
}

输出结果

webService调用成功

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值