當前位置: 首頁>>代碼示例>>C#>>正文


C# Web.WebServiceHost類代碼示例

本文整理匯總了C#中System.ServiceModel.Web.WebServiceHost的典型用法代碼示例。如果您正苦於以下問題:C# WebServiceHost類的具體用法?C# WebServiceHost怎麽用?C# WebServiceHost使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebServiceHost類屬於System.ServiceModel.Web命名空間,在下文中一共展示了WebServiceHost類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: _init

        protected int _init()
        {
            try
            {
                this._baseAddress = new Uri(this._configuration.Address);
                this._baseHost = new WebServiceHost(this._serverPrimaryType, this._baseAddress);                

                this._metadataBehaviour = new ServiceMetadataBehavior();
                this._metadataBehaviour.HttpGetEnabled = true;
                this._metadataBehaviour.HttpGetUrl = this._baseAddress;
                this._baseHost.Description.Behaviors.Add(this._metadataBehaviour);                

                this._basicBinding = new BasicHttpBinding();
                this._basicBinding.MaxBufferPoolSize = Int32.MaxValue;
                this._basicBinding.MaxReceivedMessageSize = Int32.MaxValue;
                this._basicBinding.MaxBufferSize = Int32.MaxValue;
                this._basicBinding.TransferMode = TransferMode.Streamed;
                this._basicBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                this._basicBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                this._basicBinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                this._basicBinding.ReaderQuotas.MaxDepth = 32;
                this._basicBinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;

                if (this._allowWebRequests)
                {
                    this._webBehaviour = new WebHttpBehavior();

                    this._webBinding = new WebHttpBinding();
                    this._webBinding.MaxBufferPoolSize = Int32.MaxValue;
                    this._webBinding.MaxReceivedMessageSize = Int32.MaxValue;
                    this._webBinding.MaxBufferSize = Int32.MaxValue;
                    this._webBinding.TransferMode = TransferMode.Streamed;
                    this._webBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                    this._webBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                    this._webBinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                    this._webBinding.ReaderQuotas.MaxDepth = 32;
                    this._webBinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
                }
            }
            catch (Exception ex)
            { 
                return -2;
            }

            try
            {
                this._baseHost.AddServiceEndpoint(this._serverInterfaceType, this._basicBinding, this._configuration.Address);
                if (this._allowWebRequests)
                {                                        
                    var Endpoint = this._baseHost.AddServiceEndpoint(_serverInterfaceType, this._webBinding, "Web");
                    Endpoint.Behaviors.Add(this._webBehaviour);
                }
            }
            catch (Exception ex)
            { 
                return -2;
            }

            return -1;
        }
開發者ID:cMenu,項目名稱:cMenu.Server,代碼行數:60,代碼來源:CCommunicationServer.cs

示例2: OnStart

        protected override void OnStart(string[] args)
        {
            var sn = "Facturador Fiscal Winks Hotel";

            try
            {
                Uri baseAddress = new Uri(ConfigurationManager.AppSettings["BaseAddress"]);

                var webHost = new WebServiceHost(typeof(ServiceSelector), baseAddress);
                var endpoint = webHost.AddServiceEndpoint(typeof(IServiceSelector), new WebHttpBinding(WebHttpSecurityMode.None), baseAddress);
                //add support for cors (both for the endpoint to detect and create reply)
                endpoint.Behaviors.Add(new CorsBehaviorAttribute());

                foreach (var operation in endpoint.Contract.Operations)
                {
                    //add support for cors (and for operation to be able to not
                    //invoke the operation if we have a preflight cors request)
                    operation.Behaviors.Add(new CorsBehaviorAttribute());
                }

                webHost.Open();
            }
            catch (Exception ex)
            {
                if (!EventLog.SourceExists(sn))
                    EventLog.CreateEventSource(sn, "Application");

                EventLog.WriteEntry(sn, ex.Message, EventLogEntryType.Error);
            }
        }
開發者ID:nescalante,項目名稱:taxbillerservice,代碼行數:30,代碼來源:BillingService.cs

示例3: Main

        static void Main(string[] args)
        {
            WebServiceHost webServiceHost = new WebServiceHost(typeof(PartyService.Service));

            WebHttpBinding serviceBinding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
            serviceBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            ServiceEndpoint ep = webServiceHost.AddServiceEndpoint(
                typeof(PartyService.IService),
                serviceBinding,
                "http://localhost:8000/service");
            ep.Behaviors.Add(new PartyService.ProcessorBehaviour());

            WebHttpBinding staticBinding = new WebHttpBinding(WebHttpSecurityMode.None);
            ServiceEndpoint sep = webServiceHost.AddServiceEndpoint(
                typeof(PartyService.IStaticItemService),
                new WebHttpBinding(),
                "http://localhost:8000");

            webServiceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
            webServiceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new PartyService.Validator();
            webServiceHost.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;

            webServiceHost.Open();
            Console.WriteLine("Service is running - press enter to quit");
            Console.ReadLine();
            webServiceHost.Close();
            Console.WriteLine("Service stopped");
        }
開發者ID:offspin,項目名稱:building_blocks,代碼行數:28,代碼來源:Program.cs

示例4: OnStart

 protected override void OnStart(string[] args)
 {
     var host = new WebServiceHost(new NancyWcfGenericService(),
                       new Uri("http://localhost:1234/base/"));
      host.AddServiceEndpoint(typeof(NancyWcfGenericService), new WebHttpBinding(), "");
      host.Open();
 }
開發者ID:nickgodsland,項目名稱:ContinuousDeployment-TechTalk,代碼行數:7,代碼來源:Service1.cs

示例5: Run

        public async Task Run(string hostName, string listenToken)
        {
            string httpAddress = new UriBuilder("http", hostName, -1, "svc").ToString();
            using (var host = new WebServiceHost(GetType()))
            {
                host.AddServiceEndpoint(
                    GetType(),
                    new WebHttpRelayBinding(
                        EndToEndWebHttpSecurityMode.None,
                        RelayClientAuthenticationType.None) {IsDynamic = true},
                    httpAddress)
                    .EndpointBehaviors.Add(
                        new TransportClientEndpointBehavior(
                            TokenProvider.CreateSharedAccessSignatureTokenProvider(listenToken)));

                host.Open();

                Console.WriteLine("Starting a browser to see the image: ");
                Console.WriteLine(httpAddress + "/Image");
                Console.WriteLine();
                // launching the browser
                System.Diagnostics.Process.Start(httpAddress + "/Image");
                Console.WriteLine("Press [Enter] to exit");
                Console.ReadLine();

                host.Close();
            }
        }
開發者ID:lokeshsp,項目名稱:azure-servicebus-relay-samples,代碼行數:28,代碼來源:Program.cs

示例6: Main

		static void Main (string[] args) {
			LegoRestService DemoServices = new LegoRestService ();
			WebServiceHost _serviceHost = new WebServiceHost (DemoServices, new Uri ("http://localhost:8000/DEMOService"));
			_serviceHost.Open ();
			Console.ReadKey ();
			_serviceHost.Close ();
		}
開發者ID:ubuntuuser,項目名稱:LegoRestService,代碼行數:7,代碼來源:LegoRestService.cs

示例7: RunInterface

        /// <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;

            try
            {
                this.Log.Info("Starting Rest Interface");

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

                serviceHost = new WebServiceHost(typeof(OSAERest.api), new Uri("http://localhost:8732/api"));
                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 });
                }

                this.Log.Info("Starting Rest Interface");
                serviceHost.Open();
            }
            catch (Exception ex)
            {
                this.Log.Error("Error starting RESTful web service", ex);
            }
        }
開發者ID:matthewste,項目名稱:Open-Source-Automation,代碼行數:36,代碼來源:Rest.cs

示例8: QueryServiceHost

 public QueryServiceHost(Uri address, object service)
 {
     host = new WebServiceHost(service);
     host.AddServiceEndpoint(typeof(IQueryService), new WebHttpBinding(), address);
     WebHttpBehavior behavior = new WebHttpBehavior();
     host.Description.Endpoints[0].Behaviors.Add(behavior);
 }
開發者ID:AlexZeitler,項目名稱:WcfHttpMvcFormsAuth,代碼行數:7,代碼來源:QueryServiceHost.cs

示例9: Main

        static void Main(string[] args)
        {
            ItemCounter counter = new ItemCounter();

            using (WebServiceHost host = new WebServiceHost(new StreamingFeedService(counter), new Uri("http://localhost:8000/Service")))
            {
                WebHttpBinding binding = new WebHttpBinding();

                binding.TransferMode = TransferMode.StreamedResponse;
                host.AddServiceEndpoint(typeof(IStreamingFeedService), binding, "Feeds");

                host.Open();

                XmlReader reader = XmlReader.Create("http://localhost:8000/Service/Feeds/StreamedFeed");
                StreamedAtom10FeedFormatter formatter = new StreamedAtom10FeedFormatter(counter);

                Console.WriteLine("Reading stream from server");

                formatter.ReadFrom(reader);
                SyndicationFeed feed = formatter.Feed;

                foreach (SyndicationItem item in feed.Items)
                {
                    //This sample is implemented such that the server will generate an infinite stream of items;
                    //it only stops after the client reads 10 items
                    counter.Increment();
                }

                Console.WriteLine("CLIENT: read total of {0} items", counter.GetCount());
                Console.WriteLine("Press any key to terminate");
                Console.ReadLine();
            }
        }
開發者ID:ssickles,項目名稱:archive,代碼行數:33,代碼來源:Program.cs

示例10: Start

        public void Start(string[] args)
        {
            HomeModule.Container = AppContext.Container;
            PackagesModule.Container = AppContext.Container;
            InstallationsModule.Container = AppContext.Container;
            LogModule.Container = AppContext.Container;
            ActionsModule.Container = AppContext.Container;
            ConfigurationModule.Container = AppContext.Container;

            Nancy.Json.JsonSettings.MaxJsonLength = 1024*1024*5; // 5mb max

            try
            {
                WebUiAddress = new Uri("http://localhost:9999/");
                _host = new WebServiceHost(new NancyWcfGenericService(), WebUiAddress);
                _host.AddServiceEndpoint(typeof (NancyWcfGenericService), new WebHttpBinding(), "");
                _host.Open();
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex, "could not start listening");
            }

            _logger.Info("Hosting Web interface on: " + WebUiAddress);
        }
開發者ID:andrewmyhre,項目名稱:DeployD,代碼行數:25,代碼來源:ManagementInterfaceHost.cs

示例11: Main

 static void Main(string[] args)
 {
     WebServiceHost host=new WebServiceHost(typeof(OperatingSystemService),new Uri("http://localhost:8013/RESTWebservice/"));
     host.Open();
     Console.ReadKey();
     host.Close();
 }
開發者ID:m-karimi,項目名稱:Code-Samples,代碼行數:7,代碼來源:Program.cs

示例12: StartWebHTTPService

        // WebHttpBinding, REST based
        /**
         * If you do not add an endpoint, WebServiceHost automatically creates a default endpoint. WebServiceHost also adds WebHttpBehavior and disables the HTTP Help page and the Web Services Description Language (WSDL) GET functionality so the metadata endpoint does not interfere with the default HTTP endpoint.
         * Adding a non-SOAP endpoint with a URL of "" causes unexpected behavior when an attempt is made to call an operation on the endpoint. The reason for this is the listen URI of the endpoint is the same as the URI for the help page (the page that is displayed when you browse to the base address of a WCF service).
         *
         *
         * */
        private static void StartWebHTTPService()
        {
            string strAdr = "http://localhost" + "/MathService";
            WebServiceHost webServiceHost;
            try
            {
                Uri adrbase = new Uri(strAdr);

                webServiceHost = new WebServiceHost(typeof(MathService), adrbase);

                //To disable help page to avoid interference with normal http get

                ServiceDebugBehavior sdb = webServiceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
                sdb.HttpHelpPageEnabled = false;

                WebHttpBinding webHttpBinding = new WebHttpBinding();
                webServiceHost.AddServiceEndpoint(typeof(IMathService), webHttpBinding, "");
                webServiceHost.Open();
                Console.WriteLine("\n\nService on WebHttpBinding is Running as >> " + strAdr);

            }
            catch (Exception eX)
            {
                webServiceHost = null;
                Console.WriteLine("Service can not be started as >> [" +
                  strAdr + "] \n\nError Message [" + eX.Message + "]");
            }
        }
開發者ID:cleancodenz,項目名稱:MVC4DEV,代碼行數:35,代碼來源:Program.cs

示例13: StartWebService

 public void StartWebService()
 {
     //BasicConfigurator.Configure( new PatternLayout("%d [%t] %-5p %c %m%n"), @".\test.txt");
     RestDemoServices DemoServices = new RestDemoServices();
     WebServiceHost _serviceHost = new WebServiceHost(DemoServices, new Uri(URL));
     _serviceHost.Open();
 }
開發者ID:Masterwow3,項目名稱:PAWebService,代碼行數:7,代碼來源:WebService.cs

示例14: Start

        private static void Start(string[] args)
        {
            WebServicesImplementation PureCloudServices = new WebServicesImplementation();
            WebServiceHost _serviceHost = new WebServiceHost(PureCloudServices, new Uri(PureCloudServices.URL));

            _serviceHost.Open();
        }
開發者ID:MyPureCloud,項目名稱:BridgeServerSqlRestConnector,代碼行數:7,代碼來源:Program.cs

示例15: GetTodosFiltered

        public void GetTodosFiltered()
        {
            using (var server = new WebServiceHost(new TodoService(), new Uri(_hostAddress)))
            using (var client = new WebChannelFactory<ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
            {
                server.Open();
                client.Open();
                var channel = client.CreateChannel();

                using (new OperationContextScope((IContextChannel)channel))
                {
                    var todos = channel.GetTodosFiltered(true);
                    ValidateHttpStatusResponse(HttpStatusCode.OK);

                    Assert.AreEqual(1, todos.Todo.Length);
                }

                using (new OperationContextScope((IContextChannel)channel))
                {
                    var todos = channel.GetTodosFiltered(false);
                    ValidateHttpStatusResponse(HttpStatusCode.OK);

                    Assert.AreEqual(2, todos.Todo.Length);
                }
            }
        }
開發者ID:Xtremrules,項目名稱:dot42,代碼行數:26,代碼來源:UnitTests.cs


注:本文中的System.ServiceModel.Web.WebServiceHost類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。