C#调用java服务端hessian,传递对象的时候可以使用hashtable来代替,但是hashtable里包含一组对象集合的时候传递就会出现问题。代码如下: public interface productApi
{
//传递一个对象,用Hashtable代替
string setTrade(Hashtable trade);
}
Hashtable trade = new Hashtable();
//Hashtable item = new Hashtable();
ArrayList al = new ArrayList();
// ClassItem是一个类
ClassItem it = new ClassItem();
//设置类的颜色属性或者使用hashtable的方式
it.color = "white";
//item.Add("color", "white");
al.Add(it);
trade.Add("items", al); CHessianProxyFactory factory = new CHessianProxyFactory();
string url = "http://10.0.1.148/hessian/api/productApi";
productApi test = (productApi)factory.Create(typeof(productApi), url);
//传递一个trade对象,包含一组对象集合al,al
MessageBox.Show(test.setTrade(trade));会报错:不能将hashmap转换为item(item是java那边的对象,我第一层的hashtable可以转换为对象,第二层就无法转换了,我直接传递对象进去也是一样的错误)
{
//传递一个对象,用Hashtable代替
string setTrade(Hashtable trade);
}
Hashtable trade = new Hashtable();
//Hashtable item = new Hashtable();
ArrayList al = new ArrayList();
// ClassItem是一个类
ClassItem it = new ClassItem();
//设置类的颜色属性或者使用hashtable的方式
it.color = "white";
//item.Add("color", "white");
al.Add(it);
trade.Add("items", al); CHessianProxyFactory factory = new CHessianProxyFactory();
string url = "http://10.0.1.148/hessian/api/productApi";
productApi test = (productApi)factory.Create(typeof(productApi), url);
//传递一个trade对象,包含一组对象集合al,al
MessageBox.Show(test.setTrade(trade));会报错:不能将hashmap转换为item(item是java那边的对象,我第一层的hashtable可以转换为对象,第二层就无法转换了,我直接传递对象进去也是一样的错误)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货