之前喝别人对接系统的时候,别人给了个wsdl文档,让我对接。如何使用wsdl生成客户端测试代码呢?本来通过myeplise直接生成的,但是由于wsdl文档不完整,生成失败!所以想着利用axsi去生成。下面看步骤:
1、导入所需要的jar
2、设置主方法参数
主方法必须是WSDL2Java
arguments:设置wsdl文档的连接地址
other:表示测试代码生成的路径
3、点击Run进行测试代码生成。
4、编写测试代码测试
以上代理类都生成了,但是怎么用呢?
import com.yiliaosoft.health.heartElect.front.webservice.IFrontProxyAPIRemoteHandlerLocator;
import com.yiliaosoft.health.heartElect.front.webservice.IFrontProxyAPIRemoteHandlerPortType;
public class Test {
public static void main(String[] args) throws Exception{
//IFrontProxyAPIRemoteHandler是接口名称,也就是wsdl文档的名字:IFrontProxyAPIRemoteHandler
IFrontProxyAPIRemoteHandlerLocator servince = new IFrontProxyAPIRemoteHandlerLocator();//生成代理服务
IFrontProxyAPIRemoteHandlerPortType client = servince.getIFrontProxyAPIRemoteHandlerHttpPort();//生成代理客户端
String xmlDoc = client.getDemoInfo();//此处为ws提供的方法
String xmlDoc2 = client.getDemoInfo2("测试啊!hello");//此处为ws提供的方法
System.out.println(xmlDoc+"---->"+xmlDoc2);
}
}