Webservice axis1 axis2 客户端调用代码

Webservice axis1 axis2 客户端调用代码

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class ClientTesterDemo {
	
	private static final String WSDL_PATH = "WSDL路径";
	public static void main(String[] args) throws Exception {

		// 创建客户端
		EndpointReference targetEPR = new EndpointReference(WSDL_PATH);
		ServiceClient serviceClient = new ServiceClient();

		// 参数和配置
		Options options = new Options();
		options.setTo(targetEPR);
		serviceClient.setOptions(options);

		OMFactory fac = OMAbstractFactory.getOMFactory();
		// 创建调用方法
		OMNamespace omNs = fac.createOMNamespace(
				"http://命名空间", "");
		OMElement methodName = fac.createOMElement("方法名", omNs);

		// 提交参数

		OMElement metaData = fac.createOMElement("参数名", omNs);
		metaData.setText("参数值");
		methodName.addChild(metaData);
		
		methodName.build();
		
		OMElement results = serviceClient.sendReceive(methodName);
		System.out.println("返回值:"+results.toString());
	}

}

 

你可能感兴趣的:(webservice)