private static void PrintConnectionInformation(ICounterActor counterActor) { var actorProxy = counterActor as IActorProxy; if (actorProxy != null) { ResolvedServicePartition rsp; if (actorProxy.ActorServicePartitionClient.TryGetLastResolvedServicePartition(out rsp)) { var endpoint = rsp.GetEndpoint(); Console.WriteLine(); Console.WriteLine( @"Connected to a Counter of an actor {0} hosted by the replica of a {3} Service {1} listening at Address {2}", actorProxy.ActorId, rsp.ServiceName, endpoint.Address, endpoint.Role); } else { Console.WriteLine(); Console.WriteLine( @"Connecting to Counter box of an actor {0} hosted by the replica of Service {1}", actorProxy.ActorId, actorProxy.ActorServicePartitionClient.ServiceUri); } } }
private static void Main(string[] args) { // 1. 引用 Interfaces 类库和 Service Fabric 类库 // 2. 创建客户端,这里使用的是非安全的方式,在网络隔离的情况下, // 客户端和服务端可以使用非安全方式通信 string command = Console.ReadKey().KeyChar.ToString().ToLowerInvariant(); Console.WriteLine(); if (command == "0") { Guid id = Guid.Parse("18B2A607-194A-47CE-BD62-881D196F6DA9"); ICounterActor counterActor = ActorProxy.Create <ICounterActor>(new ActorId(id), new Uri("fabric:/CounterDemo/CounterActorService")); counterActor.ResetAsync().Wait(); } if (command == "1") { Guid id = Guid.Parse("18B2A607-194A-47CE-BD62-881D196F6DA9"); ICounterActor counterActor = ActorProxy.Create <ICounterActor>(new ActorId(id), new Uri("fabric:/CounterDemo/CounterActorService")); do { try { Console.WriteLine(counterActor.CountAsync().Result); } catch (Exception e) { Console.WriteLine(e); } } while (true); } if (command == "2") { ICounterActor counterActor = ActorProxy.Create <ICounterActor>(ActorId.CreateRandom(), new Uri("fabric:/CounterDemo/CounterActorService")); do { try { Console.WriteLine(counterActor.CountAsync().Result); } catch (Exception e) { Console.WriteLine(e); } } while (true); } }