Community discussion forum

Asynchronous Webservice calls

Tags: asp.net India
  • 1 year ago

    I have  implemented a n-tier web application. In the data access layer I try to retrieve some data using some web service methods. The webmethod name is GetData(). I would want to call this method asynchronously. So I use the BeginGetData in my code

    DGetData() {

    IAsyncResult result = service.BeginRetrieveMultiple(qryExpression, new AsyncCallback(ServiceCallBack), service);

    // want to return the retrieved data

    }

    Then I implement the CallBack method as below

    private void ServiceCallBack(IAsyncResult aRes)

    {

    string strData = null;

    try

    {

    WebService service = (WebService)aRes.AsyncState;

    strData = service.EndRetrieveMultiple(aRes);

    }

    catch (Exception ex) { //Handle Exception here }

    }

    I should send this data back to the business logic layer or further processing. How am I supposed to do that?

    Please let me know if anybody has used Async web service calls in a n-tier architecture. How can the Async result be passed back to the calling layer?

    Regards
  • 1 year ago

    Hi,

    How you go about tackling this depends on your implementation.

    What you have effectively done here is cut the layers off by implementing a design that does not allow communication back up the layers.  n-tier design does state that communication flows down through the tiers, which means that anything that calls down a tier must receive the data needed.

    Effectively, meaning that asynchronous calls are not generally used.

    You could implement a system whereby the dal implements an event that is fired when the data has been collected.  the BLL could then hook into that event and ask the dal for the data from a property or a structure within the dal that holds the returned data.

    The other method is to have the bll implement a service for it to be called, this could be a delegate or another web service, again, it depends on whether your implementation is based on physical or logical tiering.

    Regards

    Simon C

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback