コード例 #1
0
        public LegendsOfKesmaiSurvival.Core.GameStateInformation.ServerInstanceInformation HostZombiesInstance(Zombies.ZombiesService zombiesService)
        {
            LegendsOfKesmaiSurvival.Core.GameStateInformation.ServerInstanceInformation serverInstanceInformation = new Core.GameStateInformation.ServerInstanceInformation();
            serverInstanceInformation.ServerId = Guid.NewGuid();

            //TODO:Currently this will get any free tcp port on the server.  This works but it needs to be a known range so that port forwarding can
            //be setup for that known range.
            string baseAddress = "net.tcp://" + System.Environment.MachineName + ":" + GetFreeTcpPort().ToString() + "/LegendsOfKesmaiSurvival/Zombies";

            NamedServiceHost host = new NamedServiceHost(zombiesService, new Uri(baseAddress));

            host.Name = serverInstanceInformation.ServerId.ToString();

            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true);

            binding.MaxBufferSize               = int.MaxValue;
            binding.MaxReceivedMessageSize      = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            binding.SendTimeout = TimeSpan.FromSeconds(10);

            ServiceEndpoint gamePlayEndpoint = host.AddServiceEndpoint(typeof(Zombies.IGameplay), binding, "/Gameplay");

            serverInstanceInformation.GameplayUri = new Uri(baseAddress + "/Gameplay");

            host.ServerInstanceInformation = serverInstanceInformation;
            host.Open();

            this.ServiceHosts.Add(host);

            return(serverInstanceInformation);
        }
コード例 #2
0
        private void InitializeNamedServiceHost(string name, string address, Type serviceType, Type endPointType)
        {
            NamedServiceHost host = new NamedServiceHost(serviceType, new Uri(address));

            host.Name = name;

            //Uncomment this line to send all incoming and outoing messages to the console
            //host.Description.Behaviors.Add(new ConsoleMessageTracing());

            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true);

            binding.MaxBufferSize               = int.MaxValue;
            binding.MaxReceivedMessageSize      = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            binding.SendTimeout = TimeSpan.FromSeconds(10);

            //// ** DISCOVERY ** //
            //// make the service discoverable by adding the discovery behavior
            //host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());

            //// ** DISCOVERY ** //
            //// add the discovery endpoint that specifies where to publish the services
            //host.AddServiceEndpoint(new UdpDiscoveryEndpoint());


            ServiceEndpoint endpoint = host.AddServiceEndpoint(endPointType, binding, "");

            //Add exception marshalling behavior to the host so that it can throw exceptions to clients
            endpoint.Behaviors.Add(new LegendsOfKesmaiSurvival.Core.Exceptions.ExceptionMarshallingBehavior());

            host.Open();

            this.ServiceHosts.Add(host);
        }