我正在编写一个简单的WCF服务,并将其托管在控制台应用程序中。
我知道该服务正在运行,因为一个简单的客户端可以执行在服务上公开的操作。
如果我将Wcf客户端指向我的服务,我将收到以下错误(注意,tempuri.com实际上是本地主机,但堆栈溢出要求我将此输出包装为代码块或包含一个FQDN):
System.InvalidOperationException :元数据包含一个无法解析的引用:“http://tempuri.com:27198/UsingWindsor.svc?wsdl”。-> System.ServiceModel.ProtocolException : Content应用程序/soap+xml;charset=utf-8不受服务http://tempuri.com:27198/UsingWindsor.svc?wsdl支持。客户端绑定和服务绑定可能不匹配。-> 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"))));发布于 2013-11-26 16:16:24
不太清楚为什么考试失败了,但我确实解决了我的问题。
我改变了注册方式:
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"))));对此:
container.Register(Component.For<ISimpleService>()
.ImplementedBy<SimpleService>()
.AsWcfService(new DefaultServiceModel()
.AddBaseAddress("http://localhost:515/SimpleService")
.PublishMetadata(x => x.EnableHttpGet())
.AddEndPoints(WcfEndpoint.ForContract<ISimpleService>().BoundTo(new BasicHttpBinding()))));在定义BaseAddress时,我现在包含"SimpleService“,并在定义EndPoints时删除它。
https://stackoverflow.com/questions/20202744
复制相似问题