Beispiel #1
0
        void StartService()
        {
            applicationService = new ApplicationInterfaceService();

            Uri baseAddress = new Uri("net.pipe://localhost/Multitouch.Service/ApplicationInterface");

            serviceHost = new ServiceHost(applicationService, baseAddress);
            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            binding.ReceiveTimeout         = TimeSpan.MaxValue;
            binding.MaxBufferSize          = int.MaxValue;
            binding.MaxReceivedMessageSize = int.MaxValue;
            serviceHost.AddServiceEndpoint(typeof(IApplicationInterface), binding, string.Empty);

            ServiceMetadataBehavior serviceMetadataBehavior = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (serviceMetadataBehavior == null)
            {
                serviceMetadataBehavior = new ServiceMetadataBehavior();
            }
            serviceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            serviceHost.Description.Behaviors.Add(serviceMetadataBehavior);

            serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
            serviceHost.Open();
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            Uri address = new Uri("net.pipe://localhost/NativeCodeService");
            NetNamedPipeBinding binding = new NetNamedPipeBinding();

            binding.ReceiveTimeout = TimeSpan.MaxValue;
            binding.SendTimeout    = TimeSpan.MaxValue;
            ////binding.MaxReceivedMessageSize = 40000000;
            ////binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            ////binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;

            using (ServiceHost host = new ServiceHost(typeof(NativeMethods)))
            {
                var ff = host.AddServiceEndpoint(typeof(INativeMethodService), binding, address);
                ServiceMetadataBehavior metadata = new ServiceMetadataBehavior();

                host.Description.Behaviors.Add(metadata);
                host.Description.Behaviors.OfType <ServiceDebugBehavior>().First().IncludeExceptionDetailInFaults = true;

                Binding mexBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                Uri     mexAddress = new Uri("net.pipe://localhost/NativeCodeService/Mex");
                host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexAddress);

                host.Open();

                Console.WriteLine("The Native Code Host Service is ready");
                Console.ReadLine();
            }
        }
        public static void AddDefaultMEXEndPoint(this ServiceHost host)
        {
            const string MexExtension = "Mex";

            ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();

            host.Description.Behaviors.Add(mexBehavior);

            foreach (Uri baseAddress in host.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(), MexExtension);
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(), MexExtension);
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(), MexExtension);
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(), MexExtension);
                }
            }
        }
Beispiel #4
0
        private void SetMexBinding(Binding binding)
        {
            var smb = new ServiceMetadataBehavior();

            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;

            Binding mexBinding = null;

            if (binding.GetType() == typeof(NetNamedPipeBinding))
            {
                mexBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
            }
            else if (binding.GetType() == typeof(NetTcpBinding))
            {
                mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
            }
            else if (binding.GetType() == typeof(BasicHttpBinding))
            {
                mexBinding         = MetadataExchangeBindings.CreateMexHttpBinding();
                smb.HttpGetEnabled = true;
            }

            if (mexBinding != null)
            {
                Host.Description.Behaviors.Add(smb);
                Host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, mexBinding, "mex");
            }
        }
Beispiel #5
0
        public void StartPipeNodeService()
        {
            throw new NotImplementedException();
            var serviceAddress = "net.pipe://localhost/NodeService/" + _pipeName;
            var serviceUri     = new Uri(serviceAddress);

            _pipeHost = new ServiceHost(NodeService, serviceUri);

            _pipeHost.AddServiceEndpoint(typeof(INodeService), new NetNamedPipeBinding(), "");

            var smb = new ServiceMetadataBehavior();

            _pipeHost.Description.Behaviors.Add(smb);
            var mexBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();

            _pipeHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex");

            try
            {
                _pipeHost.Open();
            }
            catch (CommunicationException ce)
            {
                _pipeHost.Abort();
            }
        }
Beispiel #6
0
        private void addmexbehavior()
        {
            ServiceMetadataBehavior serviceMetadataBehavior = base.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (serviceMetadataBehavior == null)
            {
                serviceMetadataBehavior = new ServiceMetadataBehavior();
                base.Description.Behaviors.Add(serviceMetadataBehavior);
            }
            foreach (Uri current in base.BaseAddresses)
            {
                if (current.Scheme == Uri.UriSchemeHttp)
                {
                    serviceMetadataBehavior.HttpGetEnabled = true;
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
                }
                else if (current.Scheme == Uri.UriSchemeHttps)
                {
                    serviceMetadataBehavior.HttpsGetEnabled = true;
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
                }
                else if (current.Scheme == Uri.UriSchemeNetPipe)
                {
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
                }
                else if (current.Scheme == Uri.UriSchemeNetTcp)
                {
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
                }
            }
        }
        private static MetadataExchangeClient CreateMetadataExchangeClient(EndpointAddress endpointReference)
        {
            string scheme = endpointReference.Uri.Scheme;

            if (string.Compare(scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding mexHttpBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpBinding();
                mexHttpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                return(new MetadataExchangeClient(mexHttpBinding));
            }
            if (string.Compare(scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding mexHttpsBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpsBinding();
                mexHttpsBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                return(new MetadataExchangeClient(mexHttpsBinding));
            }
            if (string.Compare(scheme, Uri.UriSchemeNetTcp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CustomBinding mexTcpBinding = (CustomBinding)MetadataExchangeBindings.CreateMexTcpBinding();
                mexTcpBinding.Elements.Find <TcpTransportBindingElement>().MaxReceivedMessageSize = maxReceivedMessageSize;
                return(new MetadataExchangeClient(mexTcpBinding));
            }
            if (string.Compare(scheme, Uri.UriSchemeNetPipe, StringComparison.OrdinalIgnoreCase) != 0)
            {
                string message = string.Format("Cannot obtain Metadata from {0}. The URI scheme is not supported by default. Add a client endpoint in config with name=\"\" and contract=\"IMetadataExchange\" and an appropriate binding to obtain Metadata from this URI.", endpointReference.Uri.OriginalString);
                throw new ArgumentException(message);
            }
            CustomBinding mexNamedPipeBinding = (CustomBinding)MetadataExchangeBindings.CreateMexNamedPipeBinding();

            mexNamedPipeBinding.Elements.Find <NamedPipeTransportBindingElement>().MaxReceivedMessageSize = maxReceivedMessageSize;
            return(new MetadataExchangeClient(mexNamedPipeBinding));
        }
        public void Start()
        {
            if (this.svcExternalControlInstance == null)
            {
                this.svcExternalControlInstance = new ExternalControlServer(this.playbackService, this.cacheService);
            }
            this.svcExternalControlInstance.Open();

            svcHost = new ServiceHost(svcExternalControlInstance, new Uri($"net.pipe://localhost/{ProductInformation.ApplicationName}"));
            svcHost.AddServiceEndpoint(typeof(IExternalControlServer), new NetNamedPipeBinding()
            {
#if DEBUG
                SendTimeout = new TimeSpan(0, 0, 8),
#else
                SendTimeout = new TimeSpan(0, 0, 1),
#endif
            }, "/ExternalControlService");

//            svcHost.AddServiceEndpoint(typeof(IFftDataServer), new NetNamedPipeBinding()
//            {
//#if DEBUG
//                SendTimeout = new TimeSpan(0, 0, 8),
//#else
//                SendTimeout = new TimeSpan(0, 0, 1),
//#endif
//            }, "/ExternalControlService/FftDataServer");

            var smb = svcHost.Description.Behaviors.Find <ServiceMetadataBehavior>() ?? new ServiceMetadataBehavior();
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            svcHost.Description.Behaviors.Add(smb);
            svcHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                       MetadataExchangeBindings.CreateMexNamedPipeBinding(), "/ExternalControlService/mex");

            svcHost.Open();
        }
        public void Start()
        {
            InputProviderLogic providerLogic = GetLogic <InputProviderLogic>();

            if (!providerLogic.IsRunning)
            {
                throw new MultitouchException("No provider is currently running");
            }

            service = new MultitouchService(providerLogic.CurrentProvider, GetLogic <LegacySupportLogic>());

            Uri baseAddress = new Uri("net.pipe://localhost/Danilins.Multitouch.Logic.Service/MultitouchService");

            host = new ServiceHost(service, baseAddress);

            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            host.AddServiceEndpoint(typeof(IMultitouchService), binding, string.Empty);

            ServiceMetadataBehavior serviceMetadataBehavior = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (serviceMetadataBehavior == null)
            {
                serviceMetadataBehavior = new ServiceMetadataBehavior();
            }
            serviceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(serviceMetadataBehavior);

            host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");

            host.Open();
        }
Beispiel #10
0
        // Конструктор по умолчанию определяется как private
        private WcfCheckersService()
        {
            // Регистрация сервиса и его метаданных
            _svcHost = new ServiceHost(typeof(CheckersService),
                                       new[]
            {
                new Uri("net.pipe://localhost/CheckersAppServer"),
                new Uri("net.tcp://localhost:5528/CheckersAppServer")
            });
            _svcHost.AddServiceEndpoint(typeof(ICheckersService),
                                        new NetNamedPipeBinding(), "");
            _svcHost.AddServiceEndpoint(typeof(ICheckersService),
                                        new NetTcpBinding
            {
                OpenTimeout    = _timeout,
                SendTimeout    = _timeout,
                ReceiveTimeout = _timeout,
                CloseTimeout   = _timeout
            }, "");
            var behavior = new ServiceMetadataBehavior();

            _svcHost.Description.Behaviors.Add(behavior);
            _svcHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                        MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
            _svcHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                        MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
        }
Beispiel #11
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Uri         tcpAddressUri  = new Uri("net.tcp://localhost:8080/TcpBinding");
            Uri         pipeAddressUri = new Uri("net.pipe://localhost/NetNamedPipeBinding");
            Uri         httpAddressUri = new Uri("http://localhost:8090/HttpBinding");
            ServiceHost host           = new ServiceHost(typeof(WcfClassLibrary.DumWcfService), tcpAddressUri, pipeAddressUri, httpAddressUri);

            NetNamedPipeBinding pipeBinding      = new NetNamedPipeBinding();
            NetTcpBinding       tcpBinding       = new NetTcpBinding();
            BasicHttpBinding    basicHttpBinding = new BasicHttpBinding();

            ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();

            host.Description.Behaviors.Add(mexBehavior);

            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
            host.AddServiceEndpoint(typeof(IMetadataExchange),
                                    MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
            host.AddServiceEndpoint(typeof(WcfClassLibrary.IDumWcfService), tcpBinding, tcpAddressUri);
            host.AddServiceEndpoint(typeof(WcfClassLibrary.IDumWcfService), pipeBinding, pipeAddressUri);
            host.AddServiceEndpoint(typeof(WcfClassLibrary.IDumWcfService), basicHttpBinding, httpAddressUri);

            host.Open();
            lblHostMessage.Text = "Service Has Started....";
        }
Beispiel #12
0
        // Конструктор по умолчанию определяется как private
        private WcfEventService()
        {
            // Регистрация сервиса и его метаданных
            _svcHost = new ServiceHost(typeof(AShEventService),
                                       new[]
            {
                new Uri("net.pipe://localhost/FillingEventServer"),
                new Uri("net.tcp://localhost:9901/FillingEventServer")
            });
            _svcHost.AddServiceEndpoint(typeof(IAShEventService),
                                        new NetNamedPipeBinding(), "");
            _svcHost.AddServiceEndpoint(typeof(IAShEventService),
                                        new NetTcpBinding
            {
                OpenTimeout    = _timeout,
                SendTimeout    = _timeout,
                ReceiveTimeout = _timeout,
                CloseTimeout   = _timeout,
                Security       = new NetTcpSecurity {
                    Mode = SecurityMode.None
                }
            }, "");
            var behavior = new ServiceMetadataBehavior();

            _svcHost.Description.Behaviors.Add(behavior);
            _svcHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                        MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
            _svcHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                        MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
        }
Beispiel #13
0
        public void AddAllMexEndpoint()
        {
            Debug.Assert(HasMexEndPoint == false);
            foreach (Uri baseAddress in BaseAddresses)
            {
                System.ServiceModel.Channels.Binding binding = null;
                switch (baseAddress.Scheme)
                {
                case "net.tcp":
                    binding = MetadataExchangeBindings.CreateMexTcpBinding();
                    break;

                case "net.pipe":
                    binding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                    break;

                case "http":
                    binding = MetadataExchangeBindings.CreateMexHttpBinding();
                    break;

                case "https":
                    binding = MetadataExchangeBindings.CreateMexHttpsBinding();
                    break;
                }
                if (binding != null)
                {
                    AddServiceEndpoint(typeof(IMetadataExchange), binding, "Mex");
                }
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(RemoteObject));

            {
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                host.Description.Behaviors.Add(smb);

                //provide metadata
                Binding mex = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                host.AddServiceEndpoint(typeof(IMetadataExchange), mex, "net.pipe://localhost/Demo/Meta");

                NetNamedPipeBinding pipe = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
                {
                    MaxReceivedMessageSize = int.MaxValue,
                    MaxBufferSize          = int.MaxValue,
                    MaxBufferPoolSize      = int.MaxValue,
                    TransferMode           = TransferMode.Streamed
                };
                pipe.ReaderQuotas.MaxArrayLength         = int.MaxValue;
                pipe.ReaderQuotas.MaxBytesPerRead        = int.MaxValue;
                pipe.ReaderQuotas.MaxStringContentLength = int.MaxValue;

                host.AddServiceEndpoint(typeof(IRemoteObject), pipe, "net.pipe://localhost/Demo/DoStuff");
            }
            host.Open();
            Console.WriteLine("Server Started");
            Console.ReadLine();
            host.Close();
        }
Beispiel #15
0
        }         // OnOpening

        private void Expose()
        {
            Description.Behaviors.Add(new ServiceDiscoveryBehavior());

            Description.Behaviors.Add(new ServiceMetadataBehavior());

            foreach (Uri baseAddress in BaseAddresses)
            {
                Binding binding = null;

                if (baseAddress.Scheme == "net.tcp")
                {
                    binding = MetadataExchangeBindings.CreateMexTcpBinding();
                }
                else if (baseAddress.Scheme == "net.pipe")
                {
                    binding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                }
                else if (baseAddress.Scheme == "http")
                {
                    binding = MetadataExchangeBindings.CreateMexHttpBinding();
                }

                if (binding != null)
                {
                    AddServiceEndpoint(typeof(IMetadataExchange), binding, "MEX");
                }
            }             // for each base address

            AddServiceEndpoint(new UdpDiscoveryEndpoint());
        }         // Expose
Beispiel #16
0
        protected override void OnStart(string[] args)
        {
#if !DEBUG
            eventLog.WriteEntry(Properties.Resources.LogMsgServiceStarted);
#endif
            if (_serviceHost != null)
            {
                _serviceHost.Close();
            }
            // Create a URI to serve as the base address
            Uri baseAddr = new Uri(Properties.Settings.Default.ServiceHostURI);

            // Create ServiceHost
            _serviceHost = new ServiceHost(
                typeof(AttiLA.LocalizationService.LocalizationService),
                baseAddr);

            try
            {
                // Add net named pipe service endpoint

                //var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                var binding = new NetNamedPipeBinding();
#if DEBUG
                binding.CloseTimeout   = TimeSpan.FromMinutes(1.0);
                binding.OpenTimeout    = TimeSpan.FromMinutes(1.0);
                binding.ReceiveTimeout = TimeSpan.FromMinutes(30.0);
                binding.SendTimeout    = TimeSpan.FromMinutes(30.0);
#endif

                binding.Name = Properties.Settings.Default.BindingPipeName;
                _serviceHost.AddServiceEndpoint(
                    typeof(AttiLA.LocalizationService.ILocalizationService),
                    binding,
                    Properties.Settings.Default.LocalizationServicePipe);

                // Enable metadata exchange
                ServiceMetadataBehavior smb = _serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (smb == null)
                {
                    smb = new ServiceMetadataBehavior();
                    _serviceHost.Description.Behaviors.Add(smb);
                }

                // Add MEX endpoint
                _serviceHost.AddServiceEndpoint(
                    ServiceMetadataBehavior.MexContractName,
                    MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                    Properties.Settings.Default.MessageServicePipe);

                // Start the Service
                _serviceHost.Open();
            }
            catch (CommunicationException)
            {
                _serviceHost.Abort();
                Thread.CurrentThread.Abort();
            }
        }
Beispiel #17
0
        public PresageWCFHostForm()
        {
            InitializeComponent();

            Uri baseAddress = new Uri(Constants.ServiceBaseAddress);

            // Create the ServiceHost.
            host = new ServiceHost(typeof(PresageService), baseAddress);

            NetNamedPipeBinding binding = new NetNamedPipeBinding();

            binding.Namespace = presage_wcf_service.Constants.ServiceNamespace;

            // Add presage endpoint.
            host.AddServiceEndpoint(
                typeof(IPresageService),
                binding,
                Constants.ServicePresageEndpointRelativeAddress);

            // Enable metadata publishing.
            // Check to see if the service host already has a ServiceMetadataBehavior
            ServiceMetadataBehavior smb = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            // If not, add one
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior();
            }
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);

            // Add metadata endpoint.
            host.AddServiceEndpoint(
                typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                Constants.ServiceMexEndpointRelativeAddress);

            // Open the ServiceHost to start listening for messages. Since
            // no endpoints are explicitly configured, the runtime will create
            // one endpoint per base address for each service contract implemented
            // by the service.
            try
            {
                host.Open();
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    "Error occurred while attempting to start Presage WCF Service:\n\n" + e.Message,
                    "Presage WCF Service",
                    MessageBoxButtons.OK);
                // Exit with
                // ERROR_PIPE_BUSY
                // 231 (0xE7)
                // All pipe instances are busy.
                //
                System.Environment.Exit(231);
            }
        }
        //Overriding ApplyConfiguration() allows us to
        //alter the ServiceDescription prior to opening
        //the service host.
        protected override void ApplyConfiguration()
        {
            //First, we call base.ApplyConfiguration()
            //to read any configuration that was provided for
            //the service we're hosting. After this call,
            //this.ServiceDescription describes the service
            //as it was configured.
            base.ApplyConfiguration();

            //Now that we've populated the ServiceDescription, we can reach into it
            //and do interesting things (in this case, we'll add an instance of
            //ServiceMetadataBehavior if it's not already there.
            ServiceMetadataBehavior mexBehavior = this.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior == null)
            {
                mexBehavior = new ServiceMetadataBehavior();
                this.Description.Behaviors.Add(mexBehavior);
            }
            else
            {
                //Metadata behavior has already been configured,
                //so we don't have any work to do.
                return;
            }

            //Add a metadata endpoint at each base address
            //using the "/mex" addressing convention
            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }
Beispiel #19
0
        private void CreateMetadataBehavior(SpringServiceHost ssh, ServiceMetadataBehavior smb, ServiceEndpointElement metadataEle)
        {
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior();
                if (ssh.BaseAddresses.Any(o => o.Scheme.ToLower() == Uri.UriSchemeHttp))
                {
                    smb.HttpGetEnabled = true;
                }
                ssh.Description.Behaviors.Add(smb);
            }

            foreach (var baseAddress in ssh.BaseAddresses)
            {
                //BindingElement bindingElement = null;
                Binding bindingElement = null;
                switch (baseAddress.Scheme)
                {
                case  "net.tcp":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexTcpBinding();
                    //bindingElement = new TcpTransportBindingElement();
                    break;
                }

                case "net.pipe":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                    //bindingElement = new NamedPipeTransportBindingElement();
                    break;
                }

                case "http":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexHttpBinding();
                    //bindingElement = new HttpTransportBindingElement();
                    break;
                }

                case "https":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexHttpsBinding();
                    //bindingElement = new HttpsTransportBindingElement();
                    break;
                }

                default:
                    throw new ProtocolException("The base address {0} Unable to identify".FormatString(baseAddress.ToString()));
                }
                if (bindingElement != null)
                {
                    //Binding binding = new CustomBinding(bindingElement);
                    ssh.AddServiceEndpoint(typeof(IMetadataExchange), bindingElement, "MEX");
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// Hostボタンクリック
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //指定されなきゃ何もしない
            if (textBox1.Text == "")
            {
                return;
            }

            var baseAddress     = textBox1.Text;
            var endPointAddress = "IPC";

            try
            {
                //サービスホストを作成
                ServiceHost serviceHost = new ServiceHost(
                    typeof(InterfaceDefine.InterfaceDefine),
                    new Uri(baseAddress)
                    );

                var smb = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>();

                if (smb == null)
                {
                    smb = new ServiceMetadataBehavior();
                }

                //smb.HttpGetEnabled = true;

                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;

                serviceHost.Description.Behaviors.Add(smb);

                serviceHost.AddServiceEndpoint(
                    ServiceMetadataBehavior.MexContractName,
                    MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                    "Mex"
                    );

                ///*
                //エンドポイントを追加
                serviceHost.AddServiceEndpoint(
                    typeof(IWcfInterface),
                    new NetNamedPipeBinding(NetNamedPipeSecurityMode.None),
                    endPointAddress
                    );
                //*/

                serviceHost.Open();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }
        }
Beispiel #21
0
        private void AddWellKnownMexEndpoints(ServiceHost serviceHost)
        {
            bool relativeAddress;

            foreach (var baseAddress in GetBaseAddresses(serviceHost, out relativeAddress))
            {
                Binding binding    = null;
                var     mexAddress = address;
                var     scheme     = baseAddress.Scheme;

                if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeHttp))
                {
                    binding = newBinding ? null : FindCompatibleBinding(serviceHost, scheme);
                    if (binding == null)
                    {
                        binding    = MetadataExchangeBindings.CreateMexHttpBinding();
                        mexAddress = relativeAddress ? string.Empty : baseAddress.AbsoluteUri;
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeHttps))
                {
                    binding = newBinding ? null : FindCompatibleBinding(serviceHost, scheme);
                    if (binding == null)
                    {
                        binding    = MetadataExchangeBindings.CreateMexHttpsBinding();
                        mexAddress = relativeAddress ? string.Empty : baseAddress.AbsoluteUri;
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeNetTcp))
                {
                    binding = MetadataExchangeBindings.CreateMexTcpBinding();
                    var tcpBinding = new CustomBinding(binding);
                    var transport  = tcpBinding.Elements.OfType <TcpTransportBindingElement>().Single();
                    transport.PortSharingEnabled = true;
                    binding = tcpBinding;
                    if (relativeAddress == false)
                    {
                        mexAddress = string.Format("{0}/{1}", baseAddress.AbsoluteUri, address);
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeNetPipe))
                {
                    binding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                    if (relativeAddress == false)
                    {
                        mexAddress = string.Format("{0}/{1}", baseAddress.AbsoluteUri, address);
                    }
                }

                if (binding != null)
                {
                    serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), binding, mexAddress);
                }
            }
        }
Beispiel #22
0
        /// <summary>
        /// Configures metadata (WSDL) for the service host. The method loops through the
        /// base addresses, and adds mex endpoints for http, https, net.tcp and net.pipe
        /// addresses, only when no mex endpoints have been previously added by the user.
        /// For http and htps addresses, HTTP and HTTPS "Get" mechanism for WSDL retrieval
        /// is enabled.
        /// </summary>
        protected virtual void ConfigureMetadata()
        {
            if (this.BaseAddresses == null || this.BaseAddresses.Count == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3140));
            }

            // Check if a ServiceMetadataBehavior is added.
            ServiceMetadataBehavior metadataBehavior = Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (metadataBehavior == null)
            {
                metadataBehavior = new ServiceMetadataBehavior();
                Description.Behaviors.Add(metadataBehavior);
            }

            // Check if an Mex endpoint has alread been added by user. This can be enabled through
            // configuration.
            bool isMexEndpointAlreadyAdded = (Description.Endpoints.Find(typeof(IMetadataExchange)) != null);

            Binding mexBinding = null;

            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeHttp))
                {
                    metadataBehavior.HttpGetEnabled = true;
                    mexBinding = MetadataExchangeBindings.CreateMexHttpBinding();
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeHttps))
                {
                    metadataBehavior.HttpsGetEnabled = true;
                    mexBinding = MetadataExchangeBindings.CreateMexHttpsBinding();
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeNetTcp))
                {
                    mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeNetPipe))
                {
                    mexBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                }

                if (!isMexEndpointAlreadyAdded && (mexBinding != null))
                {
                    AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, mexBinding, "mex");
                }

                mexBinding = null;
            }
        }
Beispiel #23
0
        /// <summary>
        /// Adds the mex endpoints.
        /// </summary>
        /// <param name="host">The service host.</param>
        public static void AddMexEndpoints(this ServiceHostBase host)
        {
            Type T           = host.GetType();
            var  logger      = LogManager.GetLogger(T.Name);
            var  mexBehavior = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior == null)
            {
                mexBehavior = new ServiceMetadataBehavior();
                host.Description.Behaviors.Add(mexBehavior);
            }
            logger.Debug("Checking possible MEX endpoints...");
            foreach (Uri baseAddress in host.BaseAddresses)
            {
                logger.Debug("\tAdding endpoint {0}", baseAddress.AbsoluteUri);
                if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    if (ConfigurationHelper.SecureMex)
                    {
                        mexBehavior.HttpsGetEnabled = true;
                        mexBehavior.HttpsGetUrl     = baseAddress;
                        host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                                MetadataExchangeBindings.CreateMexHttpsBinding(),
                                                "mex");
                    }
                }
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    if (!ConfigurationHelper.SecureMex)
                    {
                        mexBehavior.HttpGetEnabled = true;
                        mexBehavior.HttpGetUrl     = baseAddress;
                        host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                                MetadataExchangeBindings.CreateMexHttpBinding(),
                                                "mex");
                    }
                }
                if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// Apply configuration
        /// </summary>
        protected override void ApplyConfiguration()
        {
            this.Description.ConfigurationName = this.ServiceName;
            base.ApplyConfiguration();

            ServiceMetadataBehavior mexBehavior = this.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior == null)
            {
                mexBehavior = new ServiceMetadataBehavior();
                this.Description.Behaviors.Add(mexBehavior);
            }
            else
            {
                //Metadata behavior has already been configured,
                //so we don't have any work to do.
                return;
            }

            //Add a metadata endpoint at each base address
            //using the "/mex" addressing convention
            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }
Beispiel #25
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public NamedPipeChatServiceMode()
        {
            var binding = new NetNamedPipeBinding();

            binding.Security.Mode  = NetNamedPipeSecurityMode.None;
            ServiceEndpointBinding = binding;
            ServiceMetadataBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
            ServiceBehavior        = new ServiceMetadataBehavior {
                MetadataExporter =
                {
                    PolicyVersion = PolicyVersion.Policy15
                }
            };
        }
Beispiel #26
0
        internal void Start()
        {
            string serviceAddress = Config.MakeServiceAddress(typeof(T), Process.GetCurrentProcess().Id);

            Trace.TraceInformation($"Starting WCF service {serviceAddress}");

            try
            {
                // create the service
                _service = new ServiceHost(GetType());

                // create pipe binding
                NetNamedPipeBinding pipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
                {
                    ReceiveTimeout         = ReceiveTimeout,
                    SendTimeout            = SendTimeout,
                    MaxBufferSize          = int.MaxValue,
                    MaxReceivedMessageSize = int.MaxValue
                };
                _service.AddServiceEndpoint(typeof(T), pipeBinding, serviceAddress);

                // Metadata
                ServiceMetadataBehavior smb = _service.Description.Behaviors.Find <ServiceMetadataBehavior>() ?? new ServiceMetadataBehavior();
                _service.Description.Behaviors.Add(smb);
                if (IncludeExceptionsInFaults)
                {
                    _service.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
                    _service.Description.Behaviors.Add(new ServiceDebugBehavior {
                        IncludeExceptionDetailInFaults = true
                    });
                }

                // Add MEX endpoint
                _service.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            serviceAddress + "/mex");

                // Open
                _service.Open();

                // signal the service is ready
                _sync = new Mutex(false, serviceAddress);

                Trace.TraceInformation($"WCF service {serviceAddress} started successfully");
            }
            catch (Exception e)
            {
                Trace.TraceError($"Error starting WCF service: {e.ToString()}");
                throw;
            }
        }
        public static void AddMetaDataExchange(this ServiceHost host)
        {
            var serviceMetadataBehavior = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (null == serviceMetadataBehavior)
            {
                serviceMetadataBehavior = new ServiceMetadataBehavior();
                host.Description.Behaviors.Add(serviceMetadataBehavior);
            }
            host.AddServiceEndpoint(
                typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                "mex");
        }
Beispiel #28
0
        public static MetadataSet GetMetadataSet(string url)
        {
            MetadataExchangeClientMode mode = MetadataExchangeClientMode.MetadataExchange;
            int maxReceivedMessageSize      = 3000000;
            Uri address = new Uri(url);

            System.ServiceModel.Channels.Binding mexBinding = null;
            if (string.Compare(address.Scheme, "http", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexHttpBinding();
            }
            else if (string.Compare(address.Scheme, "https", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexHttpsBinding();
            }
            else if (string.Compare(address.Scheme, "net.tcp", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
            }
            else if (string.Compare(address.Scheme, "net.pipe", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
            }
            else
            {
                throw new Exception(string.Format("Not supported schema '{0}' for metadata exchange"));
            }

            if (mexBinding is WSHttpBinding)
            {
                (mexBinding as WSHttpBinding).MaxReceivedMessageSize = maxReceivedMessageSize;
                mode = MetadataExchangeClientMode.HttpGet;
            }
            else if (mexBinding is CustomBinding)
            {
                (mexBinding as CustomBinding).Elements.Find <TransportBindingElement>().MaxReceivedMessageSize = maxReceivedMessageSize;
            }
            else
            {
                throw new Exception(string.Format("Not supported binding for metadata exchange"));
            }

            MetadataExchangeClient proxy = new MetadataExchangeClient(mexBinding);

            proxy.ResolveMetadataReferences = true;
            MetadataSet mds = proxy.GetMetadata(address, mode);

            return(mds);
        }
Beispiel #29
0
        // Конструктор по умолчанию определяется как private
        private WcfEventService()
        {
            // Регистрация сервиса и его метаданных
            _svcHost = new ServiceHost(typeof(ModbusIntegratorEventService),
                                       new[]
            {
                new Uri("net.pipe://localhost/ModbusIntegrationServer")
            });
            _svcHost.AddServiceEndpoint(typeof(IClientEventService),
                                        new NetNamedPipeBinding(), "");
            var behavior = new ServiceMetadataBehavior();

            _svcHost.Description.Behaviors.Add(behavior);
            _svcHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                        MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
        }
        protected override void ApplyConfiguration()
        {
            base.ApplyConfiguration();

            ServiceMetadataBehavior mexBehavior = this.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior != null)
            {
                return;
            }

            mexBehavior = new ServiceMetadataBehavior();
            this.Description.Behaviors.Add(mexBehavior);

            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }