Exemple #1
0
        public void WfcServiceHost_Http()
        {
            // Verify that we can create a service instance and then call it.

            WcfServiceHost host;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>");
                host.ExposeServiceDescription(null, null);
                host.Start();

                TestServiceClient client;

                client = new TestServiceClient(new WSHttpBinding(SecurityMode.None), new EndpointAddress("http://localhost:8008/Unit/Test.svc"));
                client.Open();
                try
                {
                    client.Set("Hello World!");
                    Assert.AreEqual("Hello World!", client.Get());
                }
                finally
                {
                    client.Close();
                }
            }
            finally
            {
                host.Stop();
            }
        }
Exemple #2
0
        public void WfcServiceHost_Http_WcfClientContext()
        {
            // Verify that we can create a service instance and then call it using WcfClientContext.

            WcfServiceHost host;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>");
                host.ExposeServiceDescription(null, null);
                host.Start();

                using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>(@"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>"))
                    using (WcfClientContext <ITestService> client = new WcfClientContext <ITestService>(factory.CreateChannel()))
                    {
                        client.Open();
                        client.Proxy.Set("Hello World!");
                        Assert.AreEqual("Hello World!", client.Proxy.Get());
                    }
            }
            finally
            {
                host.Stop();
            }
        }
Exemple #3
0
        public bool Stop()
        {
            ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Stop");

            try
            {
                if (_host != null)
                {
                    lock (_lock)
                    {
                        if (_host != null)
                        {
                            _host.Close();
                            _host = null;
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
                _host = null;
            }

            return(false);
        }
Exemple #4
0
        public void WfcServiceHost_Basic_Http_Via_Factory()
        {
            // Verify that we can create a service instance and then call it
            // using a client proxy generated by a WcfChannelFactory using
            // a HTTP transport.

            WcfServiceHost host;
            ITestService   client;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), "binding=HTTP;uri=http://localhost:8008/Unit/Test.svc");
                host.ExposeServiceDescription(null, null);
                host.Start();

                using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>("binding=HTTP;uri=http://localhost:8008/Unit/Test.svc"))
                {
                    client = factory.CreateChannel();
                    using (client as IDisposable)
                    {
                        client.Set("Hello World!");
                        Assert.AreEqual("Hello World!", client.Get());
                    }
                }
            }
            finally
            {
                host.Stop();
            }
        }
Exemple #5
0
        public void WfcServiceHost_LillTek_Via_Factory()
        {
            // Verify that we can create a service instance and then call it
            // using a client proxy generated by a WcfChannelFactory using
            // the LillTek transport.

            WcfServiceHost host;
            ITestService   client;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), "binding=lilltek;uri=lilltek.logical://wcftest");
                host.ExposeServiceDescription(null, null);
                host.Start();

                using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>("binding=lilltek;uri=lilltek.logical://wcftest"))
                {
                    client = factory.CreateChannel();
                    using (client as IDisposable)
                    {
                        client.Set("Hello World!");
                        Assert.AreEqual("Hello World!", client.Get());
                    }
                }
            }
            finally
            {
                host.Stop();
            }
        }
Exemple #6
0
 private void StopWcfService()
 {
     if ((Settings.Instance.IsHub || Settings.Instance.UseWcf) && !wcfStopStart)
     {
         Logging.Log(LogLevelEnum.Info, "Stopping WCF service");
         serviceConnection.Stop();
         serviceConnection = null;
         Logging.Log(LogLevelEnum.Info, "WCF service stopped");
     }
 }
Exemple #7
0
 private void StartWcfService()
 {
     if ((Settings.Instance.IsHub || Settings.Instance.UseWcf) && !wcfStopStart)
     {
         Logging.Log(LogLevelEnum.Info, "Initialize WCF service start");
         serviceConnection = new WcfServiceHost <WcfService, IWcfContract>();
         serviceConnection.Start();
         Logging.Log(LogLevelEnum.Info, "Initialize WCF service end");
     }
 }
Exemple #8
0
        protected override void OnStart(string[] args)
        {
            OnStop();

            if (_wcfServiceHost == null)
            {
                _wcfServiceHost = WcfServiceHost.Create(EventLog);
            }

            _wcfServiceHost.Start();
        }
 public WCFBasisService()
 {
     InitializeComponent();
     
     var clientsRepository = new ClientsRepository();
     var clientsNotifications = new NotificationFactory(clientsRepository);
     var clientsManagement = new ClientsManagement(clientsRepository);
     var actionsHandler = new ServiceActionsHandler(clientsManagement, clientsNotifications);
     
     _wcfServiceHost = new WcfServiceHost(new ServiceContract(actionsHandler));
 }
        private void CurrentDomain_ProcessExit(object sender, EventArgs e)
        {
            foreach (var sMember in ListOfAllConnectedMember)
            {
                sMember.SendToClient("Close");
            }

            Console.WriteLine("exit");
            UdpClient.Close();
            WcfServiceHost.Close();
            SelfHostServer.CloseAsync();
            // Benachrichtige alle Member, dass der Server geschlossen wird, also schließe auch alle Verbindungen.
        }
Exemple #11
0
        private void Run()
        {
            logger.Info("Application start");

            PhonebookImportServiceImpl sampleService = new PhonebookImportServiceImpl(logger);

            WcfServiceHost serviceHost = new WcfServiceHost();

            serviceHost.Open(sampleService);

            Console.ReadKey();

            serviceHost.Close();
        }
Exemple #12
0
        public void WfcServiceHost_Verify_WSDL()
        {
            // Verify that we can obtain the service WSDL via a HTTP GET.

            WcfServiceHost  host;
            string          contents;
            HttpWebRequest  request;
            HttpWebResponse response;
            StreamReader    reader;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), "binding=BasicHTTP;uri=http://localhost:8008/Unit/Test.svc");
                host.ExposeServiceDescription("http://localhost:8008/Unit/Test.wsdl", null);
                host.Start();

                request  = (HttpWebRequest)WebRequest.Create("http://localhost:8008/Unit/Test.wsdl");
                response = null;
                reader   = null;

                try
                {
                    response = (HttpWebResponse)request.GetResponse();
                    reader   = new StreamReader(response.GetResponseStream());
                    contents = reader.ReadToEnd();
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }

                    if (response != null)
                    {
                        response.Close();
                    }
                }

                Assert.IsTrue(200 <= (int)response.StatusCode && (int)response.StatusCode <= 299);
                Assert.IsTrue(response.ContentType.ToUpper().StartsWith("TEXT"));
                Assert.IsTrue(contents.IndexOf("<wsdl:") != -1);
            }
            finally
            {
                host.Stop();
            }
        }
Exemple #13
0
        public void WfcServiceHost_Parse_BehaviorXML()
        {
            // Verify that we can parse behavior XML.

            WcfServiceHost host;

            host = new WcfServiceHost(new TestService());

            host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>");
            host.ExposeServiceDescription(null, null);

            host.AddBehaviors(
                @"<behavior>
    <serviceSecurityAudit auditLogLocation=""Application""
                          suppressAuditFailure=""true""
                          serviceAuthorizationAuditLevel=""Success""
                          messageAuthenticationAuditLevel=""SuccessOrFailure"" />
    <serviceThrottling maxConcurrentCalls=""121""
                       maxConcurrentInstances=""122""
                       maxConcurrentSessions=""123"" />
    <serviceTimeouts transactionTimeout=""10m"" />
</behavior>
");
            ServiceBehaviorAttribute     serviceBehavior      = (ServiceBehaviorAttribute)host.Host.Description.Behaviors[typeof(ServiceBehaviorAttribute)];
            ServiceSecurityAuditBehavior serviceSecurityAudit = (ServiceSecurityAuditBehavior)host.Host.Description.Behaviors[typeof(ServiceSecurityAuditBehavior)];
            ServiceThrottlingBehavior    serviceThrottling    = (ServiceThrottlingBehavior)host.Host.Description.Behaviors[typeof(ServiceThrottlingBehavior)];

            Assert.IsNotNull(serviceBehavior);
            Assert.IsNotNull(serviceSecurityAudit);
            Assert.IsNotNull(serviceThrottling);

            Assert.AreEqual("00:10:00", serviceBehavior.TransactionTimeout);

            Assert.AreEqual(AuditLogLocation.Application, serviceSecurityAudit.AuditLogLocation);
            Assert.IsTrue(serviceSecurityAudit.SuppressAuditFailure);
            Assert.AreEqual(AuditLevel.Success, serviceSecurityAudit.ServiceAuthorizationAuditLevel);
            Assert.AreEqual(AuditLevel.SuccessOrFailure, serviceSecurityAudit.MessageAuthenticationAuditLevel);

            Assert.AreEqual(121, serviceThrottling.MaxConcurrentCalls);
            Assert.AreEqual(122, serviceThrottling.MaxConcurrentInstances);
            Assert.AreEqual(123, serviceThrottling.MaxConcurrentSessions);
        }
Exemple #14
0
        public static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <ClientsRepository>().As <IClientsRepository>().SingleInstance();
            containerBuilder.RegisterType <NotificationFactory>().As <INotificationFactory>().SingleInstance();
            containerBuilder.RegisterType <ClientsManagement>().As <IClientsManagement>().SingleInstance();
            containerBuilder.RegisterType <ServiceActionsHandler>().As <IServiceActionsHandler>().SingleInstance();
            containerBuilder.RegisterType <ServiceContract>().As <IServiceContract>().SingleInstance();

            var container = containerBuilder.Build();

            using (var scope = container.BeginLifetimeScope())
            {
                var host = new WcfServiceHost(scope.Resolve <IServiceContract>());

                host.Open();

                Console.ReadKey();

                host.Close();
            }
        }
Exemple #15
0
        /// <summary>
        /// Starts a <see cref="ServiceHost"/> for each found service. Defaults to <see cref="BasicHttpBinding"/> if
        /// no user specified binding is found
        /// </summary>
        public void Start()
        {
            foreach (var serviceType in Configure.TypesToScan.Where(t => !t.IsAbstract && IsWcfService(t)))
            {
                _host = new WcfServiceHost(serviceType);

                Binding binding = new BasicHttpBinding();

                if (Configure.Instance.Configurer.HasComponent <Binding>())
                {
                    binding = Configure.Instance.Builder.Build <Binding>();
                }

                _host.AddDefaultEndpoint(GetContractType(serviceType),
                                         binding
                                         , "");

                _hosts.Add(_host);

                logger.InfoFormat("Initialising the WCF service: {0}", serviceType.AssemblyQualifiedName);

                _host.Open();
            }
        }
Exemple #16
0
        protected override void OnShutdown()
        {
            OnStop();

            _wcfServiceHost = null;
        }
        /// <summary>
        /// Prepares the parameters for this connector and ensures that resources exist so the <seealso cref="Start"/> operation
        /// succeeds.
        /// </summary>
        public void Open()
        {
            // Connection string
            if (ConnectionString == null)
            {
                throw new ConnectorException(ConnectorException.MSG_NULL_CONNECTION_STRING, ConnectorException.ReasonType.NullConnectionString);
            }
            else if (Formatter == null)
            {
                throw new ConnectorException(ConnectorException.MSG_NULL_FORMATTER, ConnectorException.ReasonType.NullFormatter);
            }

            Dictionary <string, List <string> > conf = ConnectionStringParser.ParseConnectionString(ConnectionString);

            string epAddress = string.Empty, epBinding = string.Empty, epContract = string.Empty,
                   epBindingConfig = string.Empty;

            // Load
            List <string> tmpValues;

            if (conf.TryGetValue("servicename", out tmpValues))
            {
                serviceName = tmpValues[0];
            }
            if (conf.TryGetValue("endpointaddress", out tmpValues))
            {
                epAddress = tmpValues[0];
            }
            if (conf.TryGetValue("bindingtype", out tmpValues))
            {
                epBinding = tmpValues[0];
            }
            if (conf.TryGetValue("bindingconfig", out tmpValues))
            {
                epBindingConfig = tmpValues[0];
            }

            epContract = typeof(IConnectorContract).FullName;

            // Service host
            svcHost = null;

            if (String.IsNullOrEmpty(epAddress))
            {
                svcHost = new WcfServiceHost(serviceName, typeof(ConnectorService));
            }
            else
            {
                svcHost = new WcfServiceHost(null, typeof(ConnectorService));
                if (!String.IsNullOrEmpty(epBindingConfig))
                {
                    svcHost.AddServiceEndpoint(
                        epContract,
                        epBinding == "basicHttpBinding" ? (Binding)(new BasicHttpBinding(epBindingConfig)) : epBinding == "wsHttpBinding" ? (Binding)(new WSHttpBinding(epBindingConfig)) : null,
                        epAddress
                        );
                }
                else
                {
                    svcHost.AddServiceEndpoint(
                        epContract,
                        epBinding == "basicHttpBinding" ? (Binding)(new BasicHttpBinding()) : epBinding == "wsHttpBinding" ? (Binding)(new WSHttpBinding()) : null,
                        epAddress
                        );
                }
            }

            svcHost.ConnectorHost = this;
        }
 /// <summary>
 /// Close the WCF connector.
 /// </summary>
 public void Close()
 {
     Stop();
     svcHost = null;
 }
Exemple #19
0
        public bool Start()
        {
            ModuleProc PROC   = new ModuleProc(this.DYN_MODULE_NAME, "Start");
            bool       result = false;

            try
            {
                if (_host == null)
                {
                    lock (_lock)
                    {
                        if (_host == null)
                        {
                            // Host
                            string hostName = Dns.GetHostName();

                            // Add the base address
                            Type serviceType = typeof(ConfigStoreService);

                            Uri pipeUri = new Uri(ConfigStoreManager.GetPipeName(Process.GetCurrentProcess().Id));
                            Log.Info(PROC, pipeUri.AbsoluteUri);

                            // default servuce
                            if (true)
                            {
                                _host = new WcfServiceHost(serviceType, null, new Uri[] { pipeUri });
                                Type[] interfaces = serviceType.GetInterfaces();
                                string serviceContractAttrString = typeof(ServiceContractAttribute).ToString();
                                if (interfaces != null)
                                {
                                    foreach (Type iface in interfaces)
                                    {
                                        ServiceContractAttribute serviceContractAttr = (from c in iface.GetCustomAttributes(false)
                                                                                        where c.ToString() == serviceContractAttrString
                                                                                        select c).FirstOrDefault() as ServiceContractAttribute;
                                        if (serviceContractAttr != null)
                                        {
                                            // named pipe
                                            _host.AddServiceEndpoint(iface, CreateNamedPipeBinding(),
                                                                     pipeUri);
                                        }
                                    }
                                }
                            }

                            // Mex endpoings
                            _host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                                     "mex");
                            Log.Info(PROC, pipeUri.AbsoluteUri + "/mex");
                        }
                    }
                }

                // default service host
                try
                {
                    if (_host != null &&
                        _host.State == CommunicationState.Created)
                    {
                        _host.Open();
                        result = true;
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(PROC, ex);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }

            return(result);
        }