wcf路由器不公开元数据

问题描述:

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

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

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)); 
     } 

您可以添加其他服务行为并打开HttpGetEnabled属性。

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

我试过了,它仍然有问题。我想知道它是否可以来自配置部分以外的其他地方。 – 2014-09-23 18:59:12

+0

你的metaDataUri与代码中的一个匹配吗? – 2014-09-23 19:16:20