java代码调用webservice接口

import java.rmi.RemoteException;

import javax.xml.rpc.ParameterMode;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;


  public static void main(String[] args) {

//远程调用路径
String endpoint = "http://10.0.20.22/cgi-bin/fglccgi/ws/r/aws_t118?WSDL";
String result = "call failed";
// 创建一个服务(service)调用(call) 
Service service = new Service();
Call call;
try{
// 通过service创建call对象   
call = (Call) service.createCall();
// 设置service所在URL 
call.setTargetEndpointAddress(endpoint);
//调用的接口地址,调用的方法名
call.setOperationName(new javax.xml.namespace.QName("http://tempuri.org/webservices", "aws_t110b2b_ins"));

//设置参数名dbs,第二个参数表示类型,第三个表示入参

                call.addParameter("dbs", XMLType.XSD_STRING, ParameterMode.IN);

call.addParameter("aba01", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("user", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("date", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("orderno", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("xml", XMLType.XSD_STRING, ParameterMode.IN);
//设置返回值类型
call.setReturnType(XMLType.XSD_STRING);
String dbs = "SZ36";
String aba01 = "9101";
String user = "admin";
String date = "2018-05-07";
String orderno = "YF01-180400044";
String xml = "xml";
result = (String) call.invoke(new Object[]{dbs,aba01,user,date,orderno,xml});// 远程调用
}catch(ServiceException e){
e.printStackTrace();
}catch(RemoteException e){
e.printStackTrace();
}
System.out.println(result);
System.exit(0);
}

a.这个里面的访问地址,方法名,对应的是我上篇博客的webservice参数,我简单介绍下,前面是webservice接口所部署的服务器网络Ip,servers路径,hello服务名,dockinfoInsert你要调用的接口的方法名,new Object[]{cs}放你传递的参数。

b.这个一般是接口的提供方会给出接口介绍文档,然后你根据文档就可以找到对应的路径,方法名。




  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值