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", Config1);
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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top