Click here to Skip to main content
15,071,921 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I have a lovely problem.

I have an Asynchronous HTTPModule and that module calls an Asynchronous WCF service.

In module I dig up several values from Session[]
But when 1 value is string.IsNullOrEmpty I do not want to make the call to the asynchronous wcf service but I want to go to the End method of my HttpModule.

The begin method is of course with returntype IAsyncResult.
Return null leads to a null reference exception in the logging.
returning a new IAsyncResult with callback name and null state makes me wait forever (it does not show up in the end method.

How to overcome this problem?
Posted

1 solution

I can understand why no one gave an anwer!
This is pretty hard but I managed :)

In the HTTPModule You first register the begin and end method.

In the begin method the wcf begin method was called and the answer return to the endmethod of the httpmodule which called the endmethod of the wcf service.

When I found out that in the begin method of httpmodule no call to the wcf service had to be made but i had to call an endmethod of the httpmodule directly. If you do this directly IIS (the owner of the httpmodule) doesn't see the signalling anymore and your page waits for ever.

How to handle this:
call a selfmade IASyncResult method
C#
private IAsyncResult NoNeedToCall(AsyncCallback callback, object state)
        {
           IAsyncResult result = new AsyncResult(callback, state);
          
           callback.Invoke(result);
           return result;
        }


The Invoke(result) comes in my Endmethod of the HTTPModule. IIS has no vision anymore of the signaling proces. So we have to use a ManuelResetEvent object.

Instantiate it and call the Set() function of it like this:

C#
ManualResetEvent evt = new ManualResetEvent(false);
evt.Set();


In my case I do the Set() after checking the AsyncState (a normal request will hold a AsyncState, but the 'shortroute' has it set to null. So I know I have to signal manually.

It costed me a lot of blood, sweet and tea(rs), but it works. Calling with invalid data or calling while te object is in cache is now past.
   
v2
Comments
[no name] 23-Sep-11 6:47am
   
Good Answer. 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900