Exemple #1
0
        private void _load_web_host()
        {
            Uri _web_http_url = new Uri(
                System.Configuration.ConfigurationManager.AppSettings["Web_HTTP_Url"]);

            _web_service_host = new System.ServiceModel.Web.WebServiceHost(wcf_service, _web_http_url);
            //Añadimos endpoint web
            System.ServiceModel.Description.ServiceEndpoint epoint =
                _web_service_host.AddServiceEndpoint(_service_interface, new System.ServiceModel.WebHttpBinding(), _web_http_url);

            //Vamos a añadir la carateristica de autoformato en response
            System.ServiceModel.Description.WebHttpBehavior wbhttp =
                epoint.Behaviors.Find <System.ServiceModel.Description.WebHttpBehavior>();

            if (wbhttp != null)
            {
                wbhttp.AutomaticFormatSelectionEnabled = true;
                wbhttp.HelpEnabled = true;
            }
            else
            {
                wbhttp = new System.ServiceModel.Description.WebHttpBehavior();
                wbhttp.AutomaticFormatSelectionEnabled = true;
                wbhttp.HelpEnabled           = true;
                wbhttp.FaultExceptionEnabled = true;
                epoint.Behaviors.Add(wbhttp);
            }
        }
Exemple #2
0
 public void OpenHost()
 {
     try
     {
         //WebHttpBinding
         WebHttpBinding webBinding = new WebHttpBinding();
         webBinding.MaxBufferPoolSize = int.MaxValue;
         webBinding.MaxReceivedMessageSize = int.MaxValue;
         webBinding.Security.Mode = WebHttpSecurityMode.None;
         webBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
         //NetTcpBinding
         NetTcpBinding tcpBinding = new NetTcpBinding();
         tcpBinding.MaxBufferPoolSize = int.MaxValue;
         tcpBinding.MaxReceivedMessageSize = int.MaxValue;
         tcpBinding.Security.Mode = SecurityMode.None;
         tcpBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
         //ServiceBehavior
         ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
         smb.HttpsGetEnabled = false;
         smb.HttpGetEnabled = true;
         _host.Description.Behaviors.Add(smb);
         ServiceDebugBehavior sdb = _host.Description.Behaviors.Find<ServiceDebugBehavior>();
         sdb.HttpHelpPageEnabled = Globals.IsDebugMode;
         sdb.HttpsHelpPageEnabled = Globals.IsDebugMode;
         sdb.IncludeExceptionDetailInFaults = Globals.IsDebugMode;
         UseRequestHeadersForMetadataAddressBehavior urhfmab = new UseRequestHeadersForMetadataAddressBehavior();
         _host.Description.Behaviors.Add(urhfmab);
         //MEX endpoint
         _host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
         if (Globals.UseClientTcpHost && Globals.UseClientHttpHost)
         {
             _host.AddServiceEndpoint(typeof(IService), tcpBinding, _tcpBaseAddress);
             _host.AddServiceEndpoint(typeof(IService), webBinding, _httpBaseAddress);
             _host.Description.Endpoints[2].Contract = CopyContract(_host.Description.Endpoints[1].Contract);
         } 
         else if (Globals.UseClientTcpHost)
         {
             _host.AddServiceEndpoint(typeof(IService), tcpBinding, _tcpBaseAddress);
         }
         else if (Globals.UseClientHttpHost)
         {
             _host.AddServiceEndpoint(typeof(IService), webBinding, _httpBaseAddress);
             _host.Description.Endpoints[1].Contract = CopyContract(_host.Description.Endpoints[1].Contract);
         }
         _host.Open();
         IsOpen = true;
        private void _load_web_host()
        {
            Uri _web_http_url = new Uri(
                System.Configuration.ConfigurationManager.AppSettings["Web_HTTP_Url"]);
            _web_service_host = new System.ServiceModel.Web.WebServiceHost(wcf_service, _web_http_url);
            //Añadimos endpoint web
            System.ServiceModel.Description.ServiceEndpoint epoint =
                _web_service_host.AddServiceEndpoint(_service_interface, new System.ServiceModel.WebHttpBinding(), _web_http_url);

            //Vamos a añadir la carateristica de autoformato en response
            System.ServiceModel.Description.WebHttpBehavior wbhttp =
                epoint.Behaviors.Find<System.ServiceModel.Description.WebHttpBehavior>();

            if (wbhttp != null)
            {
                wbhttp.AutomaticFormatSelectionEnabled = true;
                wbhttp.HelpEnabled = true;
            }
            else
            {
                wbhttp = new System.ServiceModel.Description.WebHttpBehavior();
                wbhttp.AutomaticFormatSelectionEnabled = true;
                wbhttp.HelpEnabled = true;
                wbhttp.FaultExceptionEnabled = true;
                epoint.Behaviors.Add(wbhttp);

            }
        }