Autofac WCF 集成 +会议

发布于 2024-11-29 01:41:47 字数 1548 浏览 0 评论 0原文

我有一个与 WCF 服务协作的 ASP.NET MVC 3 应用程序,该服务使用 Autofac 主机工厂托管。以下是一些代码示例:

.svc 文件:

<%@ ServiceHost 
Language="C#" 
Debug="true"
Service="MyNamespace.IMyContract, MyAssembly" 
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>

WCF 服务项目的 Global.asax:

protected void Application_Start(object sender, EventArgs e)
{
    ContainerBuilder builder = new ContainerBuilder();        

    //Here I perform all registrations, including implementation of IMyContract

    AutofacServiceHostFactory.Container = builder.Build();            
}

客户端代理类构造函数(MVC 端):

ContainerBuilder builder = new ContainerBuilder();

builder.Register(c => new ChannelFactory<IMyContract>(
    new BasicHttpBinding(),
    new EndpointAddress(Settings.Default.Url_MyService)))
    .SingleInstance();

builder.Register(c => c.Resolve<ChannelFactory<IMyContract>>().CreateChannel())
    .UseWcfSafeRelease();

_container = builder.Build();

这可以正常工作,直到我希望 WCF 服务允许或需要会话 ([ServiceContract(SessionMode = SessionMode.Allowed)][ServiceContract(SessionMode = SessionMode.Required)]) 并与 MVC 端共享一个会话。我在 MVC 端更改了对 WSHttpBinding 的绑定,但根据我如何调整它,我遇到了不同的异常。

我还尝试将 AutofacServiceHostFactory 更改为 AutofacWebServiceHostFactory ,但没有结果。

我没有使用配置文件,因为我主要是在试验,而不是开发现实生活中的应用程序,但我需要研究这个案例。但如果您认为我只需使用配置文件就可以实现我所需要的,那么好吧,我将使用它们。

如果需要,我将提供每种设置组合的异常详细信息,我将省略它们,以免帖子太大。关于我能做什么有什么想法吗?

I am having an ASP.NET MVC 3 application that collaborates with a WCF service, which is hosted using Autofac host factory. Here are some code samples:

.svc file:

<%@ ServiceHost 
Language="C#" 
Debug="true"
Service="MyNamespace.IMyContract, MyAssembly" 
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>

Global.asax of the WCF service project:

protected void Application_Start(object sender, EventArgs e)
{
    ContainerBuilder builder = new ContainerBuilder();        

    //Here I perform all registrations, including implementation of IMyContract

    AutofacServiceHostFactory.Container = builder.Build();            
}

Client proxy class constructor (MVC side):

ContainerBuilder builder = new ContainerBuilder();

builder.Register(c => new ChannelFactory<IMyContract>(
    new BasicHttpBinding(),
    new EndpointAddress(Settings.Default.Url_MyService)))
    .SingleInstance();

builder.Register(c => c.Resolve<ChannelFactory<IMyContract>>().CreateChannel())
    .UseWcfSafeRelease();

_container = builder.Build();

This works fine until I want WCF service to allow or require sessions ([ServiceContract(SessionMode = SessionMode.Allowed)], or [ServiceContract(SessionMode = SessionMode.Required)]) and to share one session with the MVC side. I changed the binding to WSHttpBinding on the MVC side, but I am having different exceptions depending on how I tune it.

I also tried changing AutofacServiceHostFactory to AutofacWebServiceHostFactory, with no result.

I am not using config file as I am mainly experimenting, not developing real-life application, but I need to study the case. But if you think I can achieve what I need only with config files, then OK, I'll use them.

I will provide exception details for each combination of settings if required, I'm omitting them not to make the post too large. Any ideas on what I can do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文