2010-06-02 17 views
11

我有一个使用DualHttpBindings回调的wcf服务。该服务发现它们时将客户端的搜索结果的数据集推回(长时间运行搜索)。更新到.net 4.0后wcf回调异常

这在.net 3.5中正常工作。自从我更新到.NET 4.0后,它就会抛出一个System.Runtime.FatalException,它实际上会杀死IIS工作进程。我不知道如何去解决这个问题。任何建议的赞赏。

从所得事件日志的信息被粘贴在下面:


发生未处理的异常和 过程被终止。

应用程序ID:/ LM/W3SVC/2/ROOT/CP

进程ID:5284

>例外: System.Runtime.FatalException

>信息:对象引用未设置为 对象的实例。

堆栈跟踪:在在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc & RPC) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc & RPC)在 System.ServiceModel.Dispatcher .MessageRpc.Process(布尔型 isOperationContextSet)at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request,Boolean cleanThread, OperationContext currentOperationContext)在 System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext的 请求,的OperationContext currentOperationContext)在 System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult的 结果)在 System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame (IAsyncResult的 结果)在 System.Runtime.AsyncResult.Complete(布尔 completedSynchronously)在 System.Runtime.InputQueue 1.AsyncQueueReader.Set(Item item) at System.Runtime.InputQueue 1.Dispatch() 在 System.ServiceModel.Channels.ReliableDuplexSessionChannel.ProcessDuplexMessage(WsrmMessageInfo 信息)在 System.ServiceModel.Channels.ReliableDuplexSessionChannel.HandleReceiveComplete(IAsyncResult的 结果)在 System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnReceiveCompletedStatic在 系统(IAsyncResult的 结果)在 System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult的 结果) .Runtime.AsyncResult.Complete(布尔 completedSynchronously)在 System.ServiceModel.Channels.ReliableChannelBinder 1.InputAsyncResult 1.OnInputComplete(IAsyncResult的 结果)在 System.Runtime.Fx.AsyncThunk。UnhandledExceptionFrame(IAsyncResult的 结果)在 System.Runtime.AsyncResult.Complete(布尔 completedSynchronously)在 System.Runtime.InputQueue 1.AsyncQueueReader.Set(Item item) at System.Runtime.InputQueue 1.Dispatch() 在 System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32的 的errorCode, UInt32的的numBytes, nativeOverlapped * nativeOverlapped)
在 System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32的 错误,UInt32的bytesRead, nativeOverlapped * nativeOverlapped)
在 System.Threading._IOCompletionCa llback.PerformIOCompletionCallback(UInt32的 的errorCode,UInt32的的numBytes, NativeOverlapped * pOVERLAP)

>的InnerException: > System.NullReferenceException

消息:对象没有设置为 的一个实例目的。

堆栈跟踪:在 System.Web.HttpApplication.ThreadContext.Enter(布尔 setImpersonationContext)在 System.Web.HttpApplication.OnThreadEnterPrivate在 System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(布尔 setImpersonationContext)(SendOrPostCallback 在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc回调,对象状态)在 System.Web.AspNetSynchronizationContext.CallCallback(SendOrPostCallback 回调,对象状态) rpc)

回答

15

好的 - 我找到了答案。很奇怪,但简单地把下列属性的WCF回调包装类:

[CallbackBehavior(UseSynchronizationContext=false)] 

感谢Cauldwell.net的答案:http://www.cauldwell.net/patrick/blog/CategoryView,category,CodeGen.aspx

从cauldwell.net:

问题,事实证明,是ASP.NET使用(默认)一点点 东西叫做 SynchronizationContext。尽量靠近我 可以告诉(我没有研究这个 彻底,说实话),它的一个 工作是确保任何 回调拿到UI线程上运行, 从而无需调用 控制。像在 WinForms中那样调用。在我的情况下,额外的 锁给了一些适合的东西,它 试图清理一个 线程,而不是更多, 因此NullReferenceException。

+0

+1票。感谢詹姆斯,你节省了我的时间:) – 2012-06-19 05:17:28

+0

这样做的伎俩!尽管我的场景与文章有点不同,因为在调用回调方法之前抛出异常。 – Jan 2016-11-16 15:53:33