I have a REST Service built with WCF Rest Service Template.
我有一个使用WCF Rest服务模板构建的REST服务。
I am curious if it is possible to have to service classes in my project and register them in the RegisterRoutes() in Global.Asax.
我很好奇是否可以在我的项目中为类提供服务并在Global.Asax中的RegisterRoutes()中注册它们。
I tried this but only Service1 will resolve:
我试过这个,但只有Service1会解决:
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(Service1)));
RouteTable.Routes.Add(new ServiceRoute("Service2", new WebServiceHostFactory(), typeof(Service2)));
}
Is this possible or should all my service methods reside on one class ?
这可能或者我的所有服务方法都应该存在于一个类中吗?
1 个解决方案
#1
1
Sure, this is possible, but in your scenario above, the first ServiceRoute will catch calls to the second Service (Service2), because it looks like calls to /Service2 are actually operations on Service1.
当然,这是可能的,但在上面的场景中,第一个ServiceRoute将捕获对第二个服务(Service2)的调用,因为看起来对/ Service2的调用实际上是对Service1的操作。
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
RouteTable.Routes.Add(new ServiceRoute("Service2", new WebServiceHostFactory(), typeof(Service2)));
should work...
alternatively,
RouteTable.Routes.Add(new ServiceRoute("Service2", new WebServiceHostFactory(), typeof(Service2)));
RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(Service1)));
should work too...but it doesn't seem like such a good idea in terms of ambiguity.
也应该工作......但在模糊性方面似乎不是一个好主意。
#1
1
Sure, this is possible, but in your scenario above, the first ServiceRoute will catch calls to the second Service (Service2), because it looks like calls to /Service2 are actually operations on Service1.
当然,这是可能的,但在上面的场景中,第一个ServiceRoute将捕获对第二个服务(Service2)的调用,因为看起来对/ Service2的调用实际上是对Service1的操作。
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
RouteTable.Routes.Add(new ServiceRoute("Service2", new WebServiceHostFactory(), typeof(Service2)));
should work...
alternatively,
RouteTable.Routes.Add(new ServiceRoute("Service2", new WebServiceHostFactory(), typeof(Service2)));
RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(Service1)));
should work too...but it doesn't seem like such a good idea in terms of ambiguity.
也应该工作......但在模糊性方面似乎不是一个好主意。