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

本文介绍了一种基于.Net Remoting技术实现的智能客户端架构。该架构分为业务逻辑层、数据访问层及客户端层,通过配置文件定义了服务端与客户端的连接方式,并实现了部门及其下属岗位的数据展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于.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
<?xmlversion="1.0"encoding="utf-8" ?>
<configuration>
 <system.runtime.remoting>
    <customErrorsmode="off"/>
    <application>
      <service >
        <wellknownmode="Singleton"type="eHead.Business.qps.Service.OrgService, eHead.Business.qps"objectUri="OrgService" />
      </service>
      <channels>
        <channelport="8087"ref="tcp">
          <serverProviders>
            <formatterref="soap"typeFilterLevel="Full"/>
            <formatterref="binary"typeFilterLevel="Full"/>
          </serverProviders>
        </channel>
      </channels>
    </application>
 </system.runtime.remoting>
</configuration>
SmartClient
App.config
<?xmlversion="1.0"?>
<configuration>
 <system.runtime.remoting>
    <application>
      <client>
        <wellknowntype="eHead.Business.qps.Service.OrgService, eHead.Business.qps"url="tcp://localhost:8087/OrgService"/>
      </client>
      <channels>
        <channelref="tcp"port="0">
          <serverProviders>
            <formatterref="binary"typeFilterLevel="Full"/>
            <formatterref="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);
            }
        }
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值