Spring-framework 集成了联机调用支持webservice的jar。需要导入spring对应的jar
服务端发布webservice服务
package com.theService;
import javax.jws.WebService;
@WebService
public class TheService {
public void print() {
System.out.println("服务端方法调用成功!");
}
public String getString() {
return "服务端返回方法!";
}
private void cantReach() {
System.out.println("私有方法,调用不到!");
}
}
发布WebService服务端
package test;
import javax.xml.ws.Endpoint;
import com.theService.TheService;
public class TheServiceTest {
public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:8080/Service/aaa", new TheService());
System.out.println("服务端服务发布成功!");
}
}
客户端通过jdk/bin目录下的wsimport.jar生成对应的client java类
wsimport -s "src目录" -p "生成类所在包名" -keep "wsdl发布地址"
例如:wsimport -s E:\\workspace3\\TheServiceCli\\src -p com.theService -keep http://127.0.0.1:8080/Service/aaa?wsdl
导入client后的目录结构
启动服务端,客户端测试代码调用发布方法
package CliTest;
import com.theService.TheService;
import com.theService.TheServiceService;
public class cliTest {
public static void main(String[] args) {
TheService service = new TheServiceService().getTheServicePort();
service.print();
System.out.println(service.getString());
}
}