首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >城堡WcfFacility发布MEX端点

城堡WcfFacility发布MEX端点
EN

Stack Overflow用户
提问于 2013-11-25 20:34:43
回答 1查看 480关注 0票数 0

我正在编写一个简单的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中修改了一个测试,以显示我所遇到的相同错误(当然,它不需要修改):

代码语言:javascript
复制
[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时,为什么这个测试会失败?我在控制台应用程序中的配置非常类似于修改后的测试。(包括完整性)

代码语言:javascript
复制
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"))));
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-26 16:16:24

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

我改变了注册方式:

代码语言:javascript
复制
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"))));

对此:

代码语言:javascript
复制
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时删除它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20202744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档