基于.Net Remoting 的智能客户端架构示例

基于.Net Remoting 的智能客户端架构示例
文件结构展示:
应用程序总体架构图:
eHead.Business
业务逻辑和数据访问
Remoting Server :
描述:是控制台应用程序,负责发布Remoting Service,也可以使用WinFormApplicatino,来实现一些对服务器的管理功能。
SmartClient
 
文件内容:
eHead.Business
Entity文件夹中的OrgDeptData.cs是一个实体类。
 
Service文件夹中的OrgService。
OrgService.cs是OrgDeptData对外部的方法的代理,OrgDeptData的方法通过OrgService向外发布,供客户端调用。
Remoting Server
Program.cs
    static class Program
    {
        ///<summary>
        /// 应用程序的主入口点。
        ///</summary>
        [STAThread]
        static void Main()
        {
            RemotingConfiguration.Configure(
AppDomain .CurrentDomain.SetupInformation.ConfigurationFile, false);
        }
}
App.config
<? xml version = "1.0"encoding="utf-8" ?>
< configuration >
 < system.runtime.remoting >
    < customErrors mode = "off"/>
    < application >
      < service >
        < wellknown mode = "Singleton"type="eHead.Business.qps.Service.OrgService, eHead.Business.qps"objectUri="OrgService" />
      </ service >
      < channels >
        < channel port = "8087"ref="tcp">
          < serverProviders >
            < formatter ref = "soap"typeFilterLevel="Full"/>
            < formatter ref = "binary"typeFilterLevel="Full"/>
          </ serverProviders >
        </ channel >
      </ channels >
    </ application >
 </ system.runtime.remoting >
</ configuration >
SmartClient
App.config
<? xml version = "1.0"?>
< configuration >
 < system.runtime.remoting >
    < application >
      < client >
        < wellknown type = "eHead.Business.qps.Service.OrgService, eHead.Business.qps"url="tcp://localhost:8087/OrgService"/>
      </ client >
      < channels >
        < channel ref = "tcp"port="0">
          < serverProviders >
            < formatter ref = "binary"typeFilterLevel="Full"/>
            < formatter ref = "soap"typeFilterLevel="Full"/>
          </ serverProviders >
        </ channel >
      </ channels >
    </ application >
 </ system.runtime.remoting >
</ configuration >
Program.cs
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application .EnableVisualStyles();
Application .SetCompatibleTextRenderingDefault(true);
RemotingConfiguration .Configure(
AppDomain .CurrentDomain.SetupInformation.ConfigurationFile, false);
}
     ShowLoginForm();
}
ServiceHolder.cs
ServiceHolder 的作用是建立一个单实例的类,客户端其他地方从这里获取服务器端的对象和方法。
    public class ServiceHolder
    {
        public static ServiceHolder Instance = ServiceHolder.CreateInstance();
        public static ServiceHolder CreateInstance()
        {
            if (Instance == null)
            {
                Instance = new ServiceHolder();
            }
            return Instance;
        }
        private OrgService _OrgService = null;
        public OrgService OrgService
        {
            get
            {
                if (this._OrgService == null)
                {
                    this._OrgService = new OrgService();
                }
                return this._OrgService;
            }
        }
}
DeptTree.cs
DeptTree里面加载了一个部门下面的岗位列表。
using System;
using System.Collections.Generic;
using System.Text;
using eHead.Business.qps.Entity.Org;
 
using eHead.UILib;
 
namespace eHead.Module.OrgManagement.UIControls
{
    public class ctlDeptPostTree : ctlDeptTree
    {
        public ctlDeptPostTree()
        {
        }
 
        private void LoadDeptPost(DeptNode deptNode)
        {
            //deptNode.Nodes.Clear();
            List<PostData> postList = ServiceHolder.Instance.OrgService.GetPostListByDept(deptNode.DeptData);   // 这里通过 ServiceHolder 来调用服务器端的方法 .
            foreach (PostData post in postList)
            {
                PostNode node = new PostNode(post);
                deptNode.Nodes.Add(node);
            }
        }
    }
}
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值