第一步:在本地(需要有jdk,并且进入jdk/bin目录执行此命令)用wsimport命令生成代理
命令:
wsimport -s ./ -p com.hanvon.iface.web.ws.wsimport http://localhost:8080/ws/attendService?wsdl
-s ./ 代表 生成的代理类放在当前目录;
-p com.hanvon.iface.web.ws.wsimport 是生成的代理类所存放的包路径,根据你的项目的包路径自己定义,因为这些类后来是要放到项目中的
生成的代理类如下:
第二步:将代理类拷入项目,调用webService
package com.hanvon.iface.web.ws;
import com.hanvon.iface.web.ws.wsimport.AttendService;
import com.hanvon.iface.web.ws.wsimport.AttendServiceImplService;
public class TestWebService {
public static void main(String[] args) {
AttendService webImplServer = new AttendServiceImplService().getAttendServiceImplPort();
String response = webImplServer.deleteClassInfo("100");//调用webService并得到返回结果
}
}
调用服务器端的webService代码如下:
WebService(targetNamespace = "kserver.hanvon.com")
public interface AttendService
{
public String deleteClassInfo(@WebParam(name="transCode")String transCode);
}