我有一个以简单MVC申请取用的WCF服务。
当我试图从一个不同的MVC中发出同样终点的电线时,与Autofac连接起来。 我收到约束/合同不匹配的例外。 类似:
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:6985/ProductService.svc. The client and service bindings may be mismatched.
System.Net.WebException: The remote server returned an error: (415) Unsupported Media Type.
I m reasonably confident I do not have a mismatch in the configuration settings on either end, I base this confidence on testing the exact same settings on a WCF + MVC combination where Autofac is not present. The config settings are on pastebin.com/t7wfR77h.
因此,如果我与自治州登记扶养/最后任命的方式是问题的话,我会有所帮助。
*Application_Start* code in MVC app for Autofac setup:
var builder = new ContainerBuilder();
//other registrations...
builder.Register(c =>
new ChannelFactory<IProductService>(
new WSHttpBinding("ProductService_wsHttpBinding"),
new EndpointAddress("http://localhost:6985/ProductService.svc")
)
).SingleInstance();
builder.Register(c =>
{
var factory = c.Resolve<ChannelFactory<IProductService>>();
return factory.CreateChannel();
}
).InstancePerHttpRequest();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
(完整性)在我使用这一工具时,只需要注入1个依赖性的产品主计长,非常简单:
public class ProductController : AsyncController
{
private IProductService _service;
public ProductController(IProductService ps)
{
_service = ps;
}
//...
//later simply call
_service.SomeMethod();
}