// Return the current communication channel between the external client and this web role instance;
        // Plus, return the internal channel between this web role instance and all work role instances.
        public string GetCommunicationChannel()
        {
            string thisWebRoleChannel = string.Format("You are talking to the workroles via {0}.",
                                                      OperationContext.Current.Channel.LocalAddress.Uri.ToString());

            // Contact the workrole and get the channel info
            string workRoleChannel = string.Empty;

            System.Text.StringBuilder sb = new StringBuilder();

            var roles = RoleEnvironment.Roles["WorkerRole1"];

            foreach (var instance in roles.Instances)
            {
                RoleInstanceEndpoint workRoleInternalEndPoint = instance.InstanceEndpoints["Internal"];
                NetTcpBinding        binding    = new NetTcpBinding(SecurityMode.None, false);
                EndpointAddress      myEndpoint = new EndpointAddress(String.Format("net.tcp://{0}/Internal",
                                                                                    workRoleInternalEndPoint.IPEndpoint));

                ChannelFactory <IContract> myChanFac = new ChannelFactory <WCFContract.IContract>(binding, myEndpoint);
                WCFContract.IContract      myClient  = myChanFac.CreateChannel();
                sb.Append(myClient.GetCommunicationChannel() + "\n");
            }
            workRoleChannel = sb.ToString();

            return(thisWebRoleChannel + "\n" + workRoleChannel);
        }
        // Return the current web role's name and instance id;
        // Plus, this web role instance talks to a work role instance via internal endpoint, and get
        // the work role's instance data.
        public string GetRoleInfo()
        {
            RoleInstance currentRoleInstance = RoleEnvironment.CurrentRoleInstance;
            string       roleName            = currentRoleInstance.Role.Name;
            string       roleInstanceID      = currentRoleInstance.Id;
            string       thisWR = string.Format("You are talking to the workroles via role {0}, instance ID {1}\n.",
                                                roleName, roleInstanceID);

            // Contact the workrole and get its info
            string workRoleInfo = string.Empty;

            System.Text.StringBuilder sb = new StringBuilder();

            var roles = RoleEnvironment.Roles["WorkerRole1"];

            foreach (var instance in roles.Instances)
            {
                RoleInstanceEndpoint WorkRoleInternalEndPoint = instance.InstanceEndpoints["Internal"];
                NetTcpBinding        binding    = new NetTcpBinding(SecurityMode.None, false);
                EndpointAddress      myEndpoint = new EndpointAddress(String.Format("net.tcp://{0}/Internal",
                                                                                    WorkRoleInternalEndPoint.IPEndpoint));

                ChannelFactory <IContract> myChanFac = new ChannelFactory <WCFContract.IContract>(binding, myEndpoint);
                WCFContract.IContract      myClient  = myChanFac.CreateChannel();
                sb.Append(myClient.GetRoleInfo() + "\n");
            }
            workRoleInfo = sb.ToString();

            return(thisWR + "\n" + workRoleInfo);
        }