IDesign C#编码规范(之九)

编码|规范

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>

时间: 2024-09-20 01:05:50

IDesign C#编码规范(之九)的相关文章

IDesign C#编码规范(之三)

编码|规范 续之二,IDesign C#编码规范之三. 34. 避免使用new继承修饰符,而是使用override. Avoid using the new inheritance qualifier. Use override instead. 35. 对非密封类总是将public和protected方法标记为virtual. Always mark public and protected methods as virtual in a non sealed class. 36. 除非涉及到

IDesign C#编码规范(总结)

编码|规范 5资源 Resource5.1 Programming .NET Components By Juval Lowy, O'Reilly 2003 ISBN: 05960034715.2 The .NET Master Class Authored by Juval Lowy, this world acclaimed intense class covers everything, from .NET essentials to the application frameworks

IDesign C#编码规范(之五)

编码|规范 续四,休息天翻得很少,不过总算在keep doing,:-) 4 Framework特别指导 Framework Specific Guidelines 4.1 数据访问 Data Access 1. 总是使用类型安全的数据集或者数据表.避免使用原始的ADO.NET. Always use type-safe data sets or data tables . Avoid raw ADO.NET. 2. 访问数据库时总是使用事务. Always use transactions w

IDesign C#编码规范(之十)

编码|规范 4.6安全 Security1.总是使用强名称发布代码,该名称对于该应用程序而言是私有的,对于你是公有的.Always demand your own strong name on assemblies and components that are private to the application, but are public(so that only you use them).public class PublicKeys{public const string MyCo

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

编码|规范 4.7企业服务Enterprise Service1.在事务方法里不要捕捉异常.要用AutoComplete属性.Do not catch exceptions in a transactional method. Use the AutoComplete attribute.a) See Chapter 4 in COM and .NET Component Services.2.不要调用SetComplete(), SetAbort(),以及相关方法.要用AutoComplete

IDesign C#编码规范(之六)

编码|规范 大家中秋好,首先非常感谢xiaxia翻译的资料.由于我对这个文档也是兴趣浓厚,所以就把下面的部分给翻译了.希望大家多多指教. 4.2ASP.NET and Web Services1.避免将代码放入ASP.NET的ASPX文件中. 所有的代码都应该放在相关代码的Partial类中.Avoid putting code in ASPX files of ASP.NET. All code should be in the code beside partial class.2.放在相关

IDesign C#编码规范(之七)

编码|规范 4.3序列化 Serialization1.总是标记未封装的类为[Serializable]Always mark non-sealed classes as serializable.2.总是标记未序列化的成员变量为[non-serializable]Always mark un-serializable member variables as non-serializable.3.总是标记序列化类中的委托为[NonSerialized]Always mark delegates

IDesign C#编码规范(之八)

编码|规范 4.4多线程 Multithreading1.应用同步机制空间.Use Synchronization Domains. See Chapter 8 in Programming .NET Components.避免手工的同步机制,应为这样容易导致死锁和竞态条件.a) Avoid manual synchronization because that often leads to deadlocks and race conditions.2.永远不要在外部调用你的同步机制空间.Ne

请问有关c#编码规范

问题描述 我用C#写的服务器端程序接受C#写的客户端程序传来的字符时候是正确的可是用DELPHI写的客户端程序传来的时候就显示为乱码请问我该怎么解决?谢谢 解决方案 解决方案二:DELHPI里面可不可以按Unicode或者Ascii解码?如果不方便的话,可以在C#发数据前换一种Delphi默认的编码方式解决方案三:编码方式不同.最好都用Unicode解决方案四:引用2楼liyinlei的回复: 编码方式不同.最好都用Unicode 同意!!解决方案五:我的代码是这样的,请问我应该如何修改啊,谢谢