参数:测试webService的地址:http://10.113.11.1:9090/enocpService/buildingEngService?wsdl
1,eclipse中新建一个项目,
2,使用jdk自带wsimport工具自动生成服务端java代码,打开dos窗口,输入 wsimport -keep http://10.23.11.1:8080/webService/buildingEngService?wsdl
服务端java 代码回自动生成,在当前目录下,只复制两个文件即可。一个是接口BuildingEngService,一个是BuildingEngService_Service,
3,把生成的两个文件代码复制到项目中,
4,新建一个java测试类HelloService。
package com.je.ws; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import cn.com.guodiantong.pb.webservice.server.base.service.BuildingEngService; public class HelloService { public static void main(String[] args) { Service energyService; Class energyTargetInterface = BuildingEngService.class; String url = "http://10.113.11.1:9090/enocpService/buildingEngService"; String targetNameSpace = "http://service.base.server.webservice.pb.guodiantong.com.cn/"; String interService = "buildingEngService"; String targetServicePort = "BuildingEngServicePort"; try { energyService = Service.create(new URL(url),new QName(targetNameSpace, interService)); QName energyQname = new QName(targetNameSpace,targetServicePort); BuildingEngService energyPort = energyService.getPort(energyQname, energyTargetInterface); String json = "{\"inputFlag\":{\"systemCode\":\"BENX\",\"functionCode\":\"getElectricRecording\"},\"inputData\":[{\"deviceNumber\":\"T1001\",\"electricQuant ity\":\"9784065.00\",\"electricLoad\":\"2349.90\",\"collectTime\":\"2016-01-11 14:30:00\"}]}"; String re = energyPort.getElectricRecording(json); System.out.println("result == "+ re); } catch (MalformedURLException e) { e.printStackTrace(); } } }
5,Run as java Application 完成。