.net - 更新到 .net 4.0 后 wcf 回调异常

标签 .net wcf iis exception

我有一个 wcf 服务,它使用 DualHttpBindings 的回调。该服务在找到它们时将搜索结果的数据表推送回客户端(用于长时间运行的搜索)。

这在 .Net 3.5 中运行良好。自从我更新到 .Net 4.0 后,它会以 System.Runtime.FatalException 的形式爆炸,实际上杀死了 IIS 工作进程。我什至不知道如何着手解决这个问题。任何建议表示赞赏。

生成的事件日志中的信息粘贴在下面:

An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/2/ROOT/CP

Process ID: 5284

> Exception: System.Runtime.FatalException

> Message: Object reference not set to an instance of an object.

StackTrace: at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at System.Runtime.InputQueue1.Dispatch() at System.ServiceModel.Channels.ReliableDuplexSessionChannel.ProcessDuplexMessage(WsrmMessageInfo info) at System.ServiceModel.Channels.ReliableDuplexSessionChannel.HandleReceiveComplete(IAsyncResult result) at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnReceiveCompletedStatic(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.ServiceModel.Channels.ReliableChannelBinder1.InputAsyncResult1.OnInputComplete(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at System.Runtime.InputQueue1.Dispatch() at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

> InnerException: > System.NullReferenceException

Message: Object reference not set to an instance of an object.

StackTrace: at System.Web.HttpApplication.ThreadContext.Enter(Boolean setImpersonationContext) at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) at System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) at System.Web.AspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)

最佳答案

好的 - 我找到了答案。很奇怪,但只需将以下属性放在 WCF 回调包装器类上:

[CallbackBehavior(UseSynchronizationContext=false)]

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

来自 cauldwell.net:

The problem, it turned out, was that ASP.NET uses (by default) a little thing called the SynchronizationContext. As near as I can tell (I haven't researched this thoroughly, to be honest) one of it's jobs it to make sure that any callbacks get run on the UI thread, thereby obviating the need to call Control.Invoke like you do in WinForms. In my case, that additional lock was giving something fits, and it was trying to clean stuff up on a thread that wasn't around any more, hence to NullReferenceException.

关于.net - 更新到 .net 4.0 后 wcf 回调异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2959704/

相关文章:

wcf - 无法解析符号 'Point'、 'Size'、 'PointCollection'

c# - 在一台服务主机中托管多个服务?

c# - 如何拦截来自 WCF 客户端的 header ...?

c# - ASP.NET 2.0-4.0 Web 应用程序的初始启动速度极慢。

c# - RxExp 匹配第一个标签

C# :Unity container and ILogger

.net - 如何将大文件从桌面传输到服务器 (.NET)

c# - 使用 System.IO.Directory.Delete 删除目录

asp.net - 如何防止在不登录网站的情况下访问虚拟目录

asp.net-mvc - 使用 .net mvc 在 IIS angular 2 应用程序上发布