我已经实现了异步模式服务:WCF异步模式不会引发故障异常
[OperationContract(AsyncPattern = true)]
IAsyncResult BeginLoadDocument(Byte[] value, AsyncCallback callback, object state);
Boolean EndLoadDocument(IAsyncResult asyncResult);
的“BeginLoadDocument”使用线程池运行在服务端的私有方法“回调”:
public IAsyncResult BeginLoadDocument(string id, AsyncCallback callback, object state)
{
PendingAsyncResult<string> asyncResult =
new PendingAsyncResult<string>(id, callback, state);
ThreadPool.QueueUserWorkItem(new WaitCallback(Callback), asyncResult);
return asyncResult;
}
回调方法加载文档并设置“EndLoadDocument”的结果。
到目前为止好,但我如何处理例外?
如果我在服务器端抛出exceling,我得到一个FaultedException'1
没有处理。 我确实尝试使用属性[FaultContract(typeof(InforError))]
,其中“InfoError”是我的Custum DataMember,但它不起作用。
我使用SvcUtil工具构建代理/一个http:...
我的接口作为异步签名: [的ServiceContract] 公共接口IMyService { [OperationContract的(AsyncPattern =真)] IAsyncResult的BeginLoadDocument(字节[]值,AsyncCallback的回调,对象的状态); Boolean EndLoadDocument(IAsyncResult asyncResult); } 我确实在客户端使用Try-Catch,问题出现在服务器端,expect没有处理它。如果我在服务器端使用Try-Catch,客户端永远不会知道异常,如果我不使用try-catch错误停止服务并且客户端没有收到任何东西。 – user429715 2010-08-24 16:18:35
两个客户端都知道IServiceInterface,因此他们应该知道您将写入的ServiceFault。把它放在“常用”或任何你把IServiceInterface放在哪里.. – ilansch 2013-03-28 06:27:48