开发者

WCF Http RouteTables (for versioning)

开发者 https://www.devze.com 2023-03-12 08:01 出处:网络
I currently have something like this for my route table. Is there a nicer way to handle versioning in WCF Web API or conventional WCF?

I currently have something like this for my route table. Is there a nicer way to handle versioning in WCF Web API or conventional WCF?

RouteTable.Routes.MapServiceRoute<Service1>("1.0/Route1", Confi开发者_开发问答g1);
RouteTable.Routes.MapServiceRoute<Service2>("1.0/Route2", Config2);
RouteTable.Routes.MapServiceRoute<Service3>("1.0/Route3", Config3);
RouteTable.Routes.MapServiceRoute<Service4>("1.0/Route4", Config4);


You could do that, but it is very protocol-bound, in this case HTTP. I wonder if there is a way to do that without worrying so much about protocols? Ideally we only want to do it once and not for each transport out there. Luckily there is a way, let me explain.

At the end of the day, your WCF internals should be protocol agnostic. By that I mean by the time a method is invoked on your service, we should not care whether it came by REST, TCP, HTTP or named pipes.

In WCF this is pretty easy and so is versioning. With versioning we can learn much about .NET interface versioning particularly when it has nothing to do with WCF. The idea is that your service should realize:

interface ISomething1 { ... }

Later when a new method or changes are required you should:

interface ISomething2 : ISomething1 { void SomethingNew (...) }

It's then a simple matter to publish your service with 2 endpoints in config, one pointing to ISomething1 and the other to ISomething2.

0

精彩评论

暂无评论...
验证码 换一张
取 消