none
how to test sqldependency for wcf RRS feed

  • Question

  • Hi

    I have simple WCF service which uses linq to query and fetches data from testTable in testDatabase .

    now i have enabled sqldependency notification for both database and table and i can see extra table

    [AspNet_SqlCacheTablesForChangeNotification] is added to database along with new Stored procedures

    my wcf config file looks like below

     <caching>
          <sqlCacheDependency enabled="true" pollTime="900000" >
            <databases>
              <add name="testDatabase" connectionStringName="testDBConnectionString" />
            </databases>
          </sqlCacheDependency>
          <outputCacheSettings>
            <outputCacheProfiles>
              <add name="CacheFor900Seconds" duration="60" varyByParam="none" sqlDependency="testDatabase:testTable"/>
            </outputCacheProfiles>
          </outputCacheSettings>

        </caching>

    and my operation contract looks like below

     [AspNetCacheProfile("CacheFor900Seconds")]
            [OperationContract]
            [WebGet( RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "GettestTable", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
            HomePage GettestTable(string brand, string culture);

    my question is  1.) how can i test that wcf is returning data from cache and not fetching it from database when no changes are there in database

    2.)how i can i add more table for nottification and caching

    Saturday, August 24, 2013 8:10 AM

All replies

  • Hi onjus1,

    If you're using the ASP.NET SQL cache dependecy, you can try applying it on an ASP.NET Webform page for testing first. For example, we can apply the SQL cachd dependency based cache profile to webform page's output cache setting. To verify that the cache dependency works, you can add breakpoint into page's code-behind (such as Page_Load event), when output cache take effect, the response should be directly returned from cache and the breakpoint should not hit in. If everytime you request the page and the code-behind is executed, then the output cache is not working correctly.

    And for the multiple table based caching you mentioned, I'm afraid this is not supported by ASP.NET SQL cache dependency. As a single dependency will support a single table or row in a table for monitoring update/changes.

    http://msdn.microsoft.com/en-us/library/ms178604(v=VS.90).aspx


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, August 26, 2013 2:33 AM
    Moderator
  • thanks for replying but i need to cache 2 tables .

    1.is there any workaround for that ?

    2. secondly when i used cache for 1 table then i query and filter table records using linq .is the whoel table cached or the query response is cached(i.e only filtered rows in table)

    Monday, August 26, 2013 9:21 AM
  • Can AggregateCacheDependency  be used in WCF service , if so please help with example ?.currently i am using sql cache dependency for 1 table.but i need to cache 5 tables
    Tuesday, August 27, 2013 10:16 AM