java axis 1.4访问c# webservice,并获取返回值为dataset

本文介绍如何使用Java访问C#的WebService服务,并详细展示了通过Apache Axis库进行SOAP请求的具体步骤,包括设置URL、操作名称、参数及返回类型等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        用java访问c# webservice时,和平时java访问自己不大一样。

  

	try {
			// 创建一个服务(service)调用(call)

			org.apache.axis.client.Service service = new org.apache.axis.client.Service();

			Call call = (Call) service.createCall();// 通过service创建call对象

			// 设置service所在URL

			call.setTargetEndpointAddress(new java.net.URL(endpoint));

			// 方法名(processService)与MyService.java方法名保持一致

			call.setOperationName(new QName("http://tempuri.org/", "GetWxyt"));

			call.setUseSOAPAction(true);
			call.setSOAPActionURI("http://tempuri.org/GetWxyt");

			call.addParameter(new QName("http://tempuri.org/", "ytTypeId"),
					org.apache.axis.encoding.XMLType.XSD_STRING,
					javax.xml.rpc.ParameterMode.IN);
			call.addParameter(new QName("http://tempuri.org/", "ytStartTime"),
					org.apache.axis.encoding.XMLType.XSD_STRING,
					javax.xml.rpc.ParameterMode.IN);
			call.addParameter(new QName("http://tempuri.org/", "ytEndTime"),
					org.apache.axis.encoding.XMLType.XSD_STRING,
					javax.xml.rpc.ParameterMode.IN);
			call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA);

			// ytTypeId ytStartTime ytEndTime

			Object object = call.invoke(new Object[] { "1",
					"2013-08-30 08:30:00", "2013-08-30 18:30:00" });
			
			System.out.println(object);
			
			//c#返回值的dataset类型,必须进行解析,下面是解析过程
			Schema schema = (Schema)object;

			//DefaultTableModel model=new DefaultTableModel(new String[]{"strFilePath","strMyImageBytes"},0); 
			schema.get_any()[1].getChildNodes().getLength();

			int nLength=schema.get_any()[1].getChildNodes().item(0).getChildNodes().getLength();
			
			String strFilePath="";
			String strMyImageBytes="";
			
			JSONArray jsons = new JSONArray();

			for(int i=0;i<nLength;i++)
			{

		    JSONObject jsonObject = new JSONObject();
		    
			if(schema.get_any()[1].getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(0).getNodeName().equals("strFilePath"))
			{
				strFilePath=schema.get_any()[1].getChildNodes().item(0).getChildNodes().
				     item(i).getChildNodes().item(0).getFirstChild().getNodeValue();
				
				jsonObject.put("strFilePath", strFilePath);
			}

			if(schema.get_any()[1].getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(1).getNodeName().equals("strMyImageBytes"))
			{
				strMyImageBytes=schema.get_any()[1].getChildNodes().item(0).
				getChildNodes().item(i).getChildNodes().item(1).getFirstChild().getNodeValue();
				
				jsonObject.put("strMyImageBytes", strMyImageBytes);
			}
			//model.addRow(new String[]{strFilePath,strMyImageBytes});

			   jsons.add(jsonObject);
			}

			System.out.println(jsons.toString());
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		}


    其中有几个设置是不可缺少的
   call.setOperationName(new QName("http://tempuri.org/", "GetWxyt"));

   call.setUseSOAPAction(true);
   call.setSOAPActionURI("http://tempuri.org/GetWxyt");

   http://tempuri.org/wsdl:definitions结点下的targetNamespace结点的属性值。

   

 

 call.addParameter(new QName("http://tempuri.org/", "ytTypeId"),
     org.apache.axis.encoding.XMLType.XSD_STRING,
     javax.xml.rpc.ParameterMode.IN);
   call.addParameter(new QName("http://tempuri.org/", "ytStartTime"),
     org.apache.axis.encoding.XMLType.XSD_STRING,
     javax.xml.rpc.ParameterMode.IN);
   call.addParameter(new QName("http://tempuri.org/", "ytEndTime"),
     org.apache.axis.encoding.XMLType.XSD_STRING,
     javax.xml.rpc.ParameterMode.IN);
   call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA);

 

    new QName("http://tempuri.org/", "ytEndTime")这边参数也必须加上命名空间,否则会出现莫名其妙的错误。

 

    最后面是dataset类型的返回值的获取,可以参考下。

 

 

  
 

   

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值