Sunday 15 September 2013

c# - CommunicationException is lifted, even in a try/catch block -


I am currently developing an application for WP7 which requires calling in the WCF service application. I tested the service with a small WPF application and everything went right. But now that I say it from your WP7 app, I would systematically receive the following exception:

  System.ServiceModel.CommunicationException But that was not the handle in the user code system. SystemModel.CommunicationException user threatened by code HResult = -2146233087 Message = remote server returned an error: NotFound Source = System.ServiceModel InnerException: System.Net.WebException HResult = -2146233079 Message = remote server returned an error: NotFound Source = System.Windows InnerException: System.Net.WebException HResult = -2146233079 message = remote server returned an error: NotFound Source = System.Windows InnerException:   

is there an exception, despite the fact That I am calling my service in a try / grip block (MyProjectPath.Model.User.cs) like this:

Public Affairs & lt; Users & gt; Load (string logon, string pwHash) {efficiency source & lt; Users & gt; TCS = new work end source & lt; Users & gt; (); Client.GetUserByCredsCompleted + = ((s, e) = & gt; {if (e. Error == NULL) TCS. TrySetResult (e.Result); else {StringBuilder sb = new StringBuilder (); sb.AppendLine ( "Error To receive data while receiving: "); sb.AppendLine (E. error message); Message box. (SB ToString ());}}); Try {Client.GetUserByCredsAsync (Logon, Peed Hash); } Hold (System.ServiceModel.CommunicationException Pre) {Message Box.Show (ex.Message); } Hold (Exception pre) {Message Box. Show (ex.Message); } Return TCS Task; }

When it is executed, the exception occurs here (systems. In Sewamodelkni.a. Dll):

  public MyProjectPath. ServiceReference.User EndGetUserByCreds (System .IAsyncResult Results) {Object [] _args = New Object [0]; // exception is raised by the following line: MyProjectPath.ServiceReference.User _result = ((MyProjectPath.ServiceReference.User) (base.EndInvoke ( "GetUserByCreds", _args, results))); Return _result; }   

Has anyone ever encountered this problem and solved it? I have to admit that I have a very strange thing here ...

You call an asynchronous API Are there. Although you wrap that call in an effort / catch block, this call will probably start a new thread or the request will be queued for taking any other thread. Either way, your effort / guard only protects you against the exception of throwing on the thread which makes the call, and there is no one. (Beginning) Your asynchronous call is successful only, so the catch block is never affected, and then the other thread is controlled and this is where the exception is thrown.

You can not keep your call against the exceptions in the EndgateUser Bikers by wrapping Gettyscrabber's Ascend in an attempt / grip, two methods are executing different threads at different times. You need to modify the Endgate Userbecreds so that they take exceptions and are appropriately related to them, instead of crashing the threads.

No comments:

Post a Comment