Last post Feb 17, 2009 12:47 PM by randallt
Feb 13, 2009 08:56 AM|dimitri_sturm|LINK
I've enabled chaching on my rest service and it works great when i call the service from IE or fiddler. Now i want to call it via a console application using a channel factory. When i do this i get the following error: WebCacheAttribute is supported only
in AspNetCompatibility mode. isn't is possible to enable the caching for a console app. I onderstand it doesn't work client side, but i hoped it would work server side.
wcf REST WebCacheAttribute AspNetCompatibility
Feb 13, 2009 04:21 PM|randallt|LINK
You are getting that exception because you are using an interface service contract that is decorated with the WebCacheAttribute when you instantiate the client channel factory. Simply make a copy of your interface for the client and strip out all of the
WebCache attributes. Or move all of your attributes from your interface service contract to your class service definition.
Feb 16, 2009 08:13 AM|dimitri_sturm|LINK
Feb 16, 2009 01:58 PM|randallt|LINK
The client and the server don't have to share the same interface file. If you have as IService.cs file like this:
2 public interface IService
7 public MyType MyOperation(MyParameters...);
Make a copy of this file called IServiceClient.cs and then remove the WebCache attributes from this version. Instantiate your service with IService and instantiate your client with IServiceClient.cs. Now your service provides caching and your client still
WebCacheAttribute is not supported on client interfaces. The WebCacheAttribute is simply used to configure the ASP.NET output cache that exists in the channel stack when AspNetCompatiabilty mode is enabled. There is no ASP.NET output cache on the client
side--so it wouldn't make any sense to have this attribute on a client.
I think your confusion arrises because you've seen that the Location property of the WebCacheAttribute can be set to "Client". When you set this, what you are doing is telling the ASP.NET output cache on the server to set the HTTP headers to
tell the client that it is able to cache the response message. IE and smart clients that have their own caches will use this information in the HTTP headers to cache. However, the ChannelFactory and the client proxies that it creates do not provide
this caching. You can not create a client proxy from a ChannelFactory and expect it to cache.
Feb 16, 2009 08:46 PM|dimitri_sturm|LINK
Thanks a lot Randall, this make things a lot more clear. But now i have one last question. How do i instantiate the server using the other interface. Now i have one interface witch i pass to the webchannelfacory on the client. I host my service in iis or
the vs integrated webserver.
Feb 17, 2009 12:47 PM|randallt|LINK
You can instantiate the server just as you normally would. In IIS, you'll have a Service.svc file that has markup like the following:
<%@ ServiceHost Language="C#" Debug="true" Service="TasksService.Service" Factory="TasksService.AppServiceHostFactory"%>
Your service class (in this case "TasksService.Factory") should implement an your server version of the contract: IService.