How to catch exeption EndpointNotFoundExeption was unhandled when i disconnect the internet? (using Bing Search API )

Answered How to catch exeption EndpointNotFoundExeption was unhandled when i disconnect the internet? (using Bing Search API )

  • Tuesday, May 22, 2012 4:10 AM
     
      Has Code

    My simple code:

    SearchRequest req = new SearchRequest();
    
    req.AppId = "My Bing API Key";
    req.Query = "msdn ";
    req.Sources = new SourceType[] { SourceType.Web };
    
    BingPortTypeClient service = new BingPortTypeClient();
                    
    service.SearchCompleted += new EventHandler<SearchCompletedEventArgs>(service_SearchCompleted);
                    service.SearchAsync(req);
    

    If i connect the internet then not problem, but when i disconnect the internet, i get exeption:

    System.ServiceModel.EndpointNotFoundException was unhandled

      Message=There was no endpoint listening at http://api.bing.net/soap.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

      StackTrace:

           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()

      InnerException: System.Net.WebException

           Message=The remote server returned an error: NotFound.

           StackTrace:

                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()

           InnerException: System.Net.WebException

                Message=The remote server returned an error: NotFound.

                StackTrace:

                     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.Delegate.DynamicInvoke(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.Delegate.DynamicInvoke(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.Hosting.DelegateWrapper.InternalInvoke(Object[] args)

                     at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

    Could anybody help me, please? Thanks!

All Replies