Beispiel #1
0
        private static void InitSoapService() // Запуск WCF SOAP сервиса
        {
            Log.Debug("Starting service...");
            // Инициализируем службу, указываем адрес, по которому она будет доступна
            ServiceHost host = new ServiceHost(typeof(WritterService),
                                               new Uri(ServiceUrl));

            // Добавляем конечную точку службы с заданным интерфейсом, привязкой (создаём новую) и адресом конечной точки
            host.AddServiceEndpoint(typeof(IWritterService), new BasicHttpBinding(), "");

            // Собираем wsdl-описание контракта сервиса
            ServiceMetadataBehavior metad
                = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (metad == null)
            {
                metad = new ServiceMetadataBehavior();
            }
            metad.HttpGetEnabled = true;
            host.Description.Behaviors.Add(metad);
            host.AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                MetadataExchangeBindings.CreateMexHttpBinding(),
                "mex"
                );

            // Запускаем службу
            host.Open();
            HttpHost = host;

            Console.WriteLine("Service started");
            Log.Information("Service started");
        }
        static void Main(string[] args)
        {
            ServiceHost      hostObj = null;
            Uri              address = new Uri("http://localhost:8888/Matematika");
            BasicHttpBinding bind    = new BasicHttpBinding();

            try
            {
                hostObj = new ServiceHost(typeof(Matematika), address);
                hostObj.AddServiceEndpoint(typeof(IMatematika), bind, "");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                hostObj.Description.Behaviors.Add(smb);

                Binding mexbind = MetadataExchangeBindings.CreateMexHttpBinding();
                hostObj.AddServiceEndpoint(typeof(IMetadataExchange), mexbind, "mex");

                hostObj.Open();
                Console.WriteLine("Server is ready!!!!");
                Console.ReadLine();
                hostObj.Close();
            }

            catch (Exception ex)
            {
                hostObj = null;
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            ServiceHost    hostObjek = null;
            Uri            address   = new Uri("http://localhost:1907/Mahasiswa");
            WebHttpBinding binding   = new WebHttpBinding();

            try
            {
                hostObjek = new ServiceHost(typeof(TI_UMY), address);
                hostObjek.AddServiceEndpoint(typeof(ITI_UMY), binding, "");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                hostObjek.Description.Behaviors.Add(smb);
                Binding mexbinding = MetadataExchangeBindings.CreateMexHttpBinding();
                hostObjek.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");

                WebHttpBehavior whb = new WebHttpBehavior();
                whb.HelpEnabled = true;
                hostObjek.Description.Endpoints[0].EndpointBehaviors.Add(whb);

                hostObjek.Open();
                Console.WriteLine("Server Ready");
                Console.ReadLine();
                hostObjek.Close();
            }

            catch (Exception ex)
            {
                hostObjek = null;
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
                Environment.Exit(1); // завершаем процесс
            };
            EnvPath = args[0];


            new System.Threading.Thread(new System.Threading.ThreadStart(ReadInput)).Start();

            try {
                ServiceHost serviceHost = new ServiceHost(typeof(WCFService), new Uri("http://localhost:8000/sparkInput"));
                serviceHost.AddServiceEndpoint(typeof(Service.IContractIn), new BasicHttpBinding(), "");
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;
                serviceHost.Description.Behaviors.Add(behavior);
                serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
                serviceHost.Open();
            } catch {
                //Service.Log.LogShow(EnvPath, "Нет прав администратора", e.ToString(), "Ошибка", Service.MessageViewMode.Error);
            }

            ChannelFactory <Service.IContract> myChannelFactory = new ChannelFactory <Service.IContract>(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/sparkMain"));

            wcfMain = myChannelFactory.CreateChannel();
            ((IClientChannel)wcfMain).OperationTimeout = new TimeSpan(0, 0, 10);

            ResetSerialPort.Elapsed += ResetSerialPort_Elapsed;
            Status = 1;

            while (true)
            {
                System.Threading.Thread.Sleep(250);
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("net.tcp://localhost:8000/ProjetDev.WCF.Service/");

            ServiceHost host = new ServiceHost(typeof(RequestService));

            try
            {
                host.AddServiceEndpoint(typeof(IRequestService), new NetTcpBinding(), baseAddress + "RequestService/");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.HttpGetUrl     = new Uri("http://localhost:8001/ProjetDev.WCF.Service/RequestService/");
                host.Description.Behaviors.Add(smb);

                host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "http://localhost:8001/ProjetDev.WCF.Service/RequestService/");



                host.Open();
                Console.WriteLine("Started host succesfully!");
                Console.WriteLine("Press enter to exit application");
                Console.ReadLine();
                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception: {e.Message}");
                host.Abort();
            }
            Console.ReadLine();
        }
Beispiel #6
0
        static void ServiceFromCode()
        {
            Console.Out.WriteLine("Testing Udp From Code.");

            Binding datagramBinding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new UdpTransportBindingElement());

            // using the 2-way calculator method requires a session since UDP is not inherently request-response
            SampleProfileUdpBinding calculatorBinding = new SampleProfileUdpBinding(true);

            calculatorBinding.ClientBaseAddress = new Uri("soap.udp://localhost:8003/");

            Uri calculatorAddress = new Uri("soap.udp://localhost:8001/");
            Uri datagramAddress   = new Uri("soap.udp://localhost:8002/datagram");

            // we need an http base address so that svcutil can access our metadata
            ServiceHost             service          = new ServiceHost(typeof(CalculatorService), new Uri("http://localhost:8000/udpsample/"));
            ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();

            metadataBehavior.HttpGetEnabled = true;
            service.Description.Behaviors.Add(metadataBehavior);
            service.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            service.AddServiceEndpoint(typeof(ICalculatorContract), calculatorBinding, calculatorAddress);
            service.AddServiceEndpoint(typeof(IDatagramContract), datagramBinding, datagramAddress);
            service.Open();

            Console.WriteLine("Service is started from code...");
            Console.WriteLine("Press <ENTER> to terminate the service and start service from config...");
            Console.ReadLine();

            service.Close();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var logger  = new Logger(typeof(WordCounter));
            var svcHost = new ServiceHost(typeof(WordCounter), new Uri("http://localhost:50000/WordCount"));
            var smb     = svcHost.Description.Behaviors.Find <ServiceMetadataBehavior>();

            // If not, add one
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior();
            }
            smb.HttpGetEnabled = true;
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            svcHost.Description.Behaviors.Add(smb);
            // Add MEX endpoint
            svcHost.AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                MetadataExchangeBindings.CreateMexHttpBinding(),
                "mex"
                );

            var ep = svcHost.AddServiceEndpoint(typeof(IWordCount), new BasicHttpBinding(), "");

            svcHost.Open();
            Console.WriteLine("Service is running on: ");
            foreach (var endPoint in  svcHost.Description.Endpoints)
            {
                Console.WriteLine(endPoint.Address);
            }
            Console.WriteLine("Press enter to quit...");
            Console.ReadLine();
            svcHost.Close();
        }
        public void Start()
        {
            myServiceHost = new ServiceHost(myServiceImplementation, new Uri(myConfig.Uri));
            myServiceHost.AddServiceEndpoint(typeof(IMonitorWang),
                                             new BasicHttpBinding(),
                                             string.Empty);

            // Add MEX to the Endpoint
            // http://msdn.microsoft.com/en-us/library/aa738489.aspx
            var smb = new ServiceMetadataBehavior
            {
                HttpGetEnabled   = true,
                MetadataExporter = { PolicyVersion = PolicyVersion.Policy15 }
            };

            myServiceHost.Description.Behaviors.Add(smb);
            myServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                             MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            myServiceHost.Open();

            Logger.Debug("\t\t{0} is listening on these endpoints...", Identity.Name);
            myServiceHost.Description.Endpoints.ToList().ForEach(
                t => Logger.Debug("\t\t{0}", t.ListenUri));
        }
Beispiel #9
0
        private static void ProgrammingModelTest()
        {
            Uri url = new Uri("http://localhost:5000");


            using (ServiceHost host = new ServiceHost(typeof(FakeHelloServices.FakeHelloService), url))
            {
                Binding binding = new BasicHttpBinding();

                //Add a service endpoint
                host.AddServiceEndpoint(typeof(IHelloServices.IHelloService), binding, string.Empty);

                //Enable metadata exchange
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                host.Description.Behaviors.Add(behavior);

                Binding mexBinding = MetadataExchangeBindings.CreateMexHttpBinding();
                host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex");

                host.Open();

                Console.WriteLine("Host started on");

                foreach (var uri in host.BaseAddresses)
                {
                    Console.WriteLine(uri);
                }
            }
        }
Beispiel #10
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 #11
0
        protected override void OnStart(string[] args)
        {
            if (service_host != null)
            {
                service_host.Close();
            }

            string address_HTTP = "http://localhost:20000/AssociaciaPATUkrzaliznytsaServer";
            string address_TCP  = "net.tcp://localhost:20000/AssociaciaPATUkrzaliznytsaServer";

            Uri[] address_base = { new Uri(address_HTTP), new Uri(address_TCP) };
            service_host = new ServiceHost(typeof(AssociaciaPATUkrzakiznutsaLibrery.AssociaciaPATUkrzaliznytsaServer), address_base);

            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();

            service_host.Description.Behaviors.Add(behavior);

            BasicHttpBinding binding_http = new BasicHttpBinding();

            service_host.AddServiceEndpoint(typeof(AssociaciaPATUkrzakiznutsaLibrery.IContract), binding_http, address_HTTP);
            service_host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            NetTcpBinding binding_tcp = new NetTcpBinding();

            binding_tcp.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            binding_tcp.Security.Message.ClientCredentialType   = MessageCredentialType.Windows;
            service_host.AddServiceEndpoint(typeof(AssociaciaPATUkrzakiznutsaLibrery.IContract), binding_tcp, address_TCP);
            service_host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");

            service_host.Open();
        }
        static void Main(string[] args)
        {
            Uri httpBaseAddress = new Uri("http://localhost:6789/");

            ServiceHost Sh = new ServiceHost(typeof(MEP), new Uri[] { httpBaseAddress });

            ServiceEndpoint Se = Sh.AddServiceEndpoint(typeof(IMEP), new WSDualHttpBinding(), httpBaseAddress);


            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();

            Sh.Description.Behaviors.Add(smb);

            ServiceEndpoint tcpSeMex = Sh.AddServiceEndpoint(typeof(IMetadataExchange),
                                                             MetadataExchangeBindings.CreateMexHttpBinding(),
                                                             "http://localhost:6789/mex");

            Sh.Open();

            Console.WriteLine("Started.....");

            foreach (var item in Sh.Description.Endpoints)
            {
                Console.WriteLine("Address: " + item.Address.ToString());
                Console.WriteLine("Binding: " + item.Binding.Name.ToString());
                Console.WriteLine("Contract: " + item.Contract.Name.ToString());
            }

            Console.ReadLine();

            Sh.Close();
        }
Beispiel #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            ServiceHost    hostObjek = null;
            Uri            address   = new Uri("http://localhost:1907/Mahasiswa");
            WebHttpBinding bind      = new WebHttpBinding();

            try
            {
                hostObjek = new ServiceHost(typeof(TI_UMY), address);
                hostObjek.AddServiceEndpoint(typeof(ITI_UMY), bind, "");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                hostObjek.Description.Behaviors.Add(smb);
                System.ServiceModel.Channels.Binding mexbind = MetadataExchangeBindings.CreateMexHttpBinding();
                hostObjek.AddServiceEndpoint(typeof(IMetadataExchange), mexbind, "mex");

                WebHttpBehavior whb = new WebHttpBehavior();
                whb.HelpEnabled = true;
                hostObjek.Description.Endpoints[0].EndpointBehaviors.Add(whb);

                hostObjek.Abort();
                label1.Text     = "Silakan Nyalakan Server";
                button1.Enabled = false;
                button2.Enabled = false;
            }
            catch (Exception ex)
            {
                hostObjek = null;
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
        SecurityMode SetMexAndSecurity(ServiceHost host,
                                       string mexScheme)
        {
            ServiceMetadataBehavior mexHttpBehavior = new ServiceMetadataBehavior();
            Uri          mexUri = new Uri("/mex", UriKind.Relative);
            Binding      binding;
            SecurityMode securityMode;

            if (mexScheme == Uri.UriSchemeHttp)
            {
                mexHttpBehavior.HttpGetEnabled = true;
                binding      = MetadataExchangeBindings.CreateMexHttpBinding();
                securityMode = SecurityMode.Message;
            }
            else
            {
                mexHttpBehavior.HttpsGetEnabled = true;
                binding      = MetadataExchangeBindings.CreateMexHttpsBinding();
                securityMode = SecurityMode.TransportWithMessageCredential;
            }
            host.Description.Behaviors.Add(mexHttpBehavior);
            host.AddServiceEndpoint(typeof(IMetadataExchange), binding, mexUri);

            return(securityMode);
        }
Beispiel #15
0
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            var serviceHost = new ServiceHost(serviceType, baseAddresses);

            serviceHost.Description.Behaviors.Add(Resolver.Activate <IServiceBehavior>("IOC"));
            var configurator = Resolver.Activate <IServiceConfiguration>();

            configurator.ConfigureServiceHost(serviceHost, serviceType);
            SetBehaviour(serviceHost);
            if (!Interstellar.Utilities.Utilities.IsTestEnv() && !Interstellar.Utilities.Utilities.IsDevelopementEnv())
            {
                return(serviceHost);
            }
            var smb = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (smb == null)
            {
                smb = new ServiceMetadataBehavior();
                serviceHost.Description.Behaviors.Add(smb);
            }
            smb.HttpGetEnabled  = true;
            smb.HttpsGetEnabled = true;
            //serviceHost.Description.Behaviors.Add(new ServiceSecurityAuditBehavior{AuditLogLocation = AuditLogLocation.Application});
            serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
            serviceHost.Description.Behaviors.Add(new ErrorServiceBehavior());
            serviceHost.Faulted += serviceHost_Faulted;
            return(serviceHost);
        }
Beispiel #16
0
        public void Start()
        {
            // auth
            var serviceCredentials = new ServiceCredentials();

            serviceCredentials.UserNameAuthentication.UserNamePasswordValidationMode  = UserNamePasswordValidationMode.Custom;
            serviceCredentials.UserNameAuthentication.CustomUserNamePasswordValidator = new ServiceAuthenticator();

            servidor.Description.Behaviors.Add(serviceCredentials);

            // bind
            var binding = new BasicHttpBinding();

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

            servidor.AddServiceEndpoint(
                typeof(IProdutoService),
                binding,
                "Produto.svc"
                );

            // mex
            servidor.Description.Behaviors.Add(new ServiceMetadataBehavior());
            servidor.AddServiceEndpoint(
                typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexHttpBinding(),
                "mex"
                );

            servidor.Open();
        }
        protected override void OnStart(string[] args)
        {
            if (_serciveHost != null)
            {
                _serciveHost.Close();
            }

            string httpAddress = "http://localhost:9001/CalcService";
            string tcpAddress  = "net.tcp://localhost:9002/CalcService";

            Uri[] adresses = { new Uri(httpAddress), new Uri(tcpAddress) };
            _serciveHost = new ServiceHost(typeof(WCFCalcLib.CalcService), adresses);

            ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();

            _serciveHost.Description.Behaviors.Add(mBehave);

            BasicHttpBinding httpb = new BasicHttpBinding();

            _serciveHost.AddServiceEndpoint(typeof(WCFCalcLib.ICalcService), httpb, httpAddress);
            _serciveHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            NetTcpBinding tcpb = new NetTcpBinding();

            _serciveHost.AddServiceEndpoint(typeof(WCFCalcLib.ICalcService), tcpb, tcpAddress);
            _serciveHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");

            _serciveHost.Open();
        }
Beispiel #18
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");
                }
            }
        }
Beispiel #19
0
        protected override void OnStart(string[] args)
        {
            if (service_host != null)
            {
                service_host.Close();
            }

            string address_HTTP = "http://localhost:9001/AntivirusService";
            string address_TCP  = "net.tcp://localhost:9002/AntivirusService";

            Uri[] address_base = { new Uri(address_HTTP), new Uri(address_TCP) };
            service_host = new ServiceHost(typeof(AntiVirusDLL.AntivirusService), address_base);

            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();

            service_host.Description.Behaviors.Add(behavior);

            BasicHttpBinding binding_http = new BasicHttpBinding();

            service_host.AddServiceEndpoint(typeof(AntiVirusDLL.IAntivirusService), binding_http, address_HTTP);
            service_host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            NetTcpBinding binding_tcp = new NetTcpBinding();

            binding_tcp.Security.Mode = SecurityMode.Transport;
            binding_tcp.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            binding_tcp.Security.Message.ClientCredentialType   = MessageCredentialType.Windows;
            binding_tcp.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;
            service_host.AddServiceEndpoint(typeof(AntiVirusDLL.IAntivirusService), binding_tcp, address_TCP);
            service_host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");

            service_host.Open();
        }
        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));
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            ServiceHost sh = new ServiceHost(typeof(MyMath), new Uri("http://localhost/MyMath"));

            /* find in App.config
             *
             * sh.AddServiceEndpoint(
             *  typeof(IMyMath),
             *  new WSHttpBinding(),
             *  "http://localhost/MyMath/EndP1");
             *
             */

            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();

            behavior.HttpGetEnabled = true;

            sh.Description.Behaviors.Add(behavior);
            sh.AddServiceEndpoint(
                typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexHttpBinding(),
                "mex");

            sh.Open();
            Console.WriteLine("Push any key for exit");
            Console.ReadKey();
            sh.Close();
        }
Beispiel #22
0
        /// <summary>
        /// Find the wsdl importer
        /// </summary>
        /// <param name="wsdlUri">The wsdl uri</param>
        /// <returns>A wsdl importer</returns>
        private WsdlImporter GetWsdlImporter(Uri wsdlUri)
        {
            _logger.WriteDebug($"GetWsdlImporter wsdlUri[{wsdlUri}]");
            WSHttpBinding mexBinding = null;

            if (wsdlUri.Scheme == Uri.UriSchemeHttp)
            {
                mexBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpBinding();
            }
            else
            {
                mexBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpsBinding();
            }
            mexBinding.MaxReceivedMessageSize = Int32.MaxValue;
            mexBinding.MaxBufferPoolSize      = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxNameTableCharCount  = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxArrayLength         = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxBytesPerRead        = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxDepth = 64;

            var mexClient = new MetadataExchangeClient(mexBinding);

            mexClient.MaximumResolvedReferences = int.MaxValue;

            var metadataSet = mexClient.GetMetadata(wsdlUri, MetadataExchangeClientMode.HttpGet);

            return(new WsdlImporter(metadataSet));
        }
        public void CreateMexHttpBinding()
        {
            var b = MetadataExchangeBindings.CreateMexHttpBinding() as WSHttpBinding;

            Assert.IsNotNull(b, "#1");
            Assert.AreEqual(SecurityMode.None, b.Security.Mode, "#2");
            Assert.IsFalse(b.TransactionFlow, "#3");
            Assert.IsFalse(b.ReliableSession.Enabled, "#4");
            Assert.IsFalse(b.CreateBindingElements().Any(be => be is SecurityBindingElement), "#b1");
            Assert.IsTrue(b.CreateBindingElements().Any(be => be is TransactionFlowBindingElement), "#b2");
            Assert.IsFalse(b.CreateBindingElements().Any(be => be is ReliableSessionBindingElement), "#b3");
            Assert.IsTrue(new TransactionFlowBindingElement().TransactionProtocol == TransactionProtocol.Default, "#x1");
            Assert.AreEqual(MessageVersion.Soap12WSAddressing10, b.MessageVersion, "#5");
            Assert.AreEqual(MessageVersion.Soap12WSAddressing10, b.GetProperty <MessageVersion> (new BindingParameterCollection()), "#6");

            var host = new ServiceHost(typeof(MetadataExchange));

            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), CreateUri("http://localhost:30158"));
            host.Open();
            try {
                // it still does not rewrite MessageVersion.None. It's rather likely ServiceMetadataExtension which does overwriting.
                Assert.AreEqual(MessageVersion.Soap12WSAddressing10, ((ChannelDispatcher)host.ChannelDispatchers [0]).MessageVersion, "#7");
            } finally {
                host.Close();
            }
        }
Beispiel #24
0
        public ServiceEndpoint Host <T>(ServiceHost host, ServiceInfo serviceInfo)
        {
            const string addressUriFormat = "{0}://{1}:{2}/{3}/{4}/";
            string       endpointAddress  = string.Format(addressUriFormat, "http", serviceInfo.ServerName, serviceInfo.Binding.Configuration.Port,
                                                          serviceInfo.Folder,
                                                          serviceInfo.ServiceName);

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

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

            var mexAddress = new Uri(endpointAddress + "MEX");

            smb.HttpGetEnabled = true;
            smb.HttpGetUrl     = mexAddress;

            var serviceEndpoint = host.AddServiceEndpoint(typeof(T), serviceInfo.Binding.WcfBinding, endpointAddress);

            host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                    MetadataExchangeBindings.CreateMexHttpBinding(), mexAddress);

            return(serviceEndpoint);
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.FirstChanceException += (sender, ea) => {
                System.Diagnostics.Debug.Print(ea.Exception.ToString());
            };

            //var svcImpl = new Connector();
            //var srv = new Server.Server(svcImpl);

            var impl = new Connector();

            using (ServiceHost host = new ServiceHost(impl, new Uri(@"http://127.0.0.1:9090/Notebook")))
            {
                var ep = host.AddServiceEndpoint(typeof(INotebook), new WebHttpBinding(), "");
                ep.EndpointBehaviors.Add(new WebHttpBehavior());
                ServiceMetadataBehavior behavior = host.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (behavior == null)
                {
                    behavior = new ServiceMetadataBehavior {
                        HttpGetEnabled = true
                    };
                    host.Description.Behaviors.Add(behavior);
                }
                host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
                host.Opening += new EventHandler(Host_Opening);
                host.Opened  += new EventHandler(Host_Opened);
                host.Open();

                Console.ReadLine();
            }
        }
Beispiel #26
0
        public ServerForm()
        {
            string           sUri     = "http://127.0.0.1:8081/Service1";
            string           sMetaUri = "http://127.0.0.1:8081/Service1Mex";
            BasicHttpBinding pBinding =
                new BasicHttpBinding();

            pBinding.Security.Transport.ClientCredentialType =
                HttpClientCredentialType.None;

            ServiceMetadataBehavior pSmb = new ServiceMetadataBehavior();

            pSmb.HttpGetEnabled = true;
            pSmb.HttpGetUrl     = new Uri(sMetaUri);
            pSmb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;

            m_pHost = new ServiceHost(typeof(Service1));
            m_pHost.Description.Behaviors.Add(pSmb);
            m_pHost.AddServiceEndpoint(
                typeof(IService1),
                pBinding,
                sUri);
            m_pHost.AddServiceEndpoint(
                typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexHttpBinding(),
                sMetaUri);

            InitializeComponent();
        }
        private void StartLocationService(string host, string port)
        {
            //1.配置方式启动服务
            //locationServiceHost = new ServiceHost(typeof(LocationService));
            //locationServiceHost.SetProxyDataContractResolver();
            //locationServiceHost.Open();

            //2.编程方式启动服务
            string url        = string.Format("http://{0}:{1}/LocationService", host, port);
            Uri    baseAddres = new Uri(url);

            locationServiceHost = new ServiceHost(typeof(LocationService), baseAddres);
            BasicHttpBinding httpBinding = new BasicHttpBinding();

            locationServiceHost.AddServiceEndpoint(typeof(ILocationService), httpBinding, baseAddres);
            //httpBinding.MaxReceivedMessageSize = 2147483647;
            //httpBinding.MaxBufferPoolSize = 2147483647;

            Binding binding = MetadataExchangeBindings.CreateMexHttpBinding();

            locationServiceHost.AddServiceEndpoint(typeof(IMetadataExchange), binding, "MEX");
            //开放数据交付终结点,客户端才能添加/更新服务引用。

            locationServiceHost.Open();

            WriteLog("LocationService: " + locationServiceHost.BaseAddresses[0]);
        }
Beispiel #28
0
        protected override void OnStart(string[] args)
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
            }

            string strAdrHTTP = "http://localhost:9017/WCFCarReceivingAppTest";
            string strAdrTCP  = "net.tcp://localhost:9032/WCFCarReceivingAppTest";

            Uri[] adrbase = { new Uri(strAdrHTTP), new Uri(strAdrTCP) };
            serviceHost = new ServiceHost(typeof(CarAppService), adrbase);

            ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();
            //   serviceHost.Description.Behaviors.Add(mBehave);

            BasicHttpBinding httpb = new BasicHttpBinding();

            serviceHost.AddServiceEndpoint(typeof(IService), httpb, strAdrHTTP);
            serviceHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                           MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            NetTcpBinding tcpb = new NetTcpBinding(SecurityMode.None);

            serviceHost.AddServiceEndpoint(typeof(IService), tcpb, strAdrTCP);
            serviceHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                           MetadataExchangeBindings.CreateMexTcpBinding(), "mex");

            serviceHost.Open();
        }
        static void Main(string[] args)
        {
            ServiceHost      hostObj = null;
            Uri              address = new Uri("http://localhost:8888/Matematika");
            BasicHttpBinding bind    = new BasicHttpBinding();

            try
            {
                hostObj = new ServiceHost(typeof(Matematika), address);
                //ALAMAT BASE ADDRESS
                hostObj.AddServiceEndpoint(typeof(IMatematika), bind, "");
                //ALAMAT ENDPOINT
                //wsdl
                ServiceMetadataBehavior smb = new
                                              ServiceMetadataBehavior(); //Service Runtime Player
                smb.HttpGetEnabled = true;                               //untuk mengaktifkan wsdl(dibuka saat development, tidak untuk dibuka)
                hostObj.Description.Behaviors.Add(smb);
                //mex
                Binding mexbind =
                    MetadataExchangeBindings.CreateMexHttpBinding();
                hostObj.AddServiceEndpoint(typeof(IMetadataExchange),
                                           mexbind, "mex");
                hostObj.Open();
                Console.WriteLine("Server is ready!!!!");
                Console.ReadLine();
                hostObj.Close();
            }
            catch (Exception ex)
            {
                hostObj = null;
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(typeof(ChatManagerService),
                                                      new Uri("http://localhost:8080/chatmgr")))
            {
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                //smb.HttpGetBinding = new WebHttpBinding();
                smb.HttpGetUrl = new Uri(host.BaseAddresses[0] + "/mex");

                ProfanityInterceptorBehavior pib = new ProfanityInterceptorBehavior();

                host.Description.Behaviors.Add(smb);
                //host.Description.Behaviors.Add(pib);

                //Manually create the service endpoint, and add to host collection
                Binding             binding     = new WSDualHttpBinding();
                EndpointAddress     address     = new EndpointAddress(host.BaseAddresses[0] + "/duplex");
                ContractDescription description = ContractDescription.GetContract(typeof(IChatManager));
                ServiceEndpoint     endpoint    = new ServiceEndpoint(description, binding, address);
                endpoint.EndpointBehaviors.Add(pib);
                host.AddServiceEndpoint(endpoint);

                //Add the metadata endpoint directly
                host.AddServiceEndpoint(typeof(IMetadataExchange),
                                        MetadataExchangeBindings.CreateMexHttpBinding(),
                                        "mex");

                host.Open();
                PrintServiceDescription(host);
                Console.ReadKey();
            }
        }