Calling web service asynchronously (C#) - completed event breakpoint not hit -


Can not go below this one and it is clearly some stupid, can someone please help?

I am calling a web service using a C # console application, and breakpoints are never hit in the 'complete' event.

Here is an example code, really simple:

public static zero call () {try {ServiceReference1.GlobalWeatherSoapClient proxy = new GlobalWeatherSoapClient (); Proxy GatecityJackCountry + Proxy_TatesBackCounter Expiration; Proxy.GetCitiesByCountryAsync ("France"); } Hold (FaultException defect exception) {var error = faultException.Message; }} Fixed zero proxy_GetCitiesByCountryCompleted (Object Sender, GetCitiesByCountryCompletedEventArgs E) // Here some exceptions to execute some new exceptions (); }

then breakpoint on the line

  throw the new NotImplementedException;  

The hit never happens.

However, I add an extra line after the actual asynch call:

  System.Threading.Thread .Sleep (5000);  

.. The breakpoint is recovering now. Can anyone tell me what is happening here? Obviously something to do with thread and debugger, but what did I not understand?

The reason for this is that the proxy is going out of the scope and therefore clean Is happening (thus losing your callback).

Therefore, you need to move your proxy out of the call so that its lifetime can be controlled by you:

  Private Sections 1. GlobalWersopCloth _ Proxy; Public Zero Callwice () {try {_Proxy = new GlobalWeatherSoapClient (); _ Proxy. Gettysybie country line + = proxy_gatecityaccount full; _proxy.GetCitiesByCountryAsync ("France"); } Hold (FaultException defect exception) {var error = faultException.Message; }} Public void proxy_GetCitiesByCountryImplementedException (); }  

This is not your correct example, without seeing the rest of your code, I can not tell you how to instantiate proxy Not in callwise but in a constructor etc, but hopefully you will get this idea!


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -