2

我正在学习 ServiceStack 并为 helloworld 开发简单的演示,但找不到ISservice接口的命名空间,我的代码如下:

 public class Hello
{
    public string name { get; set; }
}
public class HelloResponse
{
    public string Result { get; set; }
}

public class HelloService :  **IService**<Hello>
{
    public object Execute(Hello request)
    {
        return new HelloResponse { Result = "Hello" + request.name };
    }
}

public class HelloAppHost : AppHostBase
{
    public HelloAppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }
    public override void Configure(Funq.Container container)
    {
        Routes.Add<Hello>("/hello")
            .Add<Hello>("/hello/{Name}");

    }
}

谁能告诉我我需要为IService接口添加什么命名空间或 DLL?

4

1 回答 1

2

ServiceStack 的IService<T>位于ServiceStack.ServiceHost命名空间中,该命名空间位于ServiceStack.Interfaces.dll中,为什么这里是类:

https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Interfaces/ServiceHost/IService.cs

注意:如果您刚刚开始,最好从ServiceStack.ServiceInterface.ServiceBase<T>继承并覆盖Run()方法,这是一个有用的基类,可为您提供自动异常处理等功能。

如果您希望能够为不同的 HTTP 动词运行不同的代码,例如 GET/POST/PUT/DELETE(即创建 REST Web 服务),而不是希望从RestServiceBase继承并覆盖其 OnGet/OnPost/OnPut/OnDelete 方法。

于 2011-10-18T14:17:55.403 回答