基于.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);
}
}
}
}





