Reputation: 472
I've go an existing asp.net website (not owned by me) and they are asking for some web services to be added. Every ServiceStack.net sample is for a web application not a web site.
has anyone done this? I've googled alot and haven't found anything.
I know the web.config section is quite different but I'm looking for something working.
Thanks.
Upvotes: 1
Views: 264
Reputation: 3072
The Global.asax file:
<%@ Application Language="C#" %>
<%@ Import Namespace="ServiceStack.ServiceHost" %>
<%@ Import Namespace="ServiceStack.ServiceInterface" %>
<script runat="server">
[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
public class HelloService : Service
{
public object Any(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}
public class HelloAppHost : ServiceStack.WebHost.Endpoints.AppHostBase
{
//Tell Service Stack the name of your application and where to find your web services
public HelloAppHost() : base("Russ", typeof(HelloService).Assembly) { }
public override void Configure(Funq.Container container)
{
//register any dependencies your services use, e.g:
//container.Register<ICacheClient>(new MemoryCacheClient());
}
}
void Application_Start(object sender, EventArgs e)
{
new HelloAppHost().Init();
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
As for the web.config file, I found it was the same as the web application example. just find the respective sections of the tags, and input the two lines where they belong:
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
and for references I added the nuget package and did the cmd line call: install-package ServiceStack. But you're bin should have these files:
Upvotes: 2
Reputation: 3149
I just gave this a try form a new ASP.NET Web site and it does work. The meta data page was not displaying correctly but all the endpoints work. I imagine with a little tinkering you could get the metadata page working.
I installed ServiceStack via nuget and since web sites do not have project files the references will appear differently. All the dlls will be loaded directly into the bin folder.
Then add the min required DTOs, service and AppHost code and it will work.
Upvotes: 1