java调用.net服务例子

来源:互联网 发布:系统仿真软件arena 编辑:程序博客网 时间:2024/05/21 10:32
import javax.xml.namespace.QName;import org.apache.axis.client.Call;import org.apache.axis.client.Service;public class ClientTest1 {public static void main(String[] args) {try {Service service = new Service();String url="http://127.0.0.1:8080/webservice/testService.asmx";//提供接口的地址  String soapaction = "http://test.com/"; // 域名,这是在server定义的try {Call call = (Call) service.createCall();call.setTargetEndpointAddress(url);call.setOperationName(new QName(soapaction, "methodNmae")); //方法名称call.addParameter(new QName(soapaction, "arg1"),//方法参数1名称org.apache.axis.encoding.XMLType.XSD_STRING,//参数类型javax.xml.rpc.ParameterMode.IN);call.addParameter(new QName(soapaction, "arg2"),//方法参数2名称org.apache.axis.encoding.XMLType.XSD_STRING,//参数类型javax.xml.rpc.ParameterMode.IN);call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回值类型call.setUseSOAPAction(true);call.setSOAPActionURI(soapaction + "GetGovWaredict");String str = (String) call.invoke(new Object[] { "1","2" });//调用方法并传递参数 System.out.println("返回值:"+str);} catch (Exception ex) {ex.printStackTrace();}} catch (Exception e) {e.printStackTrace();}}}

0 0