大约有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));
}
答案 0 :(得分:0)
您可以添加其他服务行为并启用HttpGetEnabled属性。
ServiceMetadataBehavior b = new ServiceMetadataBehavior { HttpGetEnabled = true };
b.HttpGetUrl = myMetadataUri;
routingsvchost.Description.Behaviors.Add(b);