Can I host different ServiceStack services at diff

2019-08-09 05:10发布

问题:

When configuring ServiceStack, I have to specify a location (URL) at which my services will be available. E.g. when running side-by-side with WebApi:

<location path="svc">
 <system.web>
   <httpHandlers>
     <add path="*" type="ServiceStack..." verb="*"/>
   </httpHandlers>
 </system.web>

Now all my ServiceStack-based services will be available at http://server/webapp/svc/{route}.

After reading the page about modularizing services into plugins, I was wondering: is it possible to register the service(s) contained in each plugin at a different URL (e.g. vary the /svc/ segment of the URL per plugin)?

回答1:

See the configuring ServiceStack section in Hello World example on how to register ServiceStack to run at a custom path.

You will also want to read the README section and answer if you're trying to run ServiceStack with MVC.


(in response to the comment)

There's only 1 ServiceStack AppHost in every host application, which can only be hosted on 1 root / or /custompath. All other route configurations are mapped from that /path. So if you register it at /svc you can't register a new ServiceStack AppHost from a different mount point e.g. /svc2. If you hosted it at root path / then your individual routes can be hosted at /svc/route1, /svc/route2, etc. But then you wont be able to host it side-by-side with another web fx (e.g. MVC or WebAPI).