使用axis1.4调用wcf协议的webservice接口的案例

1.首先下载 axis1.4 的项目包 地址:

2.解压到文件夹axis-1_4下 3.进入axis-1_4/lib文件夹,然后cmd进入命令行页面,复制以下代码执行:

java -cp activation.jar;axis.jar;commons-discovery-0.2.jar;commons-logging-1.0.4.jar;jaxrpc.jar;mail.jar;saaj.jar;wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java http://test-smsa.cloudapp.net:8082/WaybillService.svc?wsdl

4.axis-1_4/lib目录下生成一个新的文件夹com,你要的代码就在里面,把这个包下的代码都复制到你的项目中去,把lib下的jar文件也添加到项目中,然后就可以调用webservice接口了

5.编写测试代码:

import com.smsaexpress.waybills.WaybillService;
import com.smsaexpress.waybills.WaybillServiceLocator;
import com.smsaexpress.waybills.WbResult;

public static void main(String[] args) {

		try {
			WaybillService client = new WaybillServiceLocator(); // 215001055928
			WbResult result = new WbResult();
			String username = "RX3302-Test";
			String password = "533DD%rr";
			String reference = "MB0001819110604";
			String senderName = "Funeng Liu";
			String senderPhone = "13427570912";
			String senderAddress1 = "guangzhou baiyun";
			String senderAddress2 = "";
			String senderZip = "510450";
			String senderCity = "";
			String senderCountry = "CN";
			String recName = "Oladipo Orimoloye";
			String recPhone = "8025947833";
			String recAddress1 = "7b Barikisu Iyede Street ";
			String recAddress2 = "";
			String recZip = "100213";
			String recCity = "Baha";
			String recCountry = "SA";
			Calendar shipDate = Calendar.getInstance();
			Float weight = 1.2f;
			String weightUnit = "KG";
			Integer parcels = 1;
			Float DV = 28.7f;
			String consigneeID = "";
			String lat = "";
			String lng = "";
			String contentDesc = "";
			String serviceCode = "SI";
			result = client.getBasicHttpBinding_IWaybillService().generateAWB(username, password, reference, senderName, 
					senderPhone, senderAddress1, senderAddress2, senderZip, senderCity, senderCountry, recName, recPhone, 
					recAddress1, recAddress2, recZip, recCity, recCountry, shipDate, weight, weightUnit, parcels, DV, 
					consigneeID, lat, lng, contentDesc, serviceCode);
			System.out.println(result);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

6.接口返回的信息都在result中。

经验分享 程序员 微信小程序 职场和发展