我有一个使用回调与DualHttpBindings WCF服务。该服务推回搜索一个DataTable导致客户端(长期运行搜索),因为它找到它们。
这在.NET 3.5中运行良好。因为我更新到.NET 4.0,它弹了一个System.Runtime.FatalException实际上杀死了IIS工作进程。我不知道如何,甚至着手开始解决这个问题。任何建议AP preciated。
从产生的事件日志的信息被粘贴如下:
发生和未处理的异常 该过程终止。
应用程序ID:/ LM / W 3 SVC / 2 / ROOT / CP
进程ID:5284
>例外: System.Runtime.FatalException
>消息:对象引用未设置为 一个对象的一个实例。
堆栈跟踪:在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&安培;
RPC)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&安培;
RPC)在
System.ServiceModel.Dispatcher.MessageRpc.Process(布尔
isOperationContextSet)在
System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(的RequestContext
要求,布尔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(项目
项目)在
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的
结果)的
System.Runtime.AsyncResult.Complete(布尔
completedSynchronously)在
System.ServiceModel.Channels.ReliableChannelBinder1.InputAsyncResult1.OnInputComplete(IAsyncResult
结果)的
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult的
结果)的
System.Runtime.AsyncResult.Complete(布尔
completedSynchronously)在
System.Runtime.InputQueue 1.AsyncQueueReader.Set(项目
项目)在
System.Runtime.InputQueue
1.Dispatch()
在
System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32的
错误code,UInt32的的numBytes,
NativeOverlapped * nativeOverlapped)
在
System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32的
错误,UInt32的读取动作,
NativeOverlapped * nativeOverlapped)
在
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32的
错误code,UInt32的的numBytes,
NativeOverlapped * pOVERLAP)
>的InnerException: *的> System.NullReferenceException 的*
信息:对象引用未设置为 一个对象的一个实例
堆栈跟踪:在 System.Web.HttpApplication.ThreadContext.Enter(布尔 setImpersonationContext)在 System.Web.HttpApplication.OnThreadEnterPrivate(布尔 setImpersonationContext)在 System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback 回调,对象的状态)的 System.Web.AspNetSynchronizationContext.CallCallback(SendOrPostCallback 回调,对象的状态)的 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&安培; RPC)
解决方案确定 - 我找到了答案。很奇怪,只是把下面的属性上的WCF回调包装类:
[CallbackBehavior(UseSynchronizationContext = FALSE)]
感谢Cauldwell.net的回答:http://www.cauldwell.net/patrick/blog/CategoryView,category,$c$cGen.aspx
从cauldwell.net:
这个问题,它的横空出世,是 ASP.NET使用(默认)一个小 所谓的东西 的SynchronizationContext。尽可能接近我 可以告诉(我没有研究这个 彻底,说实话),它的一个 它的工作,以确保任何 回调得到运行在UI线程上, 从而避免了需要调用 Control.Invoke就像你在做 的WinForms。在我的情况下,额外的 锁被给予适合的东西,它 试图清理东西了一 跟帖说是周围没有任何更多的, 因此,要NullReferenceException异常。
I have a wcf service that uses callbacks with DualHttpBindings. The service pushes back a datatable of search results the client (for a long running search) as it finds them.
This worked fine in .Net 3.5. Since I updated to .Net 4.0, it bombs out with a System.Runtime.FatalException that actually kills the IIS worker process. I have no idea how to even go about starting to fix this. Any recommendations appreciated.
The info from the resulting event logs is pasted below:
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.InputQueue
1.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.InputAsyncResult
1.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.InputQueue
1.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)
解决方案
OK - I found the answer. Very Strange, but simply put the following attribute on the WCF callback wrapper class:
[CallbackBehavior(UseSynchronizationContext=false)]
Thanks to Cauldwell.net for the answer: http://www.cauldwell.net/patrick/blog/CategoryView,category,CodeGen.aspx
From 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.