主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:179次
4.7企业服务Enterprise Service
1.在事务方法里不要捕捉异常。要用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属性。
Do not call SetComplete(), SetAbort(), and the like. Use the AutoComplete attribute.
[Transaction]
public class MyComponent : ServicedComponent
{
[AutoComplete]
public void MyMethod(long objectIdentifier)
{
GetState(objectIdentifier);
DoWork();
SaveState(objectIdentifier);
}
}
3.总是覆写CanBePooled方法并且返回true(除非你有更好的原因不用返回值到池)。
Always override CanBePooled and return true(unless you have a good reason not to return to pool).
Public class MyComponent : ServicedComponent
{
protected override bool CanBePooled()
{
return true;
}
}
4.总是在对象池里显示地调用Dispose(),除非该组件已被配置为使用JITA。
Always call Dispose() explicitly on a pooled objects unless the component is configured to use JITA as well.
5.当组建使用JITA时不可调用Dispose()。
Never call Dispose() when the components uses JITA.
6.总是为应用程序和组件设置权限水平。
Always set authorization level to application and component.
7.将所有应用程序的检证水平设置为私有。
Set authentication level to privacy on all applications.
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(
true, //Authorization
AccessChecksLevel = AccessChecksLevelOption.ApplicationComponent,
Authentication = AuthenticationOption.Privacy,
ImpersonationLevel = ImpersonationLevelOption.Identify)]
8.将客户端程序集的角色水平设置为Identity。
Set impersonation level on client assemblies to Identity.
9.总是将可服务组件的ComponentAccessControl属性设置为true。
Always set ComponentAccessControl attribute on serviced components to true.
a)The default is true
[ComponentAccessControl]
public class MyComponent : ServicedComponent
{…}
10.总是将每一个用户角色设置为marshaler。
Always add to the marshaler role the Everyone user.
[assembly: SecureRole(“Marshaler”, SetEveryoneAccess = true)]
11.应用SecureMethod属性于所有的要求检证的类。
Apply SecureMethod attribute to all classes requiring authentication.
[SecurityMethod]
public class MyComponent : ServicedComponent
{…}
关键字词: