我想在我的 xml 配置中启用 scope="request"
属性:
<object id="IDataAccess" type="Dal.DataAccess, Dal" scope="request">
我的 WCF 服务托管在 IIS 上,我使用 RouteTable
和 ServiceHostFactory
来创建我的服务:
static void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("url", serviceHostFactory, typeof(MyService)));
}
我在我的 web.config
中添加了 WebContextHandler
以启用作用域 request
和 session
如此处所述http://www.springframework.net/doc-latest/reference/html/web.htm (第 22.3.1 节)
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
</sectionGroup>
还有 httpModules
东西:
<system.web>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
</system.web>
而且因为我是window 7,framework Net 4.0我还加了:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</modules>
</system.webServer>
这些都是我做的。它不起作用,我还有:
Resource handler for the 'web' protocol is not defined.
调用时:
SpringContext = (IApplicationContext)ConfigurationManager.GetSection("spring/context");
我现在不知道该怎么办,Spring.net 社区的人可以帮助我吗?看起来我并没有尝试做一些棘手或骇人听闻的事情。在 IIS 中托管 WCF 服务是一种常见的模式。
编辑:
我试过
<add verb="*" path="*" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
正如评论中所建议的那样,它不起作用。
最佳答案
我在spring源代码中查看了一个机器人,如果我添加
ResourceHandlerRegistry.RegisterResourceHandler("web", typeof (WebResource));
在我的 Application_Start
方法中,在获取 ContextConfiguration 之前,它完成了这项工作。我不知道为什么。我认为这是当前 WebSupportModule
中的错误。
这很奇怪,因为这是在WebSupportModule
的静态构造函数中调用的。我尝试为 Spring 启用日志记录,但创建了日志文件,但仍然是空的:/它可以帮助我更多地理解。
关于c# - IIS 的 WCF 服务宿主,spring.net 范围 ="request",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7832664/