locked
WCF Asynchronous Operations and parameters RRS feed

  • Question

  • Hi All,

     

    Following the pattern of Asynchonous operations I have developed two operations BeginGetUSers and an EndGetUsers.These operations just return a list os users registered im my database. Very simple !!!

     

    My BeginGetUsers operation is called like this:

    proxy.BeginGetUsers(new AsyncCallback(OnServerResult), guVO);

     

    Where guVO, of type GetUsersVO, is my Value Object passed to BeginGetUsers operation.

     

    My BeginGetUsers operation is like this:

    public IAsyncResult BeginGetUsers(AsyncCallback cb, object stateInfo) {


    GetUsersVO gVO = null;

    if (stateInfo != null) { gVO = (GetUsersVO) stateInfo; }

    _requestState = new AsyncRequestState(cb, stateInfo);

    ThreadPool.QueueUserWorkItem(new WaitCallback(GetUsersThread), stateInfo);

    return _requestState;

    }

     

    The problem is that  BeginGetUsers is receiveing the stateInfo parameter with the type System.ServiceModel.Dispatcher.MessageRpc.Wrapper and not GetUsersVO.

     

    I need access, in BeginGetUsers, to GetUsersVO because the thread scheduled to execute the operation needs some information that is in GetUsersVO. The question is: How can I receive or extract from System.ServiceModel.Dispatcher.MessageRpc.Wrapper my original parameter.

     

    Thanks in advance

    Monday, March 17, 2008 10:52 AM

Answers

  • Very good!  Could you mark that post as the answer, so that other can reference it as well?

    Tuesday, March 18, 2008 9:23 PM

All replies

  • You might be misusing that userState.  You shouldnt use it to pass parameters this is for unique state.  Instead your method should be declared to have other parameters that you use to pass values.  The callback and userstate MUST be the last 2 parameters.  That state parameter will always be a MessageRpc.Wrapper

    IAsyncResult BeginGetUsers(object guVo, AsyncCallback callback, object state)

    Then you call it like this:

    proxy.BeginGetUsers(guVO, new AsyncCallback(OnServerResult), null);

    This site shows a good example of this too:
    http://aspalliance.com/1335_Asynchronous_Pattern_in_Windows_Communication_Foundation.4
    Monday, March 17, 2008 12:08 PM
  • It worked !!!

     

    Thanks Dan

     

    Tuesday, March 18, 2008 7:57 PM
  • Very good!  Could you mark that post as the answer, so that other can reference it as well?

    Tuesday, March 18, 2008 9:23 PM