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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值