2011-11-14 31 views
1

我正在通过Windows Phone(7.0,7.1 SDK)对ASP.NET进行WCF调用。在某些情况下(我无法在模拟器或我的任何设备上实现这种情况),未处理的异常处理程序触发其中一个调用中发生的异常(说明 - 全部在客户端 - 不在服务器上) 。我看到了这种情况(他们发生了很多)。我以前从未遇到过这个问题(不是旧版本,也不是其他使用相同WCF代理代码的应用程序)。WCF异步调用引发了异常,它发送到未处理的异常处理程序 - 我的代码在调用堆栈中没有任何代码

有没有人有任何想法为什么发生这种情况,以及如何?我能做些什么来解决它?

这种情况正在发生的第一个调用堆栈是:

System.ServiceModel.ProtocolException: The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 75 bytes of the response were: 'The page cannot be displayed because an internal server error has occurred.'. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at  
System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at  
System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass2.<EndGetResponse>b__1(Object sendState) at  
System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState) at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at  
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at  
System.Delegate.DynamicInvokeOne(Object[] args) at  
System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at  
System.Windows.Threading.Dispatcher.<>c__DisplayClass4.<FastInvoke>b__3() at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at  
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at  
System.Delegate.DynamicInvokeOne(Object[] args) at  
System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at  
System.Windows.Threading.DispatcherOperation.Invoke() at  
System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority) at  
System.Windows.Threading.Dispatcher.OnInvoke(Object context) at  
System.Windows.Hosting.CallbackCookie.Invoke(Object[] args) at  
System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)  at  
System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at  
System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result) at  
System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2) at  
System.Threading.ThreadPool.WorkItem.doWork(Object o) at  
System.Threading.Timer.ring()  at  
System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.ProcessResponse(HttpWebResponse response, WebException responseException) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result) at  
System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2)  

这是发生在第二个回调:

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at  
http://MyServer.com/Fail/FailService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at  
System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at  
System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass2.<EndGetResponse>b__1(Object sendState) at  
System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState) at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at  
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at  
System.Delegate.DynamicInvokeOne(Object[] args) at  
System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at  
System.Windows.Threading.Dispatcher.<>c__DisplayClass4.<FastInvoke>b__3() at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at  
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at  
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at  
System.Delegate.DynamicInvokeOne(Object[] args) at  
System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at  
System.Windows.Threading.DispatcherOperation.Invoke() at  
System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority) at  
System.Windows.Threading.Dispatcher.OnInvoke(Object context) at  
System.Windows.Hosting.CallbackCookie.Invoke(Object[] args) at  
System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)  at  
System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at  
System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result) at  
System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2) at  
System.Threading.ThreadPool.WorkItem.doWork(Object o) at  
System.Threading.Timer.ring()  at  
System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) at  
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result) at  
System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2) at  
System.Threading.ThreadPool.WorkItem.doWork(Object o) at  
System.Threading.Timer.ring()  

回答

1

它看起来像你的Web服务器/服务可能是由于可能崩溃未处理的例外。我会检查Web服务器上的事件日志,以查看是否存在IIS正在报告崩溃的情况。

更新澄清问题

正如我现在明白了这个问题,问题是,如果Web服务已关闭,WCF服务的提高,只能在未处理的异常处理程序捕获的异常。

我从来没有遇到这种行为,但我明白为什么会发生并有可能的解决方案。 WCF服务请求异步触发,因此实际的连接和处理发生在线程中,您可以在您的调用堆栈中看到该线程。

如果钩住了异步方法的完成事件,则该异常应该在参数中传递给该事件处理程序,而不是被抛出。我相信只有在没有处理程序时才会抛出异常,因为框架不知道如何处理异常。

+0

这不是问题(服务器实际上是关闭 - 没有抛出异常) - 问题是**客户端**有一个未处理的异常,它不能在任何地方捕获,但未处理的异常处理程序 - 这不是这个应该管用。 –

+0

澄清了这个问题。谢谢回答。 –

+0

附加信息: –