问题描述
我想实现ServiceStack到我的MVC3项目,我在下面的教程:http://www.servicestack.net/ServiceStack.Hello/
I'm trying to implement ServiceStack into my MVC3 project, and am following the tutorial at: http://www.servicestack.net/ServiceStack.Hello/
我的Global.asax.cs现在看起来像:
My Global.asax.cs now looks like:
public class MvcApplication : System.Web.HttpApplication
{
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
{
//Tell Service Stack the name of your application and where to find your web services
public HelloAppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }
public override void Configure(Container container)
{
//register user-defined REST-ful urls
Routes
.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name}");
}
}
protected void Application_Start()
{
new HelloAppHost().Init();
}
}
}
...按照说明进行操作。
... as per the instructions.
然而,当我调用init()方法中,我得到异常:
However, when I call the Init() method, I get the exception:
InvalidDataException:AppHostBase.Instance已设定
周围的Googling此提供任何帮助,除了在<一个源$ C $ C href=\"http://$c$c.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Common/ServiceStack.WebHost.Endpoints/AppHostBase.cs?r=1322\">http://$c$c.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Common/ServiceStack.WebHost.Endpoints/AppHostBase.cs?r=1322
Googling around for this provides no help, except the source code at http://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Common/ServiceStack.WebHost.Endpoints/AppHostBase.cs?r=1322
望着这,不知何故,该实例被设置。但如何?
Looking at this, somehow, the Instance is being set. But how?
什么引起的?
推荐答案
如果您已经通过的NuGet ServiceStack.Host.Mvc项目安装ServiceStack它自动为您内创建APPHOST类:
If you've installed ServiceStack via the NuGet ServiceStack.Host.Mvc project it automatically creates the AppHost class for you inside:
App_Start/ServiceStackFramework.cs
您的例子看起来你可能已添加你自己的APPHOST为好。所以,如果你删除此APPHOST和使用提供一个你不应该再有这样的错误。
Your example looks like you may have added your own AppHost as well. So if you remove this AppHost and use the provided one you should no longer have this error.
这篇关于服务堆栈/ MVC:QUOT; AppHostBase.Instance已经设置&QUOT;错误 - 但不明白为什么/如何prevent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!