【发布时间】:2013-12-10 18:00:02
【问题描述】:
我正在编写一个简单的 WCF 服务并将其托管在控制台应用程序中。
我知道服务正在运行,因为一个简单的客户端可以执行服务上公开的操作。
如果我将 Wcf 测试客户端指向我的服务,我会收到以下错误(注意 tempuri.com 实际上是 localhost,但 stackoverflow 要求我将此输出包装为代码块或包含 FQDN):
System.InvalidOperationException:元数据包含无法解析的引用:'http://tempuri.com:27198/UsingWindsor.svc?wsdl'。 ----> System.ServiceModel.ProtocolException : 内容类型 application/soap+xml;服务 http://tempuri.com:27198/UsingWindsor.svc?wsdl 不支持 charset=utf-8。客户端和服务绑定可能不匹配。 ----> System.Net.WebException:远程服务器返回错误:(415)无法处理消息,因为内容类型'application/soap+xml; charset=utf-8' 不是预期的类型 'text/xml; charset=utf-8'..
不完全理解错误,我开始使用 WcfFacility 中的测试。
我已经修改了 Castle.Facilities.WcfIntegration.Tests.ServiceHostFixture 中的一个测试,以显示我遇到的相同错误(当然它可以在没有修改的情况下工作):
[Test]
public void CanPubishMEXEndpointsUsingDefaults()
{
using (new WindsorContainer()
.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
.Register(Component.For<Operations>()
.DependsOn(new { number = 42 })
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses(
//"net.tcp://localhost/Operations",
"http://localhost:27198/UsingWindsor.svc")
.AddEndpoints(
WcfEndpoint.ForContract<IOperations>()
//.BoundTo(new NetTcpBinding { PortSharingEnabled = true })
.BoundTo(new BasicHttpBinding())
)
.PublishMetadata(mex => mex.EnableHttpGet())
)
))
{
//var tcpMextClient = new MetadataExchangeClient(new EndpointAddress("net.tcp://localhost/Operations/mex"));
//var tcpMetadata = tcpMextClient.GetMetadata();
//Assert.IsNotNull(tcpMetadata);
var httpMextClient = new MetadataExchangeClient(new EndpointAddress("http://localhost:27198/UsingWindsor.svc?wsdl"));
var httpMetadata = httpMextClient.GetMetadata();
Assert.IsNotNull(httpMextClient);
}
}
当我消除 NetTcp 绑定并绑定到 Http 时,为什么这个测试会失败?我在控制台应用程序中的配置与修改后的测试非常相似。 (包括完整性)
container.Register(Component.For<ISimpleService>()
.ImplementedBy<SimpleService>()
.AsWcfService(new DefaultServiceModel()
.AddBaseAddress("http://localhost:515")
.PublishMetadata(x => x.EnableHttpGet())
.AddEndPoints(WcfEndpoint.ForContract<ISimpleService>().BoundTo(new BasicHttpBinding()).At("SimpleService"))));
【问题讨论】:
标签: wcf castle-windsor wcffacility