Electronic approval 开发经验---xfire 调用C#接口
java使用xfire写了一个客户端,代码如下:
------------------------------client.java--------------------------------------------
Service srvcModel = new ObjectServiceFactory()
.create(IICSServices.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String xml="<?xml version='1.0' encoding='UTF-8'?>" +
"<Data>" +
"<Task BusinessId='' BusinessType='' Orgid='' Businessorgid='' Branchid='' BusinessBranchid=''>"+
"<Input ImageType='' />" +
"<Output ImageType='' />" +
"<Conclusion Status=''></Conclusion>"+
"</Task>" +
"</Data>";
// Test tt=new Test();
String getCentreInfoURL =
"https://10.4.60.225:8001/ICS/ICSService";
try {
IICSServices srvc = (IICSServices) factory.create(
srvcModel, getCentreInfoURL);
String str= srvc.Execute("", xml);//服务端暴露的接口,C#实现,传入两个参数,
} catch (Exception e) {
e.printStackTrace();
}
---------------IICSServices --------------接口类-------------
public interface IICSServices {
public String Execute(String authentication, String data);
public String Execute(String authentication, Document data);
}
这样调用一直报错,异常大致的意思是服务端或是客户的action为'',或是两者定义的不一致。
接口类就是根据规范写的一点问题没有。在服务端抓包,其实客户端是已经发送过去了,只是xfire在报文里添加了一些多余的信息,同时参数被描述成了in0,in1.
解决方法:
org.codehaus.xfire.client.Client client = null;
try {
client = new org.codehaus.xfire.client.Client(new URL("https://10.4.60.225:8001/ICS/ICSService?wsdl"));
String xml="<?xml version='1.0' encoding='UTF-8'?>" +
"<Data>" +
"<Task BusinessId='' BusinessType='' Orgid='' Businessorgid='' Branchid='' BusinessBranchid=''>"+
"<Input ImageType='' />" +
"<Output ImageType='' />" +
"<Conclusion Status=''></Conclusion>"+
"</Task>" +
"</Data>";
Object[] result1 = client.invoke("Execute", new Object[] {"222",xml});
System.out.println(result1[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
成功,嘿嘿!!!!!!