我有一個WCF服務,在被簡單的MVC應用程序訪問時工作。使用Autofac通過ChannelFactory註冊端點的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.
我有理由相信我在配置設置兩端沒有任何不匹配的地方,我將這種信心建立在對Autofac不存在的WCF + MVC組合測試完全相同的設置的基礎上。配置設置在pastebin.com/t7wfR77h。
因此,我想一些幫助分析,如果我已經註冊與Autofac的依賴性/端點的方式是問題...
* *的Application_Start代碼MVC應用程序的Autofac設置:
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依賴性ProductController的被注入,很簡單:
public class ProductController : AsyncController
{
private IProductService _service;
public ProductController(IProductService ps)
{
_service = ps;
}
//...
//later simply call
_service.SomeMethod();
}
看起來像一個WCF配置問題給我,沒有太多建議,雖然 - 一些線索在網上... http://blogs.msdn.com/b/endpoint/archive/2010/11/01/wcf- webhttp-service-returns-http-415-unsupported-media-type.aspx祝你好運! – 2011-04-20 10:04:43
@Nicholas,感謝您看到這個,希望這不是一個WCF的問題,所以它很容易解決。 – 2011-04-21 01:52:55
@neontapir也許你應該發佈你的代碼作爲答案,因爲我放棄了這一點,並沒有得到它的工作;) – 2011-10-04 12:12:39