简体   繁体   中英

How to use two service classes for a WCF REST Service?

I have a REST Service built with WCF Rest Service Template.

I am curious if it is possible to have to service classes in my project and register them in the RegisterRoutes() in Global.Asax.

I tried this but only Service1 will resolve:

    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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM