public void should_add_the_servicebehavior_to_the_behavior_collection()
        {
            var host =
                new WebServiceHost(typeof(FakeService), new[] { new Uri("net.tcp://localhost:8081") });

            host.AddServiceEndpoint(typeof(IFakeService), new NetTcpBinding(), "net.tcp://localhost:8081/MyService");
            host.Open();

            host.Description.Behaviors.ShouldContainType<ServiceBehavior>();
            host.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Stop the IMSI service
        /// </summary>
        public bool Stop()
        {
            this.Stopping?.Invoke(this, EventArgs.Empty);

            if (this.m_webHost != null)
            {
                this.m_webHost.Close();
                this.m_webHost = null;
            }

            this.Stopped?.Invoke(this, EventArgs.Empty);

            return(true);
        }
Ejemplo n.º 3
0
        private void StartService(Type serviceMannager)
        {
            Console.WriteLine($"Started service of type {serviceMannager}");
            if (_hosts == null)
            {
                _hosts = new List <SM.ServiceHost>();
            }


            var host = new WebServiceHost(serviceMannager);

            host.Open();
            _hosts.Add(host);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //Expand this region to see the code for hosting a Syndication Feed.
            #region Service

            WebServiceHost host = new WebServiceHost(typeof(ProcessService), new Uri("http://localhost:8000/diagnostics"));

            //The WebServiceHost will automatically provide a default endpoint at the base address
            //using the proper binding (the WebHttpBinding) and endpoint behavior (the WebHttpBehavior)
            host.Open();

            Console.WriteLine("Service host open");

            //The syndication feeds exposed by the service are available
            //at the following URI (for Atom use feed/?format=atom)

            // http://localhost:8000/diagnostics/feed/?format=rss

            //These feeds can be viewed directly in an RSS-aware client
            //such as IE7.
            #endregion

            //Expand this region to see the code for accessing a Syndication Feed.
            #region Client

            // Change the value of the feed query string to 'atom' to use Atom format.
            XmlReader reader = XmlReader.Create("http://localhost:8000/diagnostics/feed?format=rss",
                                                new XmlReaderSettings()
            {
                //MaxCharactersInDocument can be used to control the maximum amount of data
                //read from the reader and helps prevent OutOfMemoryException
                MaxCharactersInDocument = 1024 * 64
            });


            SyndicationFeed feed = SyndicationFeed.Load(reader);

            foreach (SyndicationItem i in feed.Items)
            {
                XmlSyndicationContent content = i.Content as XmlSyndicationContent;
                ProcessData           pd      = content.ReadContent <ProcessData>();

                Console.WriteLine(i.Title.Text);
                Console.WriteLine(pd.ToString());
            }
            #endregion

            //Press any key to end the program.
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Host a new network server
        /// </summary>
        /// <param name="directory">Path server will save data to
        /// <para>Example:  @"C:\MyTemp\Embark\Server\"</para></param>
        /// <param name="port">port to use, default set to 8030</param>
        /// <param name="textConverter">Custom converter between objects and text.
        /// <para>If parameter is NULL, the textConverter is set to default json converter.</para>
        /// </param>
        public Server(string directory, int port = 8030, ITextConverter textConverter = null)
        {
            if (textConverter == null)
            {
                textConverter = new JavascriptSerializerTextConverter();
            }

            var store          = new DiskDataStore(directory);
            var textRepository = new LocalRepository(store, textConverter);

            Uri url = new Uri("http://localhost:" + port + "/embark/");

            webHost = new WebServiceHost(textRepository, url);
        }
Ejemplo n.º 6
0
        public AddOnTask()
        {
            String uriStr = "http://localhost:" + Settings_WebServicePort.ToString() + "/PatternsAddOnService";

            Host = new WebServiceHost(typeof(PatternsService), new Uri(uriStr));
            var bind = new WebHttpBinding();

            bind.MaxReceivedMessageSize              = 2147483647;
            bind.ReaderQuotas.MaxArrayLength         = 2147483647;
            bind.ReaderQuotas.MaxStringContentLength = 2147483647;
            Host.AddServiceEndpoint(typeof(IPatternsService), bind, Settings_WebServiceEndpoint);
            StartTime = DateTime.MinValue;
            Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Information, "Patterns Add On Service, Add On Task, Service startup", "Service started");
        }
        public void Stop()
        {
            WebServiceHost       hostWeb = new WebServiceHost(typeof(restservice.Service));
            ServiceEndpoint      ep      = hostWeb.AddServiceEndpoint(typeof(restservice.IService), new WebHttpBinding(), "");
            ServiceDebugBehavior stp     = hostWeb.Description.Behaviors.Find <ServiceDebugBehavior>();

            stp.HttpHelpPageEnabled = false;
            hostWeb.Open();
            WinPOSPoint wpp = new WinPOSPoint();

            Console.WriteLine("WinPOSPoint Version " + wpp.ProgramVersion + " started on Host http://localhost:8081 " + DateTime.Now.ToString());

            Console.Read();
        }
Ejemplo n.º 8
0
        public void Start()
        {
            _host = new WebServiceHost(typeof(WCFEntryPoint), new Uri("http://localhost:9000"));
            _ep   = _host.AddServiceEndpoint(typeof(IWCFEntryPoint), new WebHttpBinding(), "");
            _stp  = _host.Description.Behaviors.Find <ServiceDebugBehavior>();
            _stp.HttpHelpPageEnabled = false;
            _host.Open();

            while (_host.State != CommunicationState.Opened)
            {
                Print.Info("Waiting for server to start up");
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 9
0
        public void Connect()
        {
            var host = new WebServiceHost(typeof(DemoService), new Uri
                                              ("http://localhost:30158/"));

            try {
                host.Open();
                var wc = new WebClient();
                wc.DownloadString("http://localhost:30158/testData");
                Console.WriteLine();
            } finally {
                host.Close();
            }
        }
        static void Main(string[] args)
        {
            Uri                  uri  = new Uri("http://localhost:8210");
            WebServiceHost       host = new WebServiceHost(typeof(HeroService), uri);
            ServiceEndpoint      ep   = host.AddServiceEndpoint(typeof(IHeroService), new WebHttpBinding(), "");
            ServiceDebugBehavior stp  = host.Description.Behaviors.Find <ServiceDebugBehavior>();

            stp.HttpHelpPageEnabled = false;
            host.Open();
            Console.WriteLine($"The service is up and running on {uri.AbsoluteUri}");
            Console.WriteLine("Press [Enter] to close the host.");
            Console.ReadLine();
            host.Close();
        }
Ejemplo n.º 11
0
    public static void Test()
    {
        string         baseAddress = "http://" + Environment.MachineName + ":8000/Service";
        WebServiceHost host        = new WebServiceHost(typeof(Service), new Uri(baseAddress));

        host.Open();
        Console.WriteLine("Host opened");
        WebClient c = new WebClient();

        Console.WriteLine(c.DownloadString(baseAddress + "/DoWork"));
        Console.Write("Press ENTER to close the host");
        Console.ReadLine();
        host.Close();
    }
Ejemplo n.º 12
0
        /// <summary>
        /// WebHttpBinding -- Transport -- Basic
        /// </summary>
        static void WebHttpBindingTransport()
        {
            string uri     = "https://localhost:44380/calcullator";
            string dnsName = "localhost";

            WebServiceHost host = new WebServiceHost(typeof(Calculator), new Uri(uri));

            //host.Authentication.AuthenticationSchemes = System.Net.AuthenticationSchemes.Basic;
            //host.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
            //host.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustomUserNamePasswordValidator();

            WebHttpBinding webHttpBinding = new WebHttpBinding();

            webHttpBinding.Security.Mode = WebHttpSecurityMode.Transport;
            webHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            host.AddServiceEndpoint(typeof(ICalculator), webHttpBinding, "").Behaviors.Add(new WebHttpBehavior());
            try
            {
                host.Open();
                Console.WriteLine("host open");

                EndpointAddress epAddress = new EndpointAddress(new Uri(uri), EndpointIdentity.CreateDnsIdentity(dnsName));

                ChannelFactory <ICalculator> factory = new ChannelFactory <ICalculator>(webHttpBinding, epAddress);
                factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
                //validate the certificate of server
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
                {
                    Console.WriteLine($"trust the server certificate: {certificate.Subject}");
                    return(true);
                };

                //factory.Credentials.UserName.UserName = "";
                //factory.Credentials.UserName.Password = "";
                factory.Credentials.Windows.ClientCredential = new NetworkCredential("", "", "");

                var proxy = factory.CreateChannel();

                var result = proxy.Add(2, 3);

                Console.WriteLine(result);

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 启动RESTFUL服务
        /// </summary>
        public void Start()
        {
            string def     = Debugger.IsAttached ? "http://localhost/shoperpdebug/" : "http://localhost/shoperp/";
            string hostUrl = LocalConfigService.GetValue(SystemNames.CONFIG_SERVER_ADDRESS, def);

            if (hostUrl == def)
            {
                LocalConfigService.UpdateValue(SystemNames.CONFIG_SERVER_ADDRESS, hostUrl);
            }
            var binding = new WebHttpBinding
            {
                Name           = "long_web_http_binding",
                AllowCookies   = true,
                SendTimeout    = new TimeSpan(0, 5, 0),
                CloseTimeout   = new TimeSpan(0, 1, 0),
                OpenTimeout    = new TimeSpan(0, 1, 0),
                ReceiveTimeout = new TimeSpan(0, 5, 0),
                ReaderQuotas   = new System.Xml.XmlDictionaryReaderQuotas {
                    MaxDepth = 16, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760, MaxStringContentLength = 10485760, MaxNameTableCharCount = 100
                },
                MaxBufferPoolSize      = 10485760,
                MaxBufferSize          = 10485760,
                MaxReceivedMessageSize = 10485760,
                Security = new WebHttpSecurity {
                    Mode = WebHttpSecurityMode.None
                },
            };

            Type[] types = Assembly.GetExecutingAssembly().GetTypes().Where(obj => obj.Namespace == "ShopErp.Server.Service.Restful").OrderBy(obj => obj.Name).ToArray();
            foreach (var v in types)
            {
                if (v.GetCustomAttribute <ServiceContractAttribute>() == null)
                {
                    continue;
                }

                var obj = Activator.CreateInstance(v);
                var s   = new WebServiceHost(obj, new Uri(hostUrl));
                ContractDescription cd = ContractDescription.GetContract(v);
                ServiceEndpoint     se = new ServiceEndpoint(cd, binding, new EndpointAddress(new Uri(hostUrl + v.Name.ToLower().Replace("restful", "").Replace("service", ""), UriKind.Absolute)));
                s.AddServiceEndpoint(se);
                s.Authorization.ServiceAuthorizationManager = this;
                service.Add(s);
                s.Open();
                foreach (var vv in s.Description.Endpoints)
                {
                    Console.WriteLine(vv.Address);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// To check service running: http://localhost:8000/EchoWithGet?value=Hello
        /// </summary>
        static void Main()
        {
            var host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));

            host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");

            host.Open();

            Console.WriteLine("Service is running");
            Console.WriteLine("Press enter to quit...");
            Console.ReadLine();

            host.Close();
        }
Ejemplo n.º 15
0
        private void StartLocationServiceApi(string host, string port)
        {
            string path = string.Format("http://{0}:{1}/LocationService/api", host, port);

            //LocationService demoServices = new LocationService();
            wcfApiHost = new WebServiceHost(typeof(LocationService));
            WebHttpBinding httpBinding = new WebHttpBinding();

            wcfApiHost.AddServiceEndpoint(typeof(ITestService), httpBinding, new Uri(path + "/test"));//不能是相同的地址,不同的地址的话可以有多个。
            //wcfApiHost.AddServiceEndpoint(typeof(IDevService), httpBinding, new Uri(path));
            wcfApiHost.AddServiceEndpoint(typeof(IPhysicalTopologyService), httpBinding, new Uri(path));
            wcfApiHost.Open();
            WriteLog("LocationService: " + path);
        }
Ejemplo n.º 16
0
        private static void Main(string[] args)
        {
            var            baseAddress = new Uri("http://bmrfservers.com:8080/Rustful");
            WebServiceHost serviceHost;
            //WSHttpBinding binding = new WSHttpBinding();
            //BasicHttpBinding binding = new BasicHttpBinding();
            var binding = new WebHttpBinding();

            binding.Security.Mode = WebHttpSecurityMode.None;
            serviceHost           = new WebServiceHost(typeof(RustService), baseAddress);

            //serviceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
            //serviceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CredentialValidator();
            //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            //ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            var whb   = new WebHttpBehavior();
            var debug = serviceHost.Description.Behaviors.Find <ServiceDebugBehavior>();

            // if not found - add behavior with setting turned on
            if (debug == null)
            {
                serviceHost.Description.Behaviors.Add(
                    new ServiceDebugBehavior {
                    IncludeExceptionDetailInFaults = true
                });
            }
            else
            {
                // make sure setting is turned ON
                if (!debug.IncludeExceptionDetailInFaults)
                {
                    debug.IncludeExceptionDetailInFaults = true;
                }
            }

            //whb.HttpGetEnabled = true;
            //whb.HttpsGetEnabled = true;
            //serviceHost.Description.Behaviors.Add(whb);

            serviceHost.Open();

            Console.WriteLine("The service is ready at {0}", baseAddress);
            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadLine();

            // Close the ServiceHost.
            serviceHost.Close();
        }
Ejemplo n.º 17
0
 public static void Main(string[] args)
 {
     WebServiceHost
     .Create <Startup>(args: args)
     .UseAutofac(Bootstrapper.LifeTimeScope)
     .UseRabbitMq(queueName: typeof(Program).Namespace)
     .SubscribeToCommand <AddPhotosToRemark>()
     .SubscribeToEvent <SignedUp>()
     .SubscribeToEvent <SignedIn>()
     .SubscribeToEvent <AccountActivated>()
     .SubscribeToEvent <UsernameChanged>()
     .SubscribeToEvent <AvatarUploaded>()
     .SubscribeToEvent <AvatarRemoved>()
     .SubscribeToEvent <RemarkCreated>()
     .SubscribeToEvent <RemarkDeleted>()
     .SubscribeToEvent <RemarkResolved>()
     .SubscribeToEvent <RemarkProcessed>()
     .SubscribeToEvent <RemarkRenewed>()
     .SubscribeToEvent <RemarkCanceled>()
     .SubscribeToEvent <RemarkEdited>()
     .SubscribeToEvent <PhotosToRemarkAdded>()
     .SubscribeToEvent <AddPhotosToRemarkRejected>()
     .SubscribeToEvent <PhotosFromRemarkRemoved>()
     .SubscribeToEvent <RemarkVoteSubmitted>()
     .SubscribeToEvent <RemarkVoteDeleted>()
     .SubscribeToEvent <CommentAddedToRemark>()
     .SubscribeToEvent <CommentEditedInRemark>()
     .SubscribeToEvent <CommentDeletedFromRemark>()
     .SubscribeToEvent <RemarkCommentVoteSubmitted>()
     .SubscribeToEvent <RemarkCommentVoteDeleted>()
     .SubscribeToEvent <FavoriteRemarkAdded>()
     .SubscribeToEvent <FavoriteRemarkDeleted>()
     .SubscribeToEvent <RemarkActionTaken>()
     .SubscribeToEvent <RemarkActionCanceled>()
     .SubscribeToEvent <RemarkReported>()
     .SubscribeToEvent <OperationCreated>()
     .SubscribeToEvent <OperationUpdated>()
     .SubscribeToEvent <RemarkStateDeleted>()
     .SubscribeToEvent <GroupCreated>()
     .SubscribeToEvent <OrganizationCreated>()
     .SubscribeToEvent <MemberAddedToGroup>()
     .SubscribeToEvent <MemberAddedToOrganization>()
     .SubscribeToEvent <AccountDeleted>()
     .SubscribeToEvent <AccountLocked>()
     .SubscribeToEvent <AccountUnlocked>()
     .SubscribeToEvent <UserNotificationSettingsUpdated>()
     .Build()
     .Run();
 }
Ejemplo n.º 18
0
        private static void Main(string[] args)
        {
            var service        = new ExampleRestService();
            var baseAddresses  = new Uri("http://127.0.0.1:8880/ws");
            var webServiceHost = new WebServiceHost(service, baseAddresses);

            try
            {
                webServiceHost.Open();
                Console.WriteLine("Service started (" + baseAddresses + ").");
                Console.WriteLine("Press 'b' to copy base URL to clipboard.");
                Console.WriteLine("Press 'r' to copy Report URL to clipboard.");
                Console.WriteLine("Press 'a' to copy Authenticate URL to clipboard.");
                Console.WriteLine("Press any other key to exit...");

                bool wait;
                do
                {
                    wait = false;
                    switch (Char.ToLower(Console.ReadKey().KeyChar))
                    {
                    case 'b':
                        ClipboardSetText(baseAddresses.ToString());
                        Console.WriteLine();
                        Console.WriteLine("Base URL copied.");
                        wait = true;
                        break;

                    case 'r':
                        ClipboardSetText(baseAddresses + UriTemplates.GetReport);
                        Console.WriteLine();
                        Console.WriteLine("Report URL copied.");
                        wait = true;
                        break;

                    case 'a':
                        ClipboardSetText(baseAddresses + UriTemplates.Authenticate);
                        Console.WriteLine();
                        Console.WriteLine("Authenticate URL copied.");
                        wait = true;
                        break;
                    }
                } while (wait);
            }
            finally
            {
                webServiceHost.Close();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            OwnTypes();
            try
            {
                this.Log.Info("Starting Rest Interface");

                bool showHelp = bool.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Show Help").Value);
                int  restPort = 8732;

                if (!OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Id.Equals(String.Empty))
                {
                    try
                    {
                        restPort = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Value);
                        Log.Info("Rest Port read in as: " + restPort);
                    }
                    catch (FormatException ex)
                    { Log.Error("Error pulling REST port from property (not a valid number)", ex); }
                    catch (OverflowException ex)
                    { Log.Error("Error pulling REST port from property (too large)", ex); }
                    catch (ArgumentNullException ex)
                    { Log.Error("Error pulling REST port from property (null)", ex); }
                }

                String restUrl = "http://localhost:" + restPort.ToString() + "/api";
                serviceHost = new WebServiceHost(typeof(OSAERest.api), new Uri(restUrl));

                WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.None);
                binding.CrossDomainScriptAccessEnabled = true;
                var endpoint = serviceHost.AddServiceEndpoint(typeof(IRestService), binding, "");

                ServiceDebugBehavior sdb = serviceHost.Description.Behaviors.Find <ServiceDebugBehavior>();
                sdb.HttpHelpPageEnabled = false;
                if (showHelp)
                {
                    serviceHost.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior {
                        HelpEnabled = true
                    });
                }

                Log.Info("Starting RESTful Interface");
                serviceHost.Open();
            }
            catch (Exception ex)
            { Log.Error("Error starting RESTful web service", ex); }
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8080/Blog");

            WebServiceHost myHost = new WebServiceHost(typeof(BlogService), baseAddress);

            Console.WriteLine("Starting Service");
            myHost.Open();

            Console.WriteLine("The service is ready at {0}", baseAddress);
            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadLine();

            myHost.Close();
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            WebServiceHost  webHost = new WebServiceHost(typeof(cl_svc_http), new Uri("http://localhost:8088/"));
            ServiceEndpoint ep      = webHost.AddServiceEndpoint(typeof(IServiceContractHttp), new WebHttpBinding(), "HTTP");

            webHost.Open();

            ServiceHost svch = new ServiceHost(typeof(cl_svc), new Uri("net.tcp://localhost/"));

            svch.AddServiceEndpoint(typeof(IServiceContract), new NetTcpBinding(), "SERVICES");
            svch.Open();

            Console.WriteLine("Press <ENTER> to escape");
            Console.Read();
        }
Ejemplo n.º 22
0
        public void RunServiceHost()
        {
            try
            {
                Uri baseAddress = new Uri("http://127.0.0.1:8000/");
                svcHost = new WebServiceHost(typeof(Command), baseAddress);

                svcHost.Open();
                Console.WriteLine("svcHost.Open");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 23
0
        public void Connect()
        {
            var url  = "http://" + NetworkHelpers.LocalEphemeralEndPoint().ToString();
            var host = new WebServiceHost(typeof(DemoService), new Uri
                                              (url));

            try {
                host.Open();
                var wc = new WebClient();
                wc.DownloadString(url + "/testData");
                Console.WriteLine();
            } finally {
                host.Close();
            }
        }
Ejemplo n.º 24
0
        } // OnStart()

        //---------------------------------------------------------------------------------------------
        protected override void OnStop()
        {
            try
            {
                Logger.Log("Closing service");
            }
            finally
            {
                // Free the resources
                baseAddress = null;
                host.Close();
                host = null;
                cf   = null;
            }
        }
Ejemplo n.º 25
0
        private void Form1_Load(object sender, EventArgs e)
        {
            RESTServices service = new RESTServices();

            serviceHost = new WebServiceHost(service, new Uri("http://localhost:8000/"));
            serviceHost.Open();

            m_yuanta_ord = new YuantaOrdClass();

            m_yuanta_ord.OnLogonS += new _DYuantaOrdEvents_OnLogonSEventHandler(m_yuanta_ord_OnLogonS);

            m_yuanta_ord.OnUserDefinsFuncResult += new _DYuantaOrdEvents_OnUserDefinsFuncResultEventHandler(m_yuanta_ord_OnUserDefinsFuncResult);

            int ret_code = m_yuanta_ord.SetFutOrdConnection("", "", "api.yuantafutures.com.tw", int.Parse("80"));
        }
Ejemplo n.º 26
0
 private void OpenServices()
 {
     SystemManagerHost = new WebServiceHost(typeof(SystemManager));
     SystemManagerHost.Open();
     BillServiceHost = new WebServiceHost(typeof(BillService));
     BillServiceHost.Open();
     FileServiceHost = new WebServiceHost(typeof(FileTransferService));
     FileServiceHost.Open();
     SystemServiceHost = new WebServiceHost(typeof(SystemService));
     SystemServiceHost.Open();
     //IndexServiceHost = new WebServiceHost(typeof(AxIndexer));
     //IndexServiceHost.Open();
     _WsServiceHost = new WebServiceHost(typeof(WsService));
     _WsServiceHost.Open();
 }
Ejemplo n.º 27
0
        public void ServiceDebugBehaviorTest()
        {
            var             host    = new WebServiceHost(typeof(MyService), new Uri("http://" + NetworkHelpers.LocalEphemeralEndPoint().ToString()));
            ServiceEndpoint webHttp = host.AddServiceEndpoint("MonoTests.System.ServiceModel.Web.WebServiceHostTest+MyService", new WebHttpBinding(), "WebHttpBinding");

            Assert.AreEqual(true, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageEnabled, "HttpHelpPageEnabled #1");
            Assert.AreEqual(true, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpsHelpPageEnabled, "HttpsHelpPageEnabled #1");

            host.Open();

            Assert.AreEqual(false, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageEnabled, "HttpHelpPageEnabled #2");
            Assert.AreEqual(false, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpsHelpPageEnabled, "HttpsHelpPageEnabled #2");

            host.Close();
        }
Ejemplo n.º 28
0
        private void start_Click(object sender, EventArgs e)
        {
            start.Enabled = false;

            message.Text = "Starting";

            var service = new TodoService(this.message);

            _webServiceHost = new WebServiceHost(service, new Uri(_hostAddress));
            _webServiceHost.Open();

            message.Text = "Started";

            stop.Enabled = true;
        }
Ejemplo n.º 29
0
        public ServiceHost(ILog log, IStatusMonitor statusMonitor)
        {
            Log           = log;
            StatusMonitor = statusMonitor;
            _host         = new WebServiceHost(typeof(Service), ServiceUri);
            // TODO: Enable HTTPS - http://stackoverflow.com/questions/14933696
            _host.AddDefaultEndpoints()[0].Binding = new WebHttpBinding();
            _host.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior {
                HelpEnabled = true
            });

            _webAppHost = new WebServiceHost(typeof(WebServer), WebAppUri);
            _webAppHost.AddDefaultEndpoints()[0].Binding = new WebHttpBinding();
            _webAppHost.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior());
        }
Ejemplo n.º 30
0
 public static void Main(string[] args)
 {
     try
     {
         WebServiceHost host = new WebServiceHost(typeof(AutoService));
         host.Open();
         Console.WriteLine("Hit any key to exit...");
         Console.ReadKey();
         host.Close();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            var             host = new WebServiceHost(typeof(Service1), new Uri("http://localhost:8000"));
            ServiceEndpoint ep   = host.AddServiceEndpoint(typeof(IService1), new WebHttpBinding(), "Test");

            ServiceDebugBehavior sdb = host.Description.Behaviors.Find <ServiceDebugBehavior>();

            sdb.HttpHelpPageEnabled = false;

            host.Open();
            Console.WriteLine("Service is running");
            Console.WriteLine("Press enter to quit...");
            Console.ReadLine();
            host.Close();
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            string uriBaseAddress = args[0];
            string waitHandleName = null;
            if(args.Length > 1)
                 waitHandleName = args[1];

            Uri[] uriArray = { new Uri(uriBaseAddress) };

            Type serviceType = Assembly.GetExecutingAssembly().GetTypes().Single(t => !t.IsAbstract && typeof(Microsoft.OData.Service.IRequestHandler).IsAssignableFrom(t));

            using(WebServiceHost host = new WebServiceHost(serviceType, uriArray))
            {
                try
                {    
                    host.Open();
                    if(waitHandleName == "Debug" || string.IsNullOrEmpty(waitHandleName)) 
                    { 
                        Console.WriteLine("Running in Debug mode , please press any key to exit");
                        Console.Read();
                    }
                    else
                    {
                        EventWaitHandle waitHandle = EventWaitHandle.OpenExisting(waitHandleName);
                        waitHandle.WaitOne();
                    }
                    host.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An exception occurred:");
                    Console.WriteLine(ex.ToString());
                    host.Abort();
                    Console.ReadLine();
                }
            }
        }
Ejemplo n.º 33
0
        public int StartProcess()
        {
            int result = 1;
              #region Pobranie i walidacja konfiguracji procesu

              ITNWebServiceCfgNode config = ITNWebServiceCfgHelper.GetITNWebServiceCfg(core.ProcessConfigurationXml);

              if (String.IsNullOrEmpty(config.endpointAddress.Trim()))
            throw new Exception("Processing canceled - endpoint address empty.");

              #endregion Pobranie i walidacja konfiguracji procesu
              SqlDatabase dbPTRConfig = null;
              TaskInserter.core = core;
              TaskInserter.dbPTRConfig = ConverterUtils.GetDBConfig(core);
              TaskInserter.taskId = config.graphBeginNodeId;
              TaskInserter.runningTaskId = TaskInserter.lastRunningTaskId = ConverterUtils.GetRunningTaskId(core);
              TaskInserter.connectionString = ConverterUtils.GetDBConvertersConnectionString(core);
              if(config.longTimer<= config.shortTimer)
              {
            throw new Exception("Processing canceled - maximum delay is shorter than task delay.");
              }
              else if(config.shortTimer == 0)
              {
            throw new Exception("Processing canceled - delay cannot be zero.");
              }
              else if (config.longTimer == 0)
              {
            throw new Exception("Processing canceled - maximum delay cannot be zero.");
              }
              TaskInserter.shortTimer = new PtrTimer(TaskInserter.ShortTimerHandler, config.shortTimer * 1000);
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Task delay {0} seconds.", config.shortTimer);
              TaskInserter.longTimer = new PtrTimer(TaskInserter.LongTimerHandler, config.longTimer * 1000);
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Maximum delay {0} seconds.", config.longTimer);

              try
              {
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Start processing");

            PTR3Core.DB_POOL.InitMSSqlPool(core, "database-converters");

            String endpointAddress = config.endpointAddress;
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Endpoint address is {0}", config.endpointAddress);
            //endpointAddress = "http://localhost/ITNWebService"; //odkomentować przy testowaniu na lokalnym hoście
            string singleWsdl = ConfigXmlReader.XmlGetConfigParam(core, "single-wsdl");
            if (String.IsNullOrEmpty(singleWsdl))
              singleWsdl = ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "single-wsdl");

            string locationWsdl = ConfigXmlReader.XmlGetConfigParam(core, "location-wsdl");
            if (String.IsNullOrEmpty(locationWsdl))
              locationWsdl = ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "location-wsdl");

            Uri uri = new Uri(endpointAddress);

            if (uri.Scheme != "http")
            {
              throw new Exception("Endpoint address has wrong schema: " + uri.Scheme);
            }

            int start = Environment.TickCount;
            int i = 0;
            bool bWorking = true;

            WebServiceHost<ITNWebServiceContract> host = new WebServiceHost<ITNWebServiceContract>(endpointAddress);
            host.EnableMetadataExchange(true);
            ServiceEndpoint endpoint = host.AddServiceHttpEndpoint((Type)typeof(IITNWebServiceContract), "");
            if (singleWsdl == "1" || !String.IsNullOrEmpty(locationWsdl))
              endpoint.Behaviors.Add(new WCFExtras.Wsdl.WsdlExtensions(null
            , String.IsNullOrEmpty(locationWsdl) ? null : new Uri(locationWsdl)
            , singleWsdl == "1"));
            ServiceDebugBehavior behavior =
              host.Description.Behaviors.Find<ServiceDebugBehavior>();

            if(behavior != null)
            {
              behavior.IncludeExceptionDetailInFaults = true;
            }
            else
            {
              host.Description.Behaviors.Add(
              new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
            }
            host.Open();
            Thread.Sleep(500);
            if (dbPTRConfig == null)
              dbPTRConfig = ConverterUtils.GetDBConfig(core);
            while (PTR3Wrapper.ShouldClose() == 0 && PTR3Wrapper.ShouldSuspend() == 0 && host.State == CommunicationState.Opened && bWorking)
            {
              if ((i++ % 50) == 0)
              {
            //PTR3Core.LOG.Log(MsgStatusEnum.MS_Deb3, "Online wait processing...");

            bWorking = host.HeartBeat();
              }
              Thread.Sleep(100);
            }
            host.Close();
            Thread.Sleep(500);
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Finish processing");
              }
              catch (Exception ex)
              {
            result = 0;
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Error, ex, "");
              }

              return result;
        }