ServiceStack - Manually register services

527 views
Skip to first unread message

Yavor Shahpasov

unread,
Mar 12, 2012, 11:31:41 AM3/12/12
to ServiceStack .NET Open Source REST Web Services Framework
I have an assembly with a lot of services.

I would like to select a number of web services to expose.
Currently the AppHost only accepts an Assembly and automatically
registers all the services.


Yavor

Demis Bellot

unread,
Mar 12, 2012, 11:35:40 AM3/12/12
to servic...@googlegroups.com
You can register services manually in your AppHost with:

this.RegisterService<MyService>("/atpath");

Which uses this extension method:

Cheers,

Yavor Shahpasov

unread,
Mar 12, 2012, 11:49:45 AM3/12/12
to servic...@googlegroups.com
Hi Demis,

This seems to work.

However I still need to pass an assembly to the constructor or I get an exception.
If I don't call the base method the register service does not work.

I've managed to work around this problem by supplying an allembly with a dummy service, but if there is a better way it would be great.


public AppHost() 
            : base("Web Services")
        {
            this.RegisterService(typeof(Service1));
            this.RegisterService<Service2>();
        }
        
        
        System.ArgumentException was unhandled by user code
  Message=No Assemblies provided in your AppHost's base constructor.
To register your services, please provide the assemblies where your web services are defined.
  Source=ServiceStack
  StackTrace:
       at ServiceStack.ServiceHost.ServiceManager..ctor(Assembly[] assembliesWithServices) in C:\src\ServiceStack\src\ServiceStack\ServiceHost\ServiceManager.cs:line 26
       at ServiceStack.WebHost.Endpoints.AppHostBase.CreateServiceManager(Assembly[] assembliesWithServices) in C:\src\ServiceStack\src\ServiceStack\WebHost.EndPoints\AppHostBase.cs:line 38
       at ServiceStack.WebHost.Endpoints.AppHostBase..ctor(String serviceName, Assembly[] assembliesWithServices) in C:\src\ServiceStack\src\ServiceStack\WebHost.EndPoints\AppHostBase.cs:line 33
       at NCommerce.WebApi.App_Start.AppHost..ctor() in C:\Users\yavo\Documents\Visual Studio 2010\Projects\NCommerce\src\NCommerce.WebApi\App_Start\ServiceStackFramework.cs:line 43
       at NCommerce.WebApi.App_Start.AppHost.Start() in C:\Users\yavo\Documents\Visual Studio 2010\Projects\NCommerce\src\NCommerce.WebApi\App_Start\ServiceStackFramework.cs:line 275
  InnerException: 


Cheers,
Yavor

Demis Bellot

unread,
Mar 12, 2012, 12:08:54 PM3/12/12
to servic...@googlegroups.com
Yes, the assembly of services is expected since that's how its supposed to work. 
Just pass in a dummy assembly.
Reply all
Reply to author
Forward
0 new messages