我正在编写一个简单的WCF服务并将其托管在控制台应用程序中。Castle WcfFacility Publishing MEX Endpoints
我知道服务正在运行,因为一个简单的客户端可以执行暴露在服务上的操作。
如果我点了WCF测试客户端对我的服务,我收到以下错误(注tempuri.com真的本地主机,但计算器要求我要么把这个包输出作为一个代码块或包括FQDN):
System.InvalidOperationException : Metadata contains a reference that cannot be resolved: ' http://tempuri.com:27198/UsingWindsor.svc?wsdl '. ----> System.ServiceModel.ProtocolException : Content Type application/soap+xml; charset=utf-8 was not supported by service http://tempuri.com:27198/UsingWindsor.svc?wsdl . The client and service bindings may be mismatched. ----> System.Net.WebException : The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type '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"))));