在主项目中添加Hessiancsharp.dll引用。
  测试代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using hessiancsharp.client;
using hessian.test.server;
namespace HessianClientTest
{
class Program
{
static void Main(string[] args)
{
string url = @"http://localhost:8080/HessianServerTest/hessian";
CHessianProxyFactory factory = new CHessianProxyFactory();
IHello test = (IHello)factory.Create(typeof(IHello), url);
//Test function
Console.WriteLine(test.sayHello("lu"));   //打印从服务器端获取的字符串
test.sayHello2(12);                       //在服务器端控制台打印 "Hello 12"
test.print("hessian");                    //在服务器端控制台打印 "hessian"
//Test Object
HelloBean bean = new HelloBean();
//bean.setName("lu xiaoxun");
bean.Name = "luxiaoxun";
HelloBean result = test.getData(bean);
Console.WriteLine(result.Name);
Console.WriteLine(result.Age);
Console.WriteLine(result);
//Test Object Array
HelloBean[] beans = test.getBeanList();
if (beans != null)
{
foreach (HelloBean data in beans)
{
Console.WriteLine(data.ToString());
}
}
//Test complex data
ComplexData complexData = test.getComplexData();
if (complexData != null)
{
Console.WriteLine("Array number: " + complexData.GetNumber());
HelloBean[] comArray = complexData.GetBeans();
if (comArray != null)
{
foreach (HelloBean data in comArray)
{
Console.WriteLine(data.ToString());
}
}
//Dictionary<String, HelloBean> helloBeanMap = complexData.GetBeansDic();
//if (helloBeanMap != null)
//{
//    foreach (String key in helloBeanMap.Keys)
//    {
//        Console.WriteLine(helloBeanMap[key].GetHelloBeanInfo());
//    }
//}
}
Console.ReadKey();
}
}
}
  测试结果:

  注意事项:
  1、服务端和客户端用于数据传递的对象的命名空间要一致
  IHello接口所在命名空间服务端和客户端可以不一致,但是IHello中用到的HelloBean和ComplexData在Java服务端和C#客户端中两个HelloBean类所在的命名空间要一致。
  2、类的字段要一致
  用于数据传输的类的字段名和字段类型要一致(修饰类型可以不一致)。
  3、服务端的类要序列化
  4、尽量使用基本的数据类型
  从上面的测试可以看出,传递基本的类型没有问题,传递普通的类对象没有问题,传递ArrayList的时候也没有问题(C#客户端使用Array数组),但是传递HashMap字典的时候会有问题,C#这边使用Dictionary没法对应一致,可能是由于hash函数内部实现不一致导致的,具体原因不明。