在下面的代码中,我收到错误消息。我想这是简单或不可能的事情,因为我无法与谷歌找到任何东西。无论如何,我得到的错误是:
合同名称' SchippersStop.Wcf.Balie.Interfaces.IBalie'无法在服务&System; Service.ServiceModel.Routing.RoutingService'。
实施的合同列表中找到。
当我尝试将ServiceEndpoint添加到主机时发生错误。
ServiceHost host = new ServiceHost(typeof(RoutingService));
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
foreach (string dll in Directory.GetFiles(path, "*.dll"))
{
Assembly assembly = Assembly.LoadFile(dll);
foreach (Type type in assembly.GetTypes())
{
if (type.GetInterfaces().Contains(typeof(ISchippersStopSvc)))
{
DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindCriteria findCriteria = new FindCriteria(type);
findCriteria.Duration = TimeSpan.FromSeconds(10);
FindResponse findResponse = discoveryClient.Find(findCriteria);
EndpointDiscoveryMetadata discoveryMetadata = findResponse.Endpoints.First();
Uri uri = discoveryMetadata.Address.Uri;
string routerAddress = uri.AbsoluteUri.Replace(uri.Host, "0.0.0.0");
DiscoveryClientBindingElement discoveryBindingElement = new DiscoveryClientBindingElement();
discoveryBindingElement.FindCriteria = findCriteria;
discoveryBindingElement.DiscoveryEndpointProvider = new UdpDiscoveryEndpointProvider();
CustomBinding binding = new CustomBinding();
binding.Elements.Insert(0, discoveryBindingElement);
ContractDescription contract = ContractDescription.GetContract(type);
RoutingConfiguration rc = new RoutingConfiguration();
rc.RouteOnHeadersOnly = true;
string groupName = Guid.NewGuid().ToString();
foreach (EndpointDiscoveryMetadata endpoint in findResponse.Endpoints)
{
List<ServiceEndpoint> endpointList = new List<ServiceEndpoint>();
ServiceEndpoint client = new ServiceEndpoint(contract, binding, new EndpointAddress(endpoint.Address.Uri.AbsoluteUri));
endpointList.Add(client);
endpointList.AddRange(findResponse.Endpoints.Except(new List<EndpointDiscoveryMetadata>() { endpoint }).Select(s => new ServiceEndpoint(contract, binding, new EndpointAddress(s.Address.Uri.AbsoluteUri))).ToList());
endpointList.ForEach(f => f.EndpointBehaviors.Add(new ClientTrackerEndpointBehavior() { }));
rc.FilterTable.Add(new CustomMessageFilter(groupName), endpointList);
}
RoutingBehavior routing = new RoutingBehavior(rc);
host.Description.Behaviors.Add(routing);
// Here the error occurs
host.AddServiceEndpoint(type, binding, routerAddress);
}
}
}
目标是将在网络上发现的WCF服务添加到路由器。但是我想以这样的方式进行设置:我不需要知道有关服务的任何信息,路由器可以检测所有必要的配置,之后它可以动态加载它们。我唯一要提供给路由器的是ServiceContract。路由器可以根据它们继承的公共接口检测具有ServiceContract的程序集。
有人可以帮我解决这个错误吗?