'WebException' error on back button even when calling 'void' async method

Posted by BlazingFrog on Stack Overflow See other posts from Stack Overflow or by BlazingFrog
Published on 2012-03-31T21:26:14Z Indexed on 2012/03/31 23:29 UTC
Read the original article Hit count: 205

I have a windows phone app that allows the user to interact with it. Each interaction will always result in an async WCF call.
In addition to that, some interactions will result in opening the browser, maps, email, etc...

The problem is that, when hitting the back button, I sometime get the following error
"An error (WebException) occurred while transmitting data over the HTTP channel."

with the following stack trace:
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.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadPool.WorkItem.doWork(Object o) at System.Threading.Timer.ring()

My understanding is that it's happening because my app opened another app (browser, maps, etc) before it had the time to execute the EndMyAsyncMethod(System.IAsyncResult result). Fair enough...

What's really annoying is that it seems it should get fixed by cloning the server-side method, only making it void with the following operation contract [OperationContract(IsOneWay = true)] but I'm still getting the error.

What's worse is that the exception is thrown in a system-generated part of the code and, thus, cannot be manually caught causing the app to just crash.

I simply don't understand the need to execute an Endxxx method when it's explicitely marked as OneWay and void.


EDIT

I did find a similar issue here. It does seem that it is related to the message getting to the service (not the client callback). My next question is:
if I'm now calling a method marked AsyncPattern and OneWay, what exactly should I be waiting for on the client to be sure the message was transmitted successfully?

This is new service definition:

[OperationContract(IsOneWay = true, AsyncPattern = true)]
IAsyncResult BeginCacheQueryWithoutCallback(string param1, QueryInfoDataContract queryInfo, AsyncCallback cb, Object s);

void EndCacheQueryWithoutCallback(IAsyncResult r);

And the implementation:

public IAsyncResult BeginCacheQueryWithoutCallback(string param1, QueryInfoDataContract queryInfo, AsyncCallback cb, Object s)
{
        // do some stuff
        return new CompletedAsyncResult<string>("");
}
public void EndCacheQueryWithoutCallback(IAsyncResult r)
{
}

© Stack Overflow or respective owner

Related posts about wcf

Related posts about windows-phone-7