When developing ordinary 3T business application you might want to use a custom proxy DLL to access your web service rather then accessing it directly (please do not mix this with proxy DLL generated for you by Visual Studio). If the signature of your proxy DLL is the same as that of your web service you'll be able to swap the two at any given moment. A local DLL will hide the complexity of using web service. In addition to that it is a very good place for implementing client side caching mechanisms for common data (i.e. countries, cities, currencies, etc.); managing retries and emergency procedures; and catching and handling some types of exceptions.

Here's a code fragment showing how you can create simple application proxy with cache mechanism.

class AppProxy

{

    private static AppProxy instance;

    private DataSet cities;

    private DateTime refreshCitiesAt;

 

    public static AppProxy Instance {

        get {

            if (instance==null)

                instance=new AppProxy();

            return instance;

        }

    }

 

    public DataSet ListCities()

    {

        if (DateTime.Now > refreshCitiesAt)

        {

            cities=webService.ListCities();

            // Refresh in 30 minutes.

            refreshCitiesAt = DateTime.Now.AddMinutes(30);

        }

        return cities;

    }

}


And here is how you would call it.

DataSet citiesDs=AppProxy.Instance.ListCities();

0 comment(s) :

Newer Post Older Post Home

Blogger Syntax Highliter