axis1.4的客户端常用模式

 

  最近因为项目需要,进行接口联调开发,初步接触到webservice客户端,最终选用axis1.4来开发客户端~几天辛苦下来,虽然很纠结,查看了很多文章~总算圆满解决问题了

 

从官网下载相应的jar包地址:http://axis.apache.org/axis/

 

最终得到的jar包截图:

 

1.根据参数的不同,我们对于axis1.4采用不同的使用方法

第一类:参数是String类型,int类型这种简单类型,就可以采用如下方式

public class WebSeriviceTest {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
	
			String xmlData = "hello";
			Service service = new Service();
			Call call = (Call)service.createCall();
			call.setTargetEndpointAddress("https://127.0.0.1/Myproject/WS/DataInterface");
			// 接口名称  
			String s1="123";
			String s2="ddf";
			String s3="dd";
			call.addParameter("xmlData", XMLType.XSD_STRING, ParameterMode.IN); 
			call.addParameter("certSubject", XMLType.XSD_STRING, ParameterMode.IN);
			call.addParameter("certSN", XMLType.XSD_STRING, ParameterMode.IN);
			call.addParameter("certBase64", XMLType.XSD_STRING, ParameterMode.IN);
			call.setOperationName(new QName("http://interfaceForWS.ra.tt.com.cn/","sendData"));
			call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
			String result = (String)call.invoke(new Object[] {xmlData, s1,s2,s3});
			System.out.println(result);
			
		} 
	
}

第二类:复杂类型xml字符串形式,我们仍然采用上述模式,但是多了一步是xml字符串的组装,这里不再细说

 

第三类:自定义对象(javabean)这里网上很多说有两种方法,第一种是添加自己的序列化工厂,但是这个人觉得需要服务端也是axis1的模式发布。第二种就是采用axis1.4提供的工具org.apache.axis.wsdl.WSDL2Java这个类自动生成客户端代码,argumes入参:-o Client -d Session -S true http://127.0.0.1:8080/TestWebService/services/RequestManager?wsdl 这个是自己定义  个人觉得使用条件是复杂数据类型的首选:

使用方法很简单:

public class ClientTest {
	
	 public static void main(String args[]){ 
  String url = "http://127.0.0.1/servic/CertManager?wsdl";
  URL serviceUrl;
  try {
      serviceUrl = new URL(url);
      CertManagerImplServiceSoapBindingStub binding=(CertManagerImplServiceSoapBindingStub)new CertManagerImplServiceLocator().getCertManagerImplPort(serviceUrl);
      //对方定义数据类型,直接在本地生成一样数据结构
      Attribute attrbute1=new Attribute();
      attrbute1.setName("123123");
      attrbute1.setValue(new Object[]{"11"});
      Attribute attrbute2=new Attribute();
      attrbute2.setName("123123");
      attrbute2.setValue(new Object[]{"11"});
      Attribute[] attributes=new Attribute[]{attrbute1,attrbute2};
      String s1="ddd";
      String s2="ddd";
      String s3="dfff"; 
     //复杂类型  
      RequestContext req=new RequestContext(attributes);
      ServiceRequest sr binding.publishCert(req, s1, s2, s3);

  } catch (Exception e) {
      e.printStackTrace();
  }       
	 }


自动生成的客户端许多文件:

其中最重要的是后缀为Locator和Stub文件

 

上述这些属于个人观点,如有帮助,非常荣幸!


 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值