首页 > 开发 > 综合 > 正文

IDesign C#编码规范(之九)

2024-07-21 02:18:56
字体:
来源:转载
供稿:网友
国内最大的酷站演示中心!
4.5远程操作 remoting
1.宁可使用管理配置(配置文件)而不使用程序自动配置。
prefer administrator configuration to programmatic configation.
2.总是在单独调用对象里完成idisposable。
always implement idisposable on single call objects.
3.远程操作时总是选用tcp信道和二进制格式
always prefer tcp channel and binary format when using remoting.
a)除非设置了防火墙
unless a firewall is present.
4.总是为一扎对象提供一个null租约。
always provide a null lease for a singleton object.
public class mysingleton : marshalbyrefobject
{
public override object initializelifetimeservice()
{
return null;
}
}
5.总是为客户端激活的对象提供sponsor。这个sponsor应该返回初始租约时刻。
always provide a sponsor for client activated object. the sponsor should return the initial lease time.
a) see chapter 10 of programming .net components.
6.在客户端应用程序停止时总是不要注册sponsor。
always unregister the sponsor on client application shutdown.
7.总是将远程对象放在类库里。
always put remote objects in class libraries.
8.避免使用soapsuds。
avoid using soapsuds.
9.避免宿主iis.
avoid hosting in iis.
10.避免使用单一定向的信道。
avoid using uni-directional channels.
11.总是在main()方法里载入远程配置文件,即使该文件为空。并且该应用程序没有使用远程操作。
always load a remoting configuration file in main() even if the file is empty, and the application does not use remoting.
a)允许在该文件重新定义远程调用,配置信道和改变应用程序发布(添加信道等)等。
allow the option of remoting some types later on, post deployment, and changing the application topology.
static void main()
{
remotingconfiguration.configue(“myapp.exe.config”);
/*rest of main()*/
}
12.避免对远程对象激活时使用activator.getobject() and activator.createinstance()。而是使用new。
avoid using activator.getobject() and activator.createinstance() for remote objects activation. use new instead.
13.总是在客户端注册port(),目的是允许递归调用。
always register port() on the client side, to allow callbacks.
14.总是将客户端和服务器端的类型过滤设置为full,使其可以递归调用。
always elevate type filtering to full on both client and host to allow callbacks.
host config file:
<channels>
<channel ref = “tcp” port = “8005”>
<serverproviders>
<formatter ref = “soap” typefilterlevel = “full”/>
<formatter ref = “binary” typefilterlevel = “full”/>
</serverproviders>
</channel>
<channel ref = “http” port = “8006”>
<serverproviders>
<formatter ref = “soap” typefilterlevel = “full”/>
<formatter ref = “binary” typefilterlevel = “full/”>
</serverproviders>
</channel>
</channels>
client config file:
<channels>
<channel ref = “tcp” port = “0”>
<serverproviders>
<formatter ref = “soap” typefilterlevel = “full”/>
<formatter ref = “binary” typefilterlevel = “full”/>
</serverproviders>
</channel>
</channels>

上一篇:IDesign C#编码规范(之十)

下一篇:C#农历

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表