`
623deyingxiong
  • 浏览: 188354 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

axis客户端 调用 .NET(axmx)服务端

阅读更多
代码:
private boolean connect(String namespace, String endpoint, String function) {
		try {
			// 连接WS服务器
			call = (Call) service.createCall();
			// 设置调用方法
			call.setOperationName(new QName(namespace, function));
			// 设置服务器地址
			call.setTargetEndpointAddress(endpoint);
		} catch (ServiceException ex) {
			LOG.error("连接服务器(" + endpoint + ")失败", ex);
			return false;
		}
		return true;
	}
public boolean dmisQuery(String endpoint, String namespace, String function, String start,
			String until,String GID) {
		//LOG.info("测试调用:" + endpoint + ", 接口方法:" + function + ", " + "发送者:" + sender);
		// 连接服务端
		if (!connect(namespace, endpoint, function))
			return false;
		
		
		boolean result = false;

		try {
			Object data = call.invoke(new Object[] {GID,start,until});
			
			// 解析数据
			String source = new String(Base64.decode((String) data));
			LOG.info("查询结果:" + (String) data);
			//Response response = unmarshal(source);
			//LOG.info("数据状态:" + response.getStatus());
//		} catch (JAXBException ex) {
//			LOG.error("格式化XML失败", ex);
		} catch (RemoteException ex) {
			LOG.error("查询(" + endpoint + ")失败", ex);
		}
		
		return result;
	}

public static void main(String[] args){
  impl.dmisQuery("http://10.50.11.190/MWWebSite/ProjectHome/WebService/WebSer_TY_GJ.asmx", "http://tempuri.org/", "GetData", "2012-08-01 00:00:00", "2012-08-01 00:00:00","");
}



注意上面的地址http://10.50.11.190/MWWebSite/ProjectHome/WebService/WebSer_TY_GJ.asmx后缀是"asmx",表明这个地址代表的服务端是.NET架构的。

报错:
AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
 faultSubcode: 
 faultString: System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP 头 SOAPAction 的值: 。
   在 System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   在 System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   在 System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   在 System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)


解决办法:
修改connect方法,针对.NET的webservice服务端,axis客户端调用时加上
call.setSOAPActionURI(namespace+function);

修改后如下:
private boolean connect(String namespace, String endpoint, String function) {
		try {
			// 连接WS服务器
			call = (Call) service.createCall();
			// 设置调用方法
			call.setOperationName(new QName(namespace, function));
			// 设置服务器地址
			call.setTargetEndpointAddress(endpoint);
                           

/******************针对.NET服务端webservice这些个代码都是必须的*******************/
call.addParameter(new QName("http://tempuri.org/","GID"), 
                org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName("http://tempuri.org/","start"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName("http://tempuri.org/","until"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

		 call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); 
		
		call.setUseSOAPAction(true);
		
		call.setSOAPActionURI("http://tempuri.org/GetData");
/******************针对.NET服务端webservice这些个代码都是必须的*******************/		
		} catch (ServiceException ex) {
			LOG.error("连接服务器(" + endpoint + ")失败", ex);
			return false;
		}
		return true;
	}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics