Ejemplo n.º 1
0
    static void RunCodeUnderDiscoveryHost(Uri serviceUri, Uri dHostUri, Action <Uri, AnnouncementEndpoint, DiscoveryEndpoint> action)
    {
        var aEndpoint = new UdpAnnouncementEndpoint(DiscoveryVersion.WSDiscoveryApril2005, new Uri("soap.udp://239.255.255.250:3802/"));
        var dbinding  = new CustomBinding(new HttpTransportBindingElement());
        var dAddress  = new EndpointAddress(dHostUri);
        var dEndpoint = new DiscoveryEndpoint(dbinding, dAddress);

        var ib = new InspectionBehavior();

        ib.RequestReceived += delegate(ref Message msg, IClientChannel
                                       channel, InstanceContext instanceContext) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
            return(null);
        };
        ib.ReplySending += delegate(ref Message msg, object o) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
        };

        dEndpoint.Behaviors.Add(ib);
        aEndpoint.Behaviors.Add(ib);

        action(serviceUri, aEndpoint, dEndpoint);
    }
Ejemplo n.º 2
0
        private static void Main()
        {
            var proxyUri      = new Uri("net.tcp://localhost:8001/Probe");
            var proxyBinding  = new NetTcpBinding(SecurityMode.None);
            var proxyEndpoint = new DiscoveryEndpoint(proxyBinding, new EndpointAddress(proxyUri));

            var svcBinding = new NetTcpBinding(SecurityMode.None);
            var svcFactory = new ChannelFactory <ICombateSvcChannel>(svcBinding);

            GameMaster.Init(proxyEndpoint, svcFactory);

            var selfHost = new ServiceHost(typeof(GameMasterSvc));

            try
            {
                selfHost.Open();
                Console.WriteLine("Game Server started.");
                Console.WriteLine();
            }
            catch (Exception e)
            {
                switch (e)
                {
                case CommunicationObjectFaultedException _:
                case EndpointNotFoundException _:
                    Console.WriteLine("The Discovery Proxy couldn't be reached.");
                    break;

                case TimeoutException _:
                    Console.WriteLine("The Discovery Proxy is unresponsive.");
                    break;

                case CommunicationException _:
                    Console.WriteLine("The Discovery Proxy refused the connection.");
                    break;

                default:
                    Console.WriteLine(e);
                    break;
                }
                Console.WriteLine();

                selfHost.Abort();
            }

            Console.WriteLine("Press <ENTER> to terminate the server.");
            Console.WriteLine();
            Console.ReadLine();

            try
            {
                selfHost.Close();
            }
            catch (Exception)
            {
                selfHost.Abort();
            }

            GameMaster.ProbeClientReseter.Dispose();
        }
Ejemplo n.º 3
0
    static void RunCodeUnderDiscoveryHost(Uri serviceUri, Action <Uri, DiscoveryEndpoint> action)
    {
        var dBinding  = new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement());
        var dEndpoint = new DiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc, dBinding, new EndpointAddress("net.tcp://" + hostname + ":9090/"));
        var ib        = new InspectionBehavior();

        ib.RequestSending += delegate(ref Message msg, IClientChannel channel) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.WriteLine(mb.CreateMessage());
            return(null);
        };
        ib.ReplyReceived += delegate(ref Message msg, object id) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.WriteLine(mb.CreateMessage());
        };
        ib.ReplySending += delegate(ref Message msg, object o) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
        };
        ib.RequestReceived += delegate(ref Message msg, IClientChannel channel, InstanceContext instanceContext) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
            return(null);
        };
        dEndpoint.Behaviors.Add(ib);

        action(serviceUri, dEndpoint);
    }
Ejemplo n.º 4
0
        static EndpointAddress FindCalculatorServiceAddress()
        {
            // Create DiscoveryClient
            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DiscoveryRouter/"));
            DiscoveryClient   discoveryClient   = new DiscoveryClient(discoveryEndpoint);

            Console.WriteLine("Finding ICalculatorService endpoints...");
            Console.WriteLine();

            // Find ICalculatorService endpoints
            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));

            findCriteria.Duration = TimeSpan.FromSeconds(10);

            FindResponse findResponse = discoveryClient.Find(findCriteria);

            Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
            Console.WriteLine();

            if (findResponse.Endpoints.Count > 0)
            {
                return(findResponse.Endpoints[0].Address);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 启动服务发现代理托管器
        /// </summary>
        /// <returns>服务宿主</returns>
        public ServiceHost Open()
        {
            if (proxyHost != null && proxyHost.State != CommunicationState.Closed)
            {
                throw new InvalidProgramException("This proxy host has been opened.");
            }

            // create a new service host with a singleton proxy
            proxyHost = new ServiceHost(new T());

            // create the discovery endpoint
            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(ServiceConfiguration.DefaultNetTcpBindingName), new EndpointAddress(proxyAddress));

            discoveryEndpoint.IsSystemEndpoint = false;

            // add UDP Annoucement endpoint
            proxyHost.AddServiceEndpoint(new UdpAnnouncementEndpoint());

            // add the discovery endpoint
            proxyHost.AddServiceEndpoint(discoveryEndpoint);

            proxyHost.Open();
            Console.WriteLine("Discovery Proxy {0}", proxyAddress);

            return(proxyHost);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            DiscoveryEndpoint dsed1, dsed2;

            dsed1 = new DiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005, ServiceDiscoveryMode.Adhoc);
            dsed2 = new DiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005, ServiceDiscoveryMode.Managed);
            Console.WriteLine($"WSDiscoveryApril2005 dsed1 {dsed1.Contract.ContractType.Name } dsed2 {dsed2.Contract.ContractType.Name }");

            dsed1 = new DiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc);
            dsed2 = new DiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Managed);
            Console.WriteLine($"WSDiscoveryApril2005 dsed1 {dsed1.Contract.ContractType.Name } dsed2 {dsed2.Contract.ContractType.Name }");

            dsed1 = new DiscoveryEndpoint(DiscoveryVersion.WSDiscoveryCD1, ServiceDiscoveryMode.Adhoc);
            dsed2 = new DiscoveryEndpoint(DiscoveryVersion.WSDiscoveryCD1, ServiceDiscoveryMode.Managed);
            Console.WriteLine($"WSDiscoveryApril2005 dsed1 {dsed1.Contract.ContractType.Name } dsed2 {dsed2.Contract.ContractType.Name }");

            AnnouncementEndpoint announcementEndpoint;

            announcementEndpoint = new AnnouncementEndpoint(DiscoveryVersion.WSDiscovery11);
            Console.WriteLine($"WSDiscovery11 dsed1 {announcementEndpoint.Contract.ContractType.Name } ");

            announcementEndpoint = new AnnouncementEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
            Console.WriteLine($"WSDiscoveryApril2005 dsed1 {announcementEndpoint.Contract.ContractType.Name } ");

            announcementEndpoint = new AnnouncementEndpoint(DiscoveryVersion.WSDiscoveryCD1);
            Console.WriteLine($"WSDiscoveryCD1 dsed1 {announcementEndpoint.Contract.ContractType.Name } ");
            Console.Read();
        }
Ejemplo n.º 7
0
        void RunCodeUnderDiscoveryHost1(Uri serviceUri, Uri dHostUri, Uri aHostUri, Action <Uri, AnnouncementEndpoint, DiscoveryEndpoint> action)
        {
            // announcement service
            var abinding  = new CustomBinding(new HttpTransportBindingElement());
            var aAddress  = new EndpointAddress(aHostUri);
            var aEndpoint = new AnnouncementEndpoint(abinding, aAddress);

            // discovery service
            var dbinding  = new CustomBinding(new HttpTransportBindingElement());
            var dAddress  = new EndpointAddress(dHostUri);
            var dEndpoint = new DiscoveryEndpoint(dbinding, dAddress);

            // Without this, .NET rejects the host as if it had no service.
            dEndpoint.IsSystemEndpoint = false;

            // it internally hosts an AnnouncementService
            using (var inst = new AnnouncementBoundDiscoveryService(aEndpoint)) {
                var host = new ServiceHost(inst);
                host.AddServiceEndpoint(dEndpoint);
                try {
                    host.Open();
                    action(serviceUri, aEndpoint, dEndpoint);
                } finally {
                    host.Close();
                }
            }
        }
        static DiscoveryEndpoint ValidateAndGetDiscoveryEndpoint(ChannelEndpointElement channelEndpointElement)
        {
            if (string.IsNullOrEmpty(channelEndpointElement.Kind))
            {
                throw FxTrace.Exception.AsError(
                          new ConfigurationErrorsException(
                              SR2.DiscoveryConfigDiscoveryEndpointMissingKind(
                                  typeof(DiscoveryEndpoint).FullName)));
            }

            ServiceEndpoint serviceEndpoint = ConfigLoader.LookupEndpoint(channelEndpointElement, null);

            if (serviceEndpoint == null)
            {
                throw FxTrace.Exception.AsError(
                          new ConfigurationErrorsException(
                              SR2.DiscoveryConfigInvalidEndpointConfiguration(
                                  channelEndpointElement.Kind)));
            }

            DiscoveryEndpoint discoveryEndpoint = serviceEndpoint as DiscoveryEndpoint;

            if (discoveryEndpoint == null)
            {
                throw FxTrace.Exception.AsError(
                          new InvalidOperationException(
                              SR2.DiscoveryConfigInvalidDiscoveryEndpoint(
                                  typeof(DiscoveryEndpoint).FullName,
                                  channelEndpointElement.Kind,
                                  serviceEndpoint.GetType().FullName)));
            }

            return(discoveryEndpoint);
        }
        public TService Discover <TService>() where TService : class
        {
            var discoveryBinding = _options.DiscoveryBindingFactory.Invoke();

            if (!string.Equals(discoveryBinding.Scheme, _options.ProbeEndpoint.Scheme))
            {
                throw new ArgumentException("ProbeEndpoint is not valid for the given DiscoveryBinding", nameof(ServiceModelDiscoveryOptions.ProbeEndpoint));
            }

            var probeEndpointAddress = new EndpointAddress(_options.ProbeEndpoint);
            var discoveryEndpoint    = new DiscoveryEndpoint(discoveryBinding, probeEndpointAddress);

            try
            {
                var criteria = new FindCriteria(typeof(TService));

                var endpoints = _discoveryClient.FindEndpoints(discoveryEndpoint, criteria);

                var items = from endpoint in endpoints
                            let binding = _bindingFactory.Create(typeof(TService), endpoint.Address.Uri.Scheme)
                                          where binding != null
                                          let channel = _channelFactory.CreateChannel <TService>(binding, endpoint.Address)
                                                        select channel;

                return(items.FirstOrDefault());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"An error occurred while resolving the service {typeof(TService).Name}");
            }

            return(null);
        }
        private DiscoveryEndpoint DiscoverEndpoint(DiscoveryEndpoint endpoint, bool required)
        {
            using (var discover = new DiscoveryClient(UdpDiscoveryEndpoint ?? new UdpDiscoveryEndpoint()))
            {
                var criteria = new FindCriteria(endpoint.Contract.ContractType)
                {
                    MaxResults = 1
                };
                if (DiscoveryDuration.HasValue)
                {
                    criteria.Duration = DiscoveryDuration.Value;
                }

                var discovered = discover.Find(criteria);
                if (discovered.Endpoints.Count > 0)
                {
                    var endpointMetadata = discovered.Endpoints[0];
                    var binding          = Binding ?? AbstractChannelBuilder.GetBindingFromMetadata(endpointMetadata);
                    return(new DiscoveryEndpoint(binding, endpointMetadata.Address));
                }

                if (required)
                {
                    throw new EndpointNotFoundException("Unable to locate a ServiceCatalog on the network.");
                }

                return(null);
            }
        }
Ejemplo n.º 11
0
        public List <AlexaProperty> FindRelatedProperties(IPremiseObject endpoint, string currentController)
        {
            List <AlexaProperty> relatedProperties = new List <AlexaProperty>();

            DiscoveryEndpoint discoveryEndpoint = PremiseServer.GetDiscoveryEndpointAsync(endpoint).GetAwaiter().GetResult();

            if (discoveryEndpoint == null)
            {
                return(relatedProperties);
            }

            foreach (Capability capability in discoveryEndpoint.capabilities)
            {
                if (capability.@interface == currentController)
                {
                    continue;
                }

                if (PremiseServer.Controllers.ContainsKey(capability.@interface))
                {
                    IAlexaController controller = PremiseServer.Controllers[capability.@interface];
                    controller.SetEndpoint(endpoint);
                    relatedProperties.AddRange(controller.GetPropertyStates());
                }
            }

            return(relatedProperties);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            // Create a DiscoveryEndpoint that points to the DiscoveryProxy
            Uri probeEndpointAddress            = new Uri("net.tcp://localhost:8001/Probe");
            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress(probeEndpointAddress));

            DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);

            Console.WriteLine("Finding ICalculatorService endpoints using the proxy at {0}", probeEndpointAddress);
            Console.WriteLine();

            try
            {
                // Find ICalculatorService endpoints
                FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(ICalculatorService)));

                Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
                Console.WriteLine();

                // Check to see if endpoints were found, if so then invoke the service.
                if (findResponse.Endpoints.Count > 0)
                {
                    InvokeCalculatorService(findResponse.Endpoints[0].Address);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("This client was unable to connect to and query the proxy. Ensure that the proxy is up and running.");
            }

            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
    /// <summary>
    /// Parses a URL and turns it into authority and discovery endpoint URL.
    /// </summary>
    /// <param name="input">The input.</param>
    /// <param name="path">The path to the discovery document. If not specified this defaults to .well-known/open-id-configuration</param>
    /// <returns></returns>
    /// <exception cref="System.InvalidOperationException">
    /// Malformed URL
    /// </exception>
    public static DiscoveryEndpoint ParseUrl(string input, string path = null)
    {
        if (String.IsNullOrEmpty(path))
        {
            path = OidcConstants.Discovery.DiscoveryEndpoint;
        }

        var success = Uri.TryCreate(input, UriKind.Absolute, out var uri);

        if (success == false)
        {
            throw new InvalidOperationException("Malformed URL");
        }

        if (!DiscoveryEndpoint.IsValidScheme(uri))
        {
            throw new InvalidOperationException("Malformed URL");
        }

        var url = input.RemoveTrailingSlash();

        if (path.StartsWith("/"))
        {
            path = path.Substring(1);
        }

        if (url.EndsWith(path, StringComparison.OrdinalIgnoreCase))
        {
            return(new DiscoveryEndpoint(url.Substring(0, url.Length - path.Length - 1), url));
        }
        else
        {
            return(new DiscoveryEndpoint(url, url.EnsureTrailingSlash() + path));
        }
    }
Ejemplo n.º 14
0
        public DiscoveredEndpointModel ManagedBy(BindingAddressEndpointModel endpoint)
        {
            var endpointAddress = endpoint.EndpointAddress ?? new EndpointAddress(endpoint.Address);

            DiscoveryEndpoint = new DiscoveryEndpoint(endpoint.Binding, endpointAddress);
            return(this);
        }
Ejemplo n.º 15
0
        void UseCase1Core(Uri serviceUri, AnnouncementEndpoint aEndpoint, DiscoveryEndpoint dEndpoint)
        {
            // actual service, announcing to 4989
            var host = new ServiceHost(typeof(TestService));
            var sdb  = new ServiceDiscoveryBehavior();

            sdb.AnnouncementEndpoints.Add(aEndpoint);
            host.Description.Behaviors.Add(sdb);
            host.AddServiceEndpoint(typeof(ITestService), new BasicHttpBinding(), serviceUri);
            host.Open();
            // It does not start announcement very soon, so wait for a while.
            Thread.Sleep(1000);
            try {
                // actual client, with DiscoveryClientBindingElement
                var be = new DiscoveryClientBindingElement()
                {
                    DiscoveryEndpointProvider = new SimpleDiscoveryEndpointProvider(dEndpoint)
                };
                var clientBinding = new CustomBinding(new BasicHttpBinding());
                clientBinding.Elements.Insert(0, be);
                var cf = new ChannelFactory <ITestService> (clientBinding, DiscoveryClientBindingElement.DiscoveryEndpointAddress);
                var ch = cf.CreateChannel();
                Assert.AreEqual("TEST", ch.Echo("TEST"), "#1");
                cf.Close();
            } finally {
                host.Close();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates the discovery client.
        /// </summary>
        /// <returns>DiscoveryClient.</returns>
        private static DiscoveryClient CreateDiscoveryClient()
        {
            var discoveryEndpoint = new DiscoveryEndpoint(
                BindingFactory.CreateBindingFromKey(BindingFactory.Key.WsHttpBindingNoSecurity),
                new EndpointAddress(new Uri(ConfigurationHelper.CloudProbe)));

            return(new DiscoveryClient(discoveryEndpoint));
        }
Ejemplo n.º 17
0
        public void Custom_path_is_supported(string input, string documentPath)
        {
            var result = DiscoveryEndpoint.ParseUrl(input, documentPath);

            // test parse URL logic
            result.Url.Should().Be("https://server:123/strange-location/openid-configuration");
            result.Authority.Should().Be("https://server:123");
        }
Ejemplo n.º 18
0
        public void Various_urls_should_normalize(string input)
        {
            var result = DiscoveryEndpoint.ParseUrl(input);

            // test parse URL logic
            result.Url.Should().Be("https://server:123/.well-known/openid-configuration");
            result.Authority.Should().Be("https://server:123");
        }
Ejemplo n.º 19
0
		protected internal override ServiceEndpoint CreateServiceEndpoint (ContractDescription contractDescription)
		{
			if (contractDescription == null)
				throw new ArgumentNullException ("contractDescription");
			var ret = new DiscoveryEndpoint (DiscoveryVersion, DiscoveryMode) { MaxResponseDelay = this.MaxResponseDelay };
			if (ret.Contract.ContractType != contractDescription.ContractType)
				throw new ArgumentException ("The argument contractDescription does not represent the expected Discovery contract");
			return ret;
		}
Ejemplo n.º 20
0
        } //Feito

        public override IEnumerable <PlayerPC> GetPlayers()
        {
            List <WCFPlayerPC> pcs = new List <WCFPlayerPC>();

            Uri probeEndpointAddress = new Uri(CompleteServerAddress);

            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.None;
            binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;

            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(binding, new EndpointAddress(probeEndpointAddress));

            DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);

            try
            {
                FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(IPlayer)));

                WCFPlayerPC pc;

                foreach (var endpoint in findResponse.Endpoints)
                {
                    try
                    {
                        NetTcpBinding bindingPC = new NetTcpBinding();
                        binding.Security.Mode = SecurityMode.None;
                        binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;

                        PlayerProxy client = new PlayerProxy(binding, endpoint.Address);

                        client.Open();

                        List <WCFScreenInformation> displays = client.GetDisplayInformation().ToList <WCFScreenInformation>();

                        client.Close();

                        pc = new WCFPlayerPC()
                        {
                            Displays = displays, Endpoint = endpoint.Address
                        };

                        pcs.Add(pc);
                    }
                    catch (EndpointNotFoundException)
                    {
                        continue;
                    }
                }
            }
            catch
            {
                return(null);
            }

            return(pcs.Cast <PlayerPC>());
        } //Feito
Ejemplo n.º 21
0
        public DiscoveryProxyEndpoint(DiscoveryEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            this.endpoint = endpoint;
        }
Ejemplo n.º 22
0
        private void DiscoverEndpoint(DiscoveryEndpoint discoveryEndpoint, DiscoveredEndpointModel model)
        {
            using (var discover = new DiscoveryClient(discoveryEndpoint))
            {
                var criteria = CreateSearchCriteria(model);

                var discovered = discover.Find(criteria);
                if (discovered.Endpoints.Count > 0)
                {
                    var binding          = model.Binding;
                    var endpointMetadata = discovered.Endpoints[0];
                    if (discovered.Endpoints.Count > 1 && model.EndpointPreference != null)
                    {
                        endpointMetadata = model.EndpointPreference(discovered.Endpoints);
                        if (endpointMetadata == null)
                        {
                            throw new EndpointNotFoundException(string.Format(
                                                                    "More than one endpoint was discovered for contract {0}.  " +
                                                                    "However, an endpoint could be selected.  This is most likely " +
                                                                    "a bug with the user-defined endpoint prefeence.",
                                                                    contract.FullName));
                        }
                    }

                    if (binding == null && model.DeriveBinding == false)
                    {
                        binding = GetBindingFromMetadata(endpointMetadata);
                    }

                    var address = endpointMetadata.Address;
                    if (model.Identity != null)
                    {
                        address = new EndpointAddress(address.Uri, model.Identity, address.Headers);
                    }

                    binding = GetEffectiveBinding(binding, address.Uri);
                    var innerCreator = GetChannel(contract, binding, address);
                    channelCreator = () =>
                    {
                        var channel = (IChannel)innerCreator();
                        if (channel is IContextChannel)
                        {
                            var metadata = new DiscoveredEndpointMetadata(endpointMetadata);
                            ((IContextChannel)channel).Extensions.Add(metadata);
                        }
                        return(channel);
                    };
                }
                else
                {
                    throw new EndpointNotFoundException(string.Format(
                                                            "Unable to discover the endpoint for contract {0}.  " +
                                                            "Either no service exists or it does not support discovery.",
                                                            contract.FullName));
                }
            }
        }
Ejemplo n.º 23
0
        protected internal override void InitializeFrom(ServiceEndpoint endpoint)
        {
            base.InitializeFrom(endpoint);

            DiscoveryEndpoint source = (DiscoveryEndpoint)endpoint;

            this.MaxResponseDelay = source.MaxResponseDelay;
            this.DiscoveryVersion = source.DiscoveryVersion;
            this.DiscoveryMode    = source.DiscoveryMode;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Needs to be called before using any other method or all will return null
        /// </summary>
        /// <exception cref="ArgumentNullException"></exception>
        /// <param name="probeEndpoint"></param>
        /// <param name="svcFactory"></param>
        public static void Init(DiscoveryEndpoint probeEndpoint, ChannelFactory <ICombateSvcChannel> svcFactory)
        {
            Manager = new GameManager();

            ProbeClient = new DiscoveryClient(probeEndpoint);

            ProbeClientReseter = new Timer(ReloadProbeClient, probeEndpoint, 900000, 900000); // 15min.

            SvcFactory = svcFactory;
        }
Ejemplo n.º 25
0
        public ResolveAsyncResult(ResolveCriteria resolveCriteria, DiscoveryEndpoint forwardingDiscoveryEndpoint, AsyncCallback callback, object state)
            : base(callback, state)
        {
            this.resolveCriteria = resolveCriteria;

            this.discoveryClient = new DiscoveryClient(forwardingDiscoveryEndpoint);
            this.discoveryClient.ResolveCompleted += new EventHandler <ResolveCompletedEventArgs>(ResolveCompleted);

            // Forwards the Resolve request message
            this.discoveryClient.ResolveAsync(resolveCriteria);
        }
Ejemplo n.º 26
0
    static void RunCodeUnderDiscoveryHost(Uri serviceUri, Uri dHostUri, Uri aHostUri, Action <Uri, AnnouncementEndpoint, DiscoveryEndpoint> action)
    {
        var abinding  = new CustomBinding(new HttpTransportBindingElement());
        var aAddress  = new EndpointAddress(aHostUri);
        var aEndpoint = new AnnouncementEndpoint(abinding, aAddress);
        var dbinding  = new CustomBinding(new HttpTransportBindingElement());
        var dAddress  = new EndpointAddress(dHostUri);
        var dEndpoint = new DiscoveryEndpoint(dbinding, dAddress);

        action(serviceUri, aEndpoint, dEndpoint);
    }
Ejemplo n.º 27
0
    static void RunCodeUnderDiscoveryHost(Uri serviceUri, Uri aHostUri)
    {
        // announcement service
        var abinding  = new CustomBinding(new HttpTransportBindingElement());
        var aAddress  = new EndpointAddress(aHostUri);
        var aEndpoint = new AnnouncementEndpoint(abinding, aAddress);

        // discovery service
        var dBinding  = new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement());
        var dEndpoint = new DiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc, dBinding, new EndpointAddress("net.tcp://" + hostname + ":9090/"));

        // Without this, .NET rejects the host as if it had no service.
        dEndpoint.IsSystemEndpoint = false;
        var ib = new InspectionBehavior();

        ib.ReplySending += delegate(ref Message msg, object o) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
        };
        ib.RequestReceived += delegate(ref Message msg, IClientChannel channel, InstanceContext instanceContext) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
            return(null);
        };
        ib.ReplyReceived += delegate(ref Message msg, object o) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
        };
        ib.RequestSending += delegate(ref Message msg, IClientChannel channel) {
            var mb = msg.CreateBufferedCopy(0x10000);
            msg = mb.CreateMessage();
            Console.Error.WriteLine(mb.CreateMessage());
            return(null);
        };

        dEndpoint.Behaviors.Add(ib);
        aEndpoint.Behaviors.Add(ib);

        // it internally hosts an AnnouncementService
        using (var inst = new AnnouncementBoundDiscoveryService(aEndpoint)) {
            var host = new ServiceHost(inst);
            host.AddServiceEndpoint(dEndpoint);
            host.Description.Behaviors.Find <ServiceDebugBehavior> ()
            .IncludeExceptionDetailInFaults = true;
            host.Open();
            Console.WriteLine("Type [CR] to quit...");
            Console.ReadLine();
            host.Close();
        }
    }
        /// <summary>
        /// Initializes the listener from a binding element.
        /// </summary>
        internal UaTcpChannelListener(UaTcpTransportBindingElement bindingElement, BindingContext context)
            :
            base(context.Binding)
        {
            // assign a unique guid to the listener.
            m_listenerId = Guid.NewGuid().ToString();

            SetUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);

            m_descriptions  = bindingElement.Descriptions;
            m_configuration = bindingElement.Configuration;

            m_quotas = new TcpChannelQuotas();

            m_quotas.MaxBufferSize         = m_configuration.MaxBufferSize;
            m_quotas.MaxMessageSize        = m_configuration.MaxMessageSize;
            m_quotas.ChannelLifetime       = m_configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_configuration.SecurityTokenLifetime;
            m_quotas.MessageContext        = bindingElement.MessageContext;

            foreach (object parameter in context.BindingParameters)
            {
                ServiceCredentials credentials = parameter as ServiceCredentials;

                if (credentials != null)
                {
                    // TBD - paste the cert with the private key with the additional chain.
                    m_serverCertificate           = CertificateFactory.Create(credentials.ServiceCertificate.Certificate, credentials.ServiceCertificate.Certificate);
                    m_quotas.CertificateValidator = credentials.ClientCertificate.Authentication.CustomCertificateValidator;
                }
            }

            m_bufferManager = new BufferManager("Server", (int)bindingElement.MaxBufferPoolSize, m_quotas.MaxBufferSize);

            m_channels     = new Dictionary <uint, TcpServerChannel>();
            m_channelQueue = new Queue <UaTcpReplyChannel>();
            m_acceptQueue  = new Queue <TcpAsyncOperation <IReplySessionChannel> >();

            // link the channel directly to the server.
            // this is a hack designed to work around a bug in the WCF framework that results in lost requests during stress testing.
            if (bindingElement.ServiceHost != null)
            {
                if (bindingElement.ServiceHost.Server is DiscoveryServerBase)
                {
                    m_callback = new DiscoveryEndpoint(bindingElement.ServiceHost);
                }
                else
                {
                    m_callback = new SessionEndpoint(bindingElement.ServiceHost);
                }
            }
        }
        public DiscoveryInnerClientAdhocCD1(DiscoveryEndpoint discoveryEndpoint, IDiscoveryInnerClientResponse responseReceiver)
        {
            Fx.Assert(discoveryEndpoint != null, "The discoveryEndpoint parameter cannot be null");
            Fx.Assert(responseReceiver != null, "The responseReceiver parameter cannot be null");

            this.responseReceiver = responseReceiver;
            if (discoveryEndpoint.Behaviors.Find <DiscoveryCallbackBehavior>() == null)
            {
                discoveryEndpoint.Behaviors.Insert(0, new DiscoveryCallbackBehavior());
            }

            this.duplexInnerClient = new DuplexClientCD1(this, discoveryEndpoint);
        }
Ejemplo n.º 30
0
    static void UseCase1Core(Uri serviceUri, AnnouncementEndpoint aEndpoint, DiscoveryEndpoint dEndpoint)
    {
        var host = new ServiceHost(typeof(TestService));
        var sdb  = new ServiceDiscoveryBehavior();

        sdb.AnnouncementEndpoints.Add(aEndpoint);
        host.Description.Behaviors.Add(sdb);
        host.AddServiceEndpoint(typeof(ITestService), new BasicHttpBinding(), serviceUri);
        host.Open();
        Console.WriteLine("Type [CR] to quit ...");
        Console.ReadLine();
        host.Close();
    }
Ejemplo n.º 31
0
        private void DiscoveryEndpointFaulted(object sender, DiscoveryEndpointFaultEventArgs args)
        {
            using (var locker = @lock.ForReadingUpgradeable())
            {
                if (args.Culprit != endpoint)
                {
                    return;
                }

                locker.Upgrade();

                endpoint = null;
            }
        }
 public IDiscoveryInnerClient CreateDiscoveryInnerClient(DiscoveryEndpoint discoveryEndpoint, IDiscoveryInnerClientResponse responseReceiver)
 {
     if (discoveryEndpoint.DiscoveryMode == ServiceDiscoveryMode.Adhoc)
     {
         return new DiscoveryInnerClientAdhoc11(discoveryEndpoint, responseReceiver);
     }
     else if (discoveryEndpoint.DiscoveryMode == ServiceDiscoveryMode.Managed)
     {
         return new DiscoveryInnerClientManaged11(discoveryEndpoint, responseReceiver);
     }
     else
     {
         throw FxTrace.Exception.AsError(new ArgumentException(SR.DiscoveryIncorrectMode(discoveryEndpoint.DiscoveryMode)));
     }
 }