static async Task CallSvcThatUsesReliableCollection() { var def = new PointDefinition() { HostTitle = "host2", // this points to host 2 where a different interfaces are exposed Binding = new NetTcpBinding(), Interfaces = new List<Type>() { typeof(ISomeWcfInterface) } }; FabricClient fc = new FabricClient(); //local cluster var resolvedPartitions = await fc.ServiceManager.ResolveServicePartitionAsync(new Uri(FabricServiceName), "P1"); var ep = resolvedPartitions.Endpoints.SingleOrDefault((endpoint) => endpoint.Role == ServiceEndpointRole.StatefulPrimary); var uri = ep.Address; Console.WriteLine(string.Format("working on {0} host", def.HostTitle )); string result; var channelFactory = new ChannelFactory<ISomeWcfInterface>(new NetTcpBinding(), new EndpointAddress(string.Concat(uri, def.HostTitle, "/", typeof(ISomeWcfInterface).ToString()))); // data interface var channel = channelFactory.CreateChannel(); result = channel.SayHello(parameter); Console.WriteLine(string.Format("opeartion {0} on interface {1} called with {2} returned {3}", "SayHello", "ISomeWcfInterface", parameter, result)); var Count = channel.GetHello(); Console.WriteLine(string.Format("opeartion {0} on interface {1} called with {2} returned {3}", "GetHello", "ISomeWcfInterface", parameter, result)); ((IClientChannel)channel).Close(); // be kind rewind. }
private void StopHost(PointDefinition def) { var host = m_hosts[def.HostTitle]; if (null == host) return; if (CommunicationState.Opened == host.State ) host.Close(); Trace.WriteLine(string.Format("Host {0} stopped", def.HostTitle)); WcfMultiPointServiceHost temp; m_hosts.TryRemove(def.HostTitle, out temp); }
private void AddStartHost(PointDefinition def) { var implementationName = def.ImplementationType.ToString(); var baseAddress = string.Concat(m_listeningAddress, def.HostTitle, "/"); var newHost = new WcfMultiPointServiceHost(StateManager, def.ImplementationType, new Uri(baseAddress)); OnWcfHostCreated(this, def, newHost ); newHost = m_hosts.AddOrUpdate( def.HostTitle, newHost, (s, Current) => { return Current; } ); foreach (var i in def.Interfaces) { var interfaceName = i.ToString(); var binding = (null != m_OverrideBinding) ? m_OverrideBinding : def.Binding; var EndPointAddress = string.Concat(baseAddress, interfaceName); var ep = newHost.AddServiceEndpoint(i, binding, // configure binding here EndPointAddress); OnWcfEndpointAdded(this, def, newHost,ep, i); Trace.WriteLine(string.Format("Host {0} with address:{1} added a new EP:{2}", def.HostTitle, baseAddress, EndPointAddress)); } newHost.Open(); }
private void verifyDefs(PointDefinition[] defs) { if (null == defs) throw new InvalidOperationException("listeing definition is null"); if (0 == defs.Count()) throw new Exception("Listening definition(s) is empty"); // are they unique? foreach (var def in defs) if (1 != defs.Where(current => current.HostTitle == def.HostTitle).Count()) throw new InvalidOperationException("Host titles has to be unique"); var bVerifyBinding = (null == m_OverrideBinding); foreach (var def in defs) def.verifyAndThrow( bVerifyBinding); }
public WcfMultiPointListener(PointDefinition[] defs, string Scheme, Binding overrideBinding) : this(Scheme, defs) { if (null == overrideBinding) throw new NullReferenceException("overrideBinding"); m_OverrideBinding = overrideBinding; }
protected override ICommunicationListener CreateCommunicationListener() { // a point def defines a host and a set of interfaces that will be // exposed as an endpoints along with Binding //each point defi will be exposed as the following: // <listeningaddress>/<host title>/interface type name // unless you override using OnXXX delegates var def1 = new PointDefinition() { HostTitle = "host1", Binding = new NetTcpBinding(), ImplementationType = typeof(WcfService), Interfaces = new List<Type>() { typeof(SvcInterface1), typeof(SvcInterface2) } }; // this one however uses a state manager // from a listener point of view nothing is different // the listner along with WCF extention make sure that each // service implementation instance gets a refernce to state manager var def2 = new PointDefinition() { HostTitle = "host2", Binding = new NetTcpBinding(), ImplementationType = typeof(WcfSvc_SF), Interfaces = new List<Type>() { typeof(ISomeWcfInterface),} }; var listener = new WcfMultiPointListener("net.tcp", def1, def2); listener.StateManager = this.StateManager; // this ensures that state manager used by this // replica instance is shared with wcf services instances. // created by the WcfHost (irrespective of instance model) // if you want to control how listening and publishing addresses are created //listener.OnCreateListeningAddress = (listenerInstance) => { /* return address ere */ }; //listener.OnCreatePublishingAddress = (listenerInstance) => { /* return address ere */ }; // if you want access to host before it opens (i.e add custom behviours, credentials etc) //listener.OnWcfHostCreated = (listenerInstance, pointDef, host) => { /* magic goes here*/}; // same apply for WcfEndPoint //listener.OnWcfHostCreated = (listenerInstance, pointDef, host, endPoint, interfaceType) => { /* magic goes here*/}; // in both cases the host and the PointDef that caused the creation is passed to you return listener; }
static async Task doStuffUsingICommInterfaces(ServicePartitionClient<WcfMultiPointCommunicationClient> partitionClient) { // the client needs those to know which interface is wired to wich host. var PointDef = new PointDefinition() { HostTitle = "host1", Binding = new NetTcpBinding(), Interfaces = new List<Type>() { typeof(SvcInterface1), typeof(SvcInterface2) } }; var defs = new PointDefinition[1] { PointDef }; ; await partitionClient.InvokeWithRetryAsync(client => { if (client.ConnectionStatus == ClientConnectionStatus.NotConnected) client.PointDefinition = defs; foreach (var def in defs) // hosts { Console.WriteLine(string.Format("working on {0} host", def.HostTitle)); string result = string.Empty; // our listner has wired the same 2 interfaces per host var Channel1= client.GetChannel<SvcInterface1>(def, typeof(SvcInterface1)); result = Channel1.SvcInterface1Op1(parameter); Console.WriteLine(string.Format("opeartion {0} on interface {1} called with {2} returned {3}", "SvcInterface1Op1", "SvcInterface1", parameter, result)); result = Channel1.SvcInterface1Op2(parameter); Console.WriteLine(string.Format("opeartion {0} on interface {1} called with {2} returned {3}", "SvcInterface1Op2", "SvcInterface1", parameter, result)); var Channel2 = client.GetChannel<SvcInterface2>(def, typeof(SvcInterface2)); result = Channel2.SvcInterface2Op1(parameter); Console.WriteLine(string.Format("opeartion {0} on interface {1} called with {2} returned {3}", "SvcInterface2Op1", "SvcInterface2", parameter, result)); result = Channel2.SvcInterface2Op2(parameter); Console.WriteLine(string.Format("opeartion {0} on interface {1} called with {2} returned {3}", "SimSessionOp2", "SvcInterface2Op2", parameter, result)); } return Task.Delay(0); }); }