2013-11-25 42 views
0

我正在编写一个简单的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")))); 

回答

0

不太确定为什么测试失败,但我确实解决了我的问题。

我从这个改变了登记:

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” 和限定的端点时将其删除。