![](/img/trans.png)
[英]WCF restful service injecting WebOperationContext with Autofac
[英]Injecting wcf channel with autofac
我想在WCF服务(使用Autofac.Integration.Web)中使用autofac来解决对wcf通道的依赖性。 我正在尝试的是这样的事情
Global.asax中
protected void Application_Start(object sender, EventArgs e)
{
var builder = new ContainerBuilder();
builder.RegisterType<CheckingService>();
builder.Register(c => new ChannelFactory<IAuthenticationService>(
new WSHttpBinding("wsHttpBinding_Common"),
new EndpointAddress(ConfigurationManager.AppSettings["AuthenticationServiceUrl"])).CreateChannel())
.SingleInstance();
AutofacHostFactory.Container = builder.Build();
}
使用通道的类:
public AuthorizationManager(IAuthenticationService authenticationServiceClient)
{
AuthenticationServiceClient = authenticationServiceClient;
}
但是我越来越
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
当我尝试使用WCF测试客户端时。
但是,如果我只是在方法中新建频道,客户端不会抱怨:
所以我的理解是我在绑定中做错了什么,但不确定是什么。
public AuthorizationManager()
{
AuthenticationServiceClient = new ChannelFactory<IAuthenticationService>(
new WSHttpBinding("wsHttpBinding_Common"),
new EndpointAddress(ConfigurationManager.AppSettings["AuthenticationServiceUrl"])).CreateChannel();
}
因此,如果我错了,请纠正我,问题应该出在绑定中,但是我不知道我在做什么错。
谢谢
更新
ResourceServiceAuthorizationManager以nuget包的形式出现
public class ResourceServiceAuthorizationManager : ServiceAuthorizationManager
{
public ResourceServiceAuthorizationManager();
public IAuthenticationService AuthenticationServiceClient { get; set; }
public Guid ResourceId { get; set; }
public override bool CheckAccess(OperationContext operationContext);
}
我不确定您是否以正确的方式使用DI来使用WCF服务,但是初始化可能是
builder.Register(c => new ChannelFactory<IAuthenticationService>(
new WSHttpBinding("wsHttpBinding_Common"),
new EndpointAddress(ConfigurationManager.AppSettings["AuthenticationServiceUrl"]))
.CreateChannel()).As<IAuthenticationService>().SingleInstance();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.