前提:需要调用webservice接口时,获取到wsdl地址,并清楚里面的相关内容。
1 引入相关jar包:axis相关jar包下载
2 java相关代码,和网上提供的大致相同:
package com.demo.service;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class MyClient {
public static void main(String[] args) {
try {
// 直接引用远程的wsdl文件地址,如http://www.baidu.com/myService/serviceTest
String endpoint = "";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("sendInfo");// WSDL里面描述的接口名称
call.addParameter("in0",
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.addParameter("in1",
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.addParameter("in2",
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
String result = (Strin