WCF Http RouteTables(用于版本控制)
我目前的路由表有类似的内容。是否有更好的方法来处理 WCF Web API
或传统 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做,但它非常协议绑定,在本例中是HTTP。我想知道是否有一种方法可以做到这一点而不必太担心协议?理想情况下,我们只想执行一次,而不是每次传输都执行一次。幸运的是有一种方法,让我解释一下。
归根结底,您的 WCF 内部结构应该与协议无关。我的意思是,当在您的服务上调用一个方法时,我们不应该关心它是通过 REST、TCP、HTTP 还是命名管道来的。
在 WCF 中,这非常简单,版本控制也是如此。通过版本控制,我们可以了解有关 .NET 接口版本控制的更多信息,特别是当它与 WCF 无关时。这个想法是,您的服务应该实现:
稍后,当需要新方法或更改时,您应该:
然后在配置中使用 2 个端点发布您的服务是一件简单的事情,一个指向 ISomething1 ,另一个指向 ISomething1到ISomething2。
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:
Later when a new method or changes are required you should:
It's then a simple matter to publish your service with 2 endpoints in config, one pointing to ISomething1 and the other to ISomething2.