【问题标题】:Is the callback from WCF to ASP.NET possible?从 WCF 到 ASP.NET 的回调可能吗?
【发布时间】:2011-04-18 20:00:53
【问题描述】:
我有一个托管在 IIS 中的不同盒子中的 Web 服务和托管在 Windows 服务中的 WCF 服务,在不同的盒子中。(N 层方法)。这里,Web 服务是 WCF 服务的客户端。上传文件的请求来自 IIS 托管的 Web 服务,而这个 IIS 托管的 Web 服务反过来调用 WCF 服务并进行实际的上传。到目前为止,一切都很好。上传完成后,WCF 服务执行回调(我已将回调存储在字典中,并且我使用过 (InstanceContextMode=InstanceContextMode.PerSession, ConcurrencyMode=ConcurrencyMode.Multiple))。 WCF 服务发送回调。在跟踪查看器中,看起来 ASP.NET 收到了回调,但浏览器中的上传页面(这是最终用户)永远冻结了。
我正在使用 larsw 的 ChunkingChannel 绑定。
首先,是否有可能实现上述情景,正如约翰桑德斯在此链接中提到的那样:
What does "OperationContext.Current.GetCallbackChannel" actually do?
感谢您的帮助。
【问题讨论】:
标签:
wcf
channel
chunking
wcf-callbacks
【解决方案1】:
不确定您所说的“冻结”是什么意思,只是它没有更新还是没有响应。
可能是在响应从 wcf 服务返回到 Web 服务器之前,将 asp 页面的响应发送到浏览器。在这种情况下,当服务返回结果时,asp 页面不会得到更新。
你有两个选择:
- 使用 javascript 轮询服务器以进行更改。
- 在收到服务响应之前阻止上传页面的返回。
如果您最终等待回调,那么只做一个请求响应样式会更简单。
另一个常见问题是客户端上的 wcf 代理在收到回调之前关闭。跟踪会显示它回来了,但没有人在听。
【解决方案2】:
很奇怪,我重新启动了计算机,现在在客户端 (ASP.NET) 端的 Trace 查看器中得到以下内容,而且页面现在没有冻结(无响应)。我最关心的消息是它的内部异常:System.NullReferenceException, mscorlib 并说 Object reference not...
我尝试使用控制台应用程序作为 WCF 服务的客户端。回调效果很好。只有当我在 IIS 中托管我的网站并调用 WCF 服务来上传文件时(作为回报,它会回调客户端以通知上传成功/不成功)。
(我正在使用 HttpChunkingBinding)。
有什么想法吗?
System.Runtime.FatalException,
System.Runtime.DurableInstancing,版本=4.0.0.0,文化=中性,
PublicKeyToken=31bf3856ad364e35 对象
引用未设置为对象的实例。
在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&
RPC)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&
rpc) 在 System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
isOperationContextSet) 在
System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext
请求,布尔型 cleanThread,OperationContext
当前操作上下文)在
System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext
请求,OperationContext currentOperationContext)在
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult
结果)在
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult
结果)在
System.ServiceModel.Diagnostics.TraceUtility.c_DisplayClass4.b_2(AsyncCallback
回调,IAsyncResult 结果)在
System.Runtime.AsyncResult.Complete(布尔完成同步)在
System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at
System.Runtime.InputQueue1.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(布尔
同步完成)在
System.ServiceModel.Channels.ReliableChannelBinder1.InputAsyncResult1.OnInputComplete(IAsyncResult
结果)在
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult
结果)在
System.ServiceModel.Diagnostics.TraceUtility.c_DisplayClass4.b_2(AsyncCallback
回调,IAsyncResult 结果)在
System.Runtime.AsyncResult.Complete(布尔完成同步)在
System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at
System.Runtime.InputQueue1.Dispatch() 在
System.Runtime.ActionItem.DefaultActionItem.Invoke() 在
System.Runtime.ActionItem.CallbackHelper.InvokeWithoutContext(对象
州)在
System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32
errorCode,UInt32 numBytes,NativeOverlapped* nativeOverlapped) 在
System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32
错误,UInt32 bytesRead,NativeOverlapped* nativeOverlapped) 在
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode、UInt32 numBytes、NativeOverlapped* pOVERLAP)
System.Runtime.FatalException:对象引用不
设置为对象的实例。 --->
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) --- 内部异常堆栈跟踪结束 --- at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&
RPC)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&
rpc) 在 System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
isOperationContextSet) 在
System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext
请求,布尔型 cleanThread,OperationContext
当前操作上下文)在
System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext
请求,OperationContext currentOperationContext)在
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult
结果)在
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult
结果)在
System.ServiceModel.Diagnostics.TraceUtility.c_DisplayClass4.b_2(AsyncCallback
回调,IAsyncResult 结果)在
System.Runtime.AsyncResult.Complete(布尔完成同步)
在 System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at
System.Runtime.InputQueue1.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(布尔
同步完成)在
System.ServiceModel.Channels.ReliableChannelBinder1.InputAsyncResult1.OnInputComplete(IAsyncResult
结果)在
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult
结果)在
System.ServiceModel.Diagnostics.TraceUtility.c_DisplayClass4.b_2(AsyncCallback
回调,IAsyncResult 结果)在
System.Runtime.AsyncResult.Complete(布尔完成同步)
在 System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at
System.Runtime.InputQueue1.Dispatch() 在
System.Runtime.ActionItem.DefaultActionItem.Invoke() 在
System.Runtime.ActionItem.CallbackHelper.InvokeWithoutContext(对象
州)在
System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32
errorCode,UInt32 numBytes,NativeOverlapped* nativeOverlapped) 在
System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32
错误,UInt32 bytesRead,NativeOverlapped* nativeOverlapped) 在
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode,UInt32 numBytes,NativeOverlapped*
重叠)
System.NullReferenceException,mscorlib,
版本=4.0.0.0,文化=中性,
PublicKeyToken=b77a5c561934e089 对象
引用未设置为对象的实例。
在 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) 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)