我试图弄清楚如何从 asp mvc4 控制器调用服务,但我就是做不到。我已经设置了服务,但是当我尝试从我的控制器方法调用时,它会显示:
http://s10.postimg.org/5ojcryn7t/error_1.png
这是我的代码:
全球.asax.cs
namespace mvc4_servicestack
{
// Nota: para obtener instrucciones sobre cómo habilitar el modo clásico de IIS6 o IIS7,
// visite http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public class AppHost : AppHostBase
{
public AppHost()
: base("Nombre del Host de los WebService", typeof(SS_WebServices.StatusService).Assembly)
{ }
public override void Configure(Funq.Container container)
{
}
}
protected void Application_Start()
{
new AppHost().Init();
AreaRegistration.RegisterAllAreas();
// WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
}
}
SS_WebServices.cs
命名空间 mvc4_servicestack { 公共类 SS_WebServices {
//Request DTO Objet
[ServiceStack.ServiceHost.Route("/Home/About/statuss")]
[ServiceStack.ServiceHost.Route("/Home/About/statuss/{Name}")]
public class StatusQuery : ServiceStack.ServiceHost.IReturn<StatusResponse>
{
public string Name { get; set; }
public int Id { get; set; }
}
//Response DTO Object
public class StatusResponse
{
public string Result { get; set; }
}
//Service
public class StatusService : ServiceStack.ServiceInterface.Service
{
//Implement teh Method VERB (POST,GET,PUT,DELETE) OR Any for ALL VERBS
public object Any(StatusQuery request)
{
//Looks strange when the name is null so we replace with a generic name.
var name = request.Name ?? "John Doe";
return new StatusResponse { Result = "Hello, " + name };
}
}
}
}
我一直在阅读帖子ServiceStack 应该是 MVC 应用程序中的服务层还是应该调用服务层?
但我仍然无法理解以下内容:为什么注册返回一个接口而不是一个 GreeterResponse?container.Register(c => new Greeter());
我真的希望你们能帮助我......!