wcf路由器没有';t公开元数据

本文关键字:元数据 路由器 wcf | 更新日期: 2023-09-27 18:22:41

大约有30个wcf服务,我们使用wcf路由器来分发来自客户端的请求。wcf服务由windows服务托管。当我们将客户端和服务放在同一台计算机中时,客户端和服务可以相互联系。但是,当它们在不同的机器中时,客户端无法联系服务。我也使用wcftestclient来测试服务,但它总是无法添加服务,或者如果我使用添加的客户端项目来测试它,它就无法添加服务。如果服务与客户端在不同的机器上,则所有单个服务都使用net.pipe,而路由器则使用net.tcp。我已经做了几个星期了,问题仍然存在。有人能指出它可能出了什么问题吗?非常感谢!

我们有一个设置配置文件,供最终用户输入服务服务器地址的名称。端口号也将在设置文件中。

    if (!this._issinglecomputer)
        {
            // now add protocol conversion router
            Uri routerbaseaddress = new Uri(publicbaseaddress, "router");
            _routingsvchost = new ServiceHost(typeof(RoutingService), routerbaseaddress);
            _routingsvchostmex = new ServiceHost(typeof (RoutingService), new Uri(routerbaseaddress, "mex"));
            // add the endpoint the router will use to receive service requests
            // we use IDuplexSessionRouter to support a variety of one-way and two-way calls
            _routingsvchost.AddServiceEndpoint(typeof(IDuplexSessionRouter), new NetTcpBinding(SecurityMode.None), "");
            _routingsvchostmex.AddServiceEndpoint(typeof(IDuplexSessionRouter), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
            // add routing config
            RoutingConfiguration rc = new RoutingConfiguration();
            // loop over all the hosted interfaces and add the entries to the routing table
            foreach (IWcfServiceLibrary sl in wcfServiceLibraries)
            {
                foreach (IWcfServiceConfig config in sl.WcfServiceConfigs)
                {
                    string routedservice = config.WcfService.ServiceClassName.Split('.').Last();
                    var contract = ContractDescription.GetContract(typeof(ISimplexDatagramRouter));
                    var client = new ServiceEndpoint(contract, new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), new EndpointAddress("net.pipe://localhost/" + routedservice));
                    var ea = new EndpointAddress(routerbaseaddress.AbsoluteUri.ToString() + "/" + routedservice);
                    rc.FilterTable.Add(new EndpointAddressMessageFilter(ea, false), new List<ServiceEndpoint>() { client });
                }
            }
            _routingsvchost.Description.Behaviors.Add(new RoutingBehavior(rc));
            _routingsvchostmex.Description.Behaviors.Add(new RoutingBehavior(rc));
            _routingsvchost.Open();
            _routingsvchostmex.Open();

            LoggingService.Logger.Info(string.Format("It is now routing services at {0}", routerbaseaddress.AbsoluteUri));
        }

wcf路由器没有';t公开元数据

您可以添加另一个服务行为并打开HttpGetEnabled属性。

ServiceMetadataBehavior b = new ServiceMetadataBehavior { HttpGetEnabled = true };
b.HttpGetUrl = myMetadataUri;
routingsvchost.Description.Behaviors.Add(b);