注意:我确认ServiceStack 3.9.71.0和4.0.46.0会出现此问题。
这是我非常基本的服务代码:
namespace MyServiceStackApplication.Services
{
[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello
{
public string Name { get; set; }
}
public class HelloService : Service
{
public Guid Any(Hello request) // Note that this method returns a Guid.
{
throw new Exception("My test exception."); // Note that I am throwing an exception here.
}
}
}
这是我的Global.asax.cs
代码:
public class MvcApplication : HttpApplication
{
public class AppHost : AppHostBase
{
public AppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }
public override void Configure(Container container)
{
//register any dependencies your services use, e.g:
//container.Register<ICacheClient>(new MemoryCacheClient());
}
public override IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext)
{
return new MyServiceRunner<TRequest>(this, actionContext);
}
public class MyServiceRunner<T> : ServiceRunner<T>
{
public MyServiceRunner(IAppHost appHost, ActionContext actionContext) : base(appHost, actionContext)
{
}
public override object HandleException(IRequest request, T requestDto, Exception ex)
{
Console.WriteLine(ex);
return base.HandleException(request, requestDto, ex);
}
}
}
protected void Application_Start()
{
//AreaRegistration.RegisterAllAreas();
//FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
//RouteConfig.RegisterRoutes(RouteTable.Routes);
//BundleConfig.RegisterBundles(BundleTable.Bundles);
new AppHost().Init();
}
}
我的问题:
答案 0 :(得分:1)
您只能从ServiceStack服务返回一个参考类型,该服务理想情况下应该是一个响应DTO,但也可以是原始类型,如string
,byte[]
,Stream
等。< / p>