static void Main(string[] args)
{
// 创建DiscoveryClient,使用服务代理 discoveryProxy地址
// Create a DiscoveryEndpoint that points to the DiscoveryProxy
Uri probeEndpointAddress = new Uri("http://localhost:9001/Probe");
DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new WSHttpBinding(), new EndpointAddress(probeEndpointAddress));
DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);
// Find ICalculatorService endpoints in the specified scope
// 特定范围内查找IWCFService终结点
FindCriteria findCriteria = new FindCriteria();
//findCriteria.Scopes.Add(scope);
FindResponse findResponse = discoveryClient.Find(findCriteria);
//打印所有终结点信息
Console.WriteLine("All Endpoints:");
Console.ForegroundColor = ConsoleColor.Yellow;
foreach (EndpointDiscoveryMetadata edm in findResponse.Endpoints)
{
Console.WriteLine("[Address]: {0},[Contract]: {1}",
edm.Address, edm.ContractTypeNames[0].Name);
}
//定义Scope,限制搜索范围
Uri scope = new Uri("http://localhost:8000/");
findCriteria.Scopes.Add(scope);
findResponse = discoveryClient.Find(findCriteria);
//打印所有终结点信息
Console.WriteLine("Special Endpoints:");
Console.ForegroundColor = ConsoleColor.Red;
foreach (EndpointDiscoveryMetadata edm in findResponse.Endpoints)
{
Console.WriteLine("[Address]: {0},[Contract]: {1}",
edm.Address, edm.ContractTypeNames[0].Name);
}
Console.ForegroundColor = ConsoleColor.Yellow;
if (findResponse.Endpoints.Count > 0)
{
//创建服务代理客户端实例
EndpointAddress address = findResponse.Endpoints[0].Address;
IWCFService client = ChannelFactory<IWCFService>.CreateChannel(new WSHttpBinding(), address);
Console.WriteLine("Invoking WCFService at {0}", address);
// 调用SayHello服务操作.
string result = client.SayHello("Frank Xu Lei");
}