using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using hessiancsharp.client;
namespace HessianTest
{
using f.studio.domain;
using System.Threading;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
CHessianProxyFactory factory = new CHessianProxyFactory("userName", "password");
string url = "http://localhost/HessianTest/rpc/studentServiceRpc";//修改为你的server端地址
StudentService test = (StudentService)factory.Create(typeof(StudentService), url);
string result = test.hello("大白鲨");
var q = new QueryStudentInfo() { BTime = DateTime.Now, Name = "哈哈", Id = 1888, Sex = false };
q.Data = new byte[] { 5, 4, 3, 2, 1 };
q.CreateDate = DateTime.Now;
q.RecId = 99999;
var list = test.query(q);
foreach (var it in list)
{
Console.WriteLine(it);
}
Console.WriteLine(result);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
namespace f.studio.domain
{
public class BaseInfo
{
private DateTime? createDate;
public DateTime? CreateDate
{
get { return createDate; }
set { createDate = value; }
}
private long? recId;
public long? RecId
{
get { return recId; }
set { recId = value; }
}
}
/// <summary>
/// 上传时用需要保持命名空间与服务器一致
/// </summary>
public class QueryStudentInfo :BaseInfo
{
private int id;
private String name;
private DateTime? btime;
private Byte[] data;
private bool sex;
public int Id
{
get { return id; }
set { id = value; }
}
public DateTime? BTime
{
get { return btime; }
set { btime = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public Byte[] Data
{
get { return data; }
set { data = value; }
}
public bool Sex
{
get { return sex; }
set { sex = value; }
}
}
/// <summary>
/// 不能使用public int Id{get;set;}
/// private 字段名称,大小写需要跟服务端定义一致
/// [Serializable]标记貌似不是必须的
/// </summary>
public class Klass :BaseInfo
{
private int id;
private String name;
private DateTime? addTime;
public DateTime? AddTime
{
get { return addTime; }
set { addTime = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public int Id
{
get { return id; }
set { id = value; }
}
}
public class StudentInfo :BaseInfo
{
private string name;
private bool? sex;
private long id;
private byte[] fileData;
public byte[] FileData
{
get { return fileData; }
set { fileData = value; }
}
private List<Klass> ks;
public List<Klass> Ks
{
get { return ks; }
set { ks = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public long Id
{
get { return id; }
set { id = value; }
}
public bool? Sex
{
get { return sex; }
set { sex = value; }
}
public override string ToString()
{
return string.Format("Id:{0},Name:{1},Sex:{2},RecId:{3},CreateDate:{4}", Id, Name, Sex,RecId,CreateDate);
}
}
}
View Code
完成服务端代码下载