日期:2014-05-17  浏览次数:20978 次

Hessian实现C#语言开发winforms前端+sshj2ee后台服务(二、C#客户端)

接下来实现jsp和struts测试项目功能,一切成功后,正式启动tomcat6.0,让服务运行。

下面开始做客户端 (C# winforms)
客户端Model层

?

namespace ClientDemo.Models
{
    [Serializable()]

    public class PosInfo
    {
        private string posid;

        public string Posid
        {
            get { return posid; }
            set { posid = value; }
        }
        private string posname;

        public string Posname
        {
            get { return posname; }
            set { posname = value; }
        }
        private string lmodifydate;

        public string Lmodifydate
        {
            get { return lmodifydate; }
            set { lmodifydate = value; }
        }

    }
}

?

?

创建调用Hessian服务的C#接口

?

namespace ClientDemo.DAL
{

    using ClientDemo.Models;

    public interface IPosService
    {


         void savePosition(PosVO vo);

         void updatePosition(PosVO vo);

         PosInfo queryPositionById(String posId);

         void deletePosition(String posId);

         List<PosInfo> queryPositions();


         string test(string s);

    }

}

?

?

调用Hessian服务的封装类

?

namespace ClientDemo.DAL
{
    using hessiancsharp.client;

    public class PosInfoService
    {

        //获取服务
        public static IPosService GetService()
        {

            IPosService reService = null;

            CHessianProxyFactory factory = new CHessianProxyFactory();

            string url = "http://localhost:8080/*/remote/HessianService";

            reService = (IPosService)factory.Create(typeof(IPosService), url);

            return reService;

        }
    }
}

?

?

BLL层的服务处理

?

namespace ClientDemo.BLL
{

    using ClientDemo.DAL;
    using ClientDemo.Models;

    public static class PosInfoManager
    {


        //增
        public static void AddNewPos(PosVO posVO) {

            PosInfoService.GetService().savePosition(posVO);
        
        }

        //删
        public static void DelPosById(PosVO posVO) {
            PosInfoService.GetService().deletePosition(posVO.Posid);
        }

        //改
        public static void UpdatePos(PosVO posVO){
            PosInfoService.GetService().updatePosition(posVO);
        }

        //查
        public static PosInfo GetPosById(PosVO posVO){
        
            return PosInfoService.GetService().queryPositionById(posVO.Posid);

        }

        //全查
        public static List<PosInfo> GetAllPos(){
        
            List<PosInfo> list=null;

            list=PosInfoService.GetService().queryPositions();

            return list;
        }
    }
}

?

?

客户端运行演示效果

?



?