locked
Non WCF Client Async Calls RRS feed

  • Question

  • Hi,

     

    I'm trying to implement a publish-subcribe-type service for non-WCF clients, using WCF for the server.

     

    The clients can only use "plain" (basicHttpBinding) web services.

     

    To scale the service I was thinking of using the Async pattern on the server, so that IIS passes subscriptions onto a seperate thread. If I try to implement a standard operation using something like:

     

    [OperationContract(AsyncPattern=true)]

    IAsyncResult BeginGetData(string intParam, AsyncCallback callback, object asyncState);

    string EndGetData(IAsyncResult r);

     

    If I debug, the BeginGetData call gets called, but the EndGetDate never gets called, meaning the a client call to GetData(string s) never gets a response. I can't use/generate a proxy for the client, becasue it is not .NET.

     

    So;

    a) What am I doing wrong? Even if I set the IsCompleted attribute on the IAsyncResult to true, End never gets called. 

    b) Is this the right model I should be using?

     

    Cheers,

     

    Paul

    Thursday, May 24, 2007 1:11 PM

Answers

  • It's your responsibility to call the callback when your operation is done.  For the purpose of getting it working, you can call it in BeginAckService.  Later, you'll call it once the response is ready.

     

    Once you get to the point where you want to complete the operation later, you will need to re-implement CallbackAsyncResult to properly implement AsyncWaitHandle, CompletedSynchronously, and IsCompleted.

    Friday, May 25, 2007 1:14 AM

All replies

  • It sounds like something is wrong with the implementation of your BeginGetData method - can you share the code?

     

    The model seems fine.

     

    You might also want to check out http://blogs.msdn.com/mjm/archive/2005/05/04/414793.aspx (old, but not dated); it doesn't necessarily address your question, but is good background info about WCF async pattern.

    Thursday, May 24, 2007 2:30 PM
  • Thanks Brian,

     

    This is the code (I've stripped it down to the bare minimum). Am I right in thinking the the callback thunk shoudl automatically wire up the End method so that if IAsyncResult.IsCompleted is true, the End method is called automatically? Or do I have to do some additional wiring? If I set breakpoints on the Begin and End methods, only the ones on Begin are hit, so I know that no return mesage is being set.

     

    Thanks,

     

    Paul

     

    //////////////// Service:

    public IAsyncResult BeginAckService(string sessionId, AsyncCallback callback, object asyncState)

    {

    Debug.WriteLine("Invoked Begin, called with: " + sessionId);

    IAsyncResult asyncResult = new CallbackAsyncResult(sessionId);

    return asyncResult;

    }

     

    public string EndAckService(IAsyncResult r)

    {

    CallbackAsyncResult result = r as CallbackAsyncResult;

    Debug.WriteLine("Result: " + result.Event);

    return "Async: " + result.Event;

    }

    ////////////////////

     

    class CallbackAsyncResult : IAsyncResult

    {

    string _eventType;

    public CallbackAsyncResult(string eventId)

    {

    this._eventType = eventId;

    }

    public string Event

    {

    get

    {

    return _eventType;

    }

    }

    #region IAsyncResult Members

    public object AsyncState

    {

    get

    {

    return (object)_eventType;

    }

    }

    public WaitHandle AsyncWaitHandle

    {

    get

    {

    return null;

    }

    }

    public bool CompletedSynchronously

    {

    get

    {

    return true;

    }

    }

    public bool IsCompleted

    {

    get

    {

    return true;

    }

    }

    #endregion

    }

    Friday, May 25, 2007 12:36 AM
  • It's your responsibility to call the callback when your operation is done.  For the purpose of getting it working, you can call it in BeginAckService.  Later, you'll call it once the response is ready.

     

    Once you get to the point where you want to complete the operation later, you will need to re-implement CallbackAsyncResult to properly implement AsyncWaitHandle, CompletedSynchronously, and IsCompleted.

    Friday, May 25, 2007 1:14 AM