Welcome

首页 / 软件开发 / WCF / WCF服务编程设计规范(4):操作与错误设计

WCF服务编程设计规范(4):操作与错误设计2012-02-23 博客园 Frank Xu LeiWCF服务编程设计规范(4):操作与错误设计。主要包含服务操作与调用、错误设计规范。中英对照。欢迎留言交流。下一节会介绍事务、并发管理和队列服务的内容。

Operations and Calls

操作与调用

1. Do not treat one-way calls as asynchronous calls.

不要把单向调用作为异步调用

2. Do not treat one-way calls as concurrent calls.

不要把单向调用作为并发调用

3. Expect exceptions from a one-way operation.

单向操作也应该返回异常

4. Enable reliability even on one-way calls. Use of ordered delivery is optional for one way calls.

即使当单向调用的时候,也要启用可靠性。单向调用不必使用有序传递。

5. Avoid one-way operations on a sessionful service. If used, make it the terminating operation:

避免在会话服务里使用单向调用。如果用到,作为结束操作。

[ServiceContract(SessionMode = SessionMode.Required)]
interface IMyContract
{
[OperationContract]
void MyMethod1();
[OperationContract(IsOneWay = true,IsInitiating = false,IsTerminating =true)]
void MyMethod2();
}

6. Name the callback contract on the service side after the service contract name, suffixed by Callback:

回调操作最好使用服务契约的名字加后缀Callback

interface IMyContractCallback
{...}
[ServiceContract(CallbackContract = typeof(IMyContractCallback))]
interface IMyContract
{...}

7. Strive to mark callback operations as one-way.

回调操作标记会单向操作