如何在WCF Rest中触发Autofac构造函数注入?

如何在WCF Rest中触发Autofac构造函数注入?,wcf,rest,autofac,Wcf,Rest,Autofac,我正在构建一个WCF REST服务,并希望使用Autofac作为DI容器。我希望能够调用服务类的参数化构造函数。下面是我的代码: [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession

我正在构建一个WCF REST服务,并希望使用Autofac作为DI容器。我希望能够调用服务类的参数化构造函数。下面是我的代码:

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public partial class QDService:IQDService
{
    public QDService(IApplicationService appService)
    {
        this.appService = appService;
    }

    private readonly IApplicationService appService;
}
然后在global.asax中,我通过以下方式设置配置:

启动项目并浏览到

http://localhost:1685/QDService/Test/1
浏览器向我抛出一个异常,如:

The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service.
,我使用firebug跟踪它,发现了以下内容:


我不知道是什么原因导致了这一点,但在我删除参数化构造函数之后,所有这些都对我很好。然后我在网上快速搜索了一下,但什么也没有得到。需要您的帮助,thx。

我在这里发布了一个博客,跟踪解决此问题时遇到的所有步骤:


它是用中文写的,有时间我会把它翻译成英文,谢谢。

I你调试服务,它是否在构造函数中中断,appService是否从容器中解析?@Jon_Lindeheim每次我刷新页面时,调试点未被触发,但引发了如上所述的异常。我已通过网络检查了该表达式,发现我的请求中可能存在某些格式错误。但我仔细检查了一下,什么也没发现,所以连线了。@Jon_Lindeheim,现在我可以调试了。我可以用c语言编写一个新实例,它可以由ioc容器创建。但是为什么我可以返回字符串方法,列表方法不会返回任何数据?@Jon_Lindeheim嗨,我已经解决了这个问题!!!!!我将发布一个博客来跟踪这一点,以防我将来使用它。无论如何。
http://localhost:1685/QDService/Test/1
The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service.