/// <summary> /// /// </summary> /// <param name="description"></param> private void AddDefaultBehaviors(ServiceDescription description) { #region ServiceMetadataBehavior if (_containMeta) { var behavior = description.Behaviors.Find <ServiceMetadataBehavior>(); if (behavior == null) { behavior = new ServiceMetadataBehavior(); description.Behaviors.Add(behavior); } behavior.HttpGetEnabled = true; } #endregion #region ServiceDebugBehavior if (_includeExceptionDetailInFaults) { var serviceDebug = description.Behaviors.Find <ServiceDebugBehavior>(); if (serviceDebug == null) { serviceDebug = new ServiceDebugBehavior(); description.Behaviors.Add(serviceDebug); } serviceDebug.IncludeExceptionDetailInFaults = true; } #endregion }
static void Main(string[] args) { var host = new ServiceHost(typeof(Server.Server), new Uri[] { new Uri("http://localhost:8081") }); ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(Server.IServer), new WebHttpBinding(), "web"); endpoint.EndpointBehaviors.Add(new WebHttpBehavior()); ServiceDebugBehavior sdb = host.Description.Behaviors.Find <ServiceDebugBehavior>(); sdb.HttpHelpPageEnabled = false; //var b = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); //if (b == null) b = new ServiceMetadataBehavior(); //host.Description.Behaviors.Add(b); //host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); host.Open(); Console.WriteLine("Server HTTP is running ..."); Console.ReadLine(); host.Close(); }
private void AddDefaultServiceBehaviors() { ModuleProc PROC = new ModuleProc("ExOneServiceHost", "AddDefaultServiceBehaviors"); try { // ServiceMetadataBehavior _serviceMetadata = this.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (_serviceMetadata == null) { _serviceMetadata = new ServiceMetadataBehavior(); this.Description.Behaviors.Add(_serviceMetadata); } _serviceMetadata.HttpGetEnabled = false; //bServiceMetadata.HttpGetUrl = uriHttp; // ServiceDebugBehavior ServiceDebugBehavior bServiceDebug = this.Description.Behaviors.Find <ServiceDebugBehavior>(); if (bServiceDebug == null) { bServiceDebug = new ServiceDebugBehavior(); this.Description.Behaviors.Add(bServiceDebug); } bServiceDebug.IncludeExceptionDetailInFaults = false; } catch (Exception ex) { Log.Exception(PROC, ex); } }
static void PokreniService(System.ServiceModel.ServiceHost host, string nazivServisa) { #if DEBUG ServiceDebugBehavior debug = host.Description.Behaviors.Find <ServiceDebugBehavior>(); if (debug == null) { host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { if (!debug.IncludeExceptionDetailInFaults) { debug.IncludeExceptionDetailInFaults = true; } } #endif host.Open(); System.Console.WriteLine("Pokrenut {0}", nazivServisa); foreach (var endpoint in host.Description.Endpoints) { System.Console.WriteLine(""); System.Console.WriteLine("Endpoint:"); System.Console.WriteLine("Adresa: {0}", endpoint.Address.Uri); System.Console.WriteLine("Binding: {0}", endpoint.Binding.Name); System.Console.WriteLine("Contract: {0}", endpoint.Contract.Name); System.Console.WriteLine(""); } }
/// <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); } }
static void Main(string[] args) { Uri baseAddress = new Uri("net.tcp://localhost:9002/CalculatorService/" + Guid.NewGuid().ToString()); Uri announcementEndpointAddress = new Uri("net.tcp://localhost:9021/Announcement"); //create service host ServiceHost host = new ServiceHost(typeof(CalculatorService), baseAddress); ServiceDebugBehavior sdb = host.Description.Behaviors.Find <ServiceDebugBehavior>(); if (sdb == null) { host.Description.Behaviors.Add( new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { if (!sdb.IncludeExceptionDetailInFaults) { sdb.IncludeExceptionDetailInFaults = true; } } //try //{ //add a service endpoint ServiceEndpoint netTcpEndpoint = host.AddServiceEndpoint(typeof(ICalculatorService), new NetTcpBinding(), string.Empty); //create an announcement endpoint, which points to the Announcement endpoint hosted by the proxy service AnnouncementEndpoint announcementEndpoint = new AnnouncementEndpoint(new NetTcpBinding(), new EndpointAddress(announcementEndpointAddress)); //create a servicediscoveryBehavior and add the announcement endpoint ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior(); serviceDiscoveryBehavior.AnnouncementEndpoints.Add(announcementEndpoint); //add the serviceDiscoveryBehavior to the service host to make the service discovnerable host.Description.Behaviors.Add(serviceDiscoveryBehavior); //start listening for messages host.Open(); Console.WriteLine("Calculator Service started at {0}", baseAddress); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate the service."); Console.WriteLine(); Console.ReadLine(); host.Close(); //} //catch (CommunicationException e) //{ // Console.WriteLine(e.Message); //} //catch (TimeoutException e) //{ // Console.WriteLine(e.Message); //} //if (host.State != CommunicationState.Closed) //{ // Console.WriteLine("Aborting the service..."); // host.Abort(); //} }
protected virtual void ApplyConfiguration() { if (Description == null) { throw new InvalidOperationException("ApplyConfiguration requires that the Description property be initialized. Either provide a valid ServiceDescription in the CreateDescription method or override the ApplyConfiguration method to provide an alternative implementation"); } ServiceElement service = GetServiceElement(); if (service != null) { LoadConfigurationSection(service); } // simplified configuration AddServiceBehaviors(String.Empty, false); // TODO: consider commonBehaviors here // ensure ServiceAuthorizationBehavior Authorization = Description.Behaviors.Find <ServiceAuthorizationBehavior> (); if (Authorization == null) { Authorization = new ServiceAuthorizationBehavior(); Description.Behaviors.Add(Authorization); } // ensure ServiceDebugBehavior ServiceDebugBehavior debugBehavior = Description.Behaviors.Find <ServiceDebugBehavior> (); if (debugBehavior == null) { debugBehavior = new ServiceDebugBehavior(); Description.Behaviors.Add(debugBehavior); } }
void TestInstanceBehavior(MessageInspectBehavior b, string expected, Result actual, int invocations) { ServiceHost h = new ServiceHost(typeof(AllActions), new Uri("http://localhost:8080")); try { h.AddServiceEndpoint(typeof(IAllActions).FullName, new BasicHttpBinding(), "AllActions"); h.Description.Behaviors.Add(b); ServiceDebugBehavior db = h.Description.Behaviors.Find <ServiceDebugBehavior> (); db.IncludeExceptionDetailInFaults = true; h.Open(); AllActionsProxy p = new AllActionsProxy(new BasicHttpBinding() { SendTimeout = TimeSpan.FromSeconds(5), ReceiveTimeout = TimeSpan.FromSeconds(5) }, new EndpointAddress("http://localhost:8080/AllActions")); for (int i = 0; i < invocations; ++i) { p.Get(10); } p.Close(); //let ther server finish his work Thread.Sleep(100); Console.WriteLine(actual.string_res); Assert.AreEqual(expected, actual.string_res); actual.Done = true; } finally { h.Close(); } }
public static void StartCacheServerService() { Uri baseAddress = new Uri(ConfigHelper.GetConfigValue <string>("CacheHostWebServiceUrl")); Uri mexAddress = new Uri("mex", UriKind.Relative); serviceHost = new ServiceHost(typeof(ServerSideCacheServerService), baseAddress); NetTcpBinding binding = new NetTcpBinding(); binding.MaxBufferPoolSize = int.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; // binding.TransferMode = TransferMode.Streamed; binding.ReaderQuotas.MaxArrayLength = int.MaxValue; binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue; binding.ReaderQuotas.MaxDepth = int.MaxValue; binding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue; binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; binding.Security.Mode = SecurityMode.None; binding.CloseTimeout = new TimeSpan(0, 2, 0); binding.OpenTimeout = new TimeSpan(0, 2, 0); binding.ReceiveTimeout = new TimeSpan(0, 2, 0); binding.SendTimeout = new TimeSpan(0, 2, 0); //binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; //binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; //binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; serviceHost.AddServiceEndpoint(typeof(Core.Cmn.Cache.Server.IServerSideCacheServerService), binding, baseAddress); // Add metadata exchange behavior to the service ServiceDebugBehavior 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; } } // Add a service Endpoint for the metadata exchange serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), mexAddress); // Run the service serviceHost.Open(); Console.WriteLine("Service started. Press enter to terminate service."); IsCacheServerServiceStart = true; // serviceHost.Close(); }
static void Main(string[] args) { WebServiceHost hostWeb = new WebServiceHost(typeof(BIPIT_server.Service)); //ServiceEndpoint ep = hostWeb.AddServiceEndpoint(typeof(BIPIT_server.IService), new WebHttpBinding(), ""); ServiceDebugBehavior stp = hostWeb.Description.Behaviors.Find <ServiceDebugBehavior>(); stp.HttpHelpPageEnabled = false; hostWeb.Open(); Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}-{DateTime.Now.ToShortDateString()}] Service Host started "); //{ // // Configure a binding with TCP port sharing enabled // NetTcpBinding binding = new NetTcpBinding(); // binding.PortSharingEnabled = true; // // Start a service on a fixed TCP port // ServiceHost host = new ServiceHost(typeof(Service)); // ushort salt = (ushort)new Random().Next(); // string address = $"net.tcp://localhost:3081/service/{salt}"; // //var sae = new Service(); // host.AddServiceEndpoint(typeof(IService), binding, address); // host.Open(); //} Console.Read(); }
public void ChannelDispatchers_NoDebug() { var ep = "http://" + NetworkHelpers.LocalEphemeralEndPoint().ToString(); ServiceHost h = new ServiceHost(typeof(AllActions), new Uri(ep)); h.AddServiceEndpoint(typeof(AllActions).FullName, new BasicHttpBinding(), "address"); ServiceDebugBehavior b = h.Description.Behaviors.Find <ServiceDebugBehavior> (); b.HttpHelpPageEnabled = false; h.Open(); try { Assert.AreEqual(h.ChannelDispatchers.Count, 1); ChannelDispatcher channelDispatcher = h.ChannelDispatchers[0] as ChannelDispatcher; Assert.IsNotNull(channelDispatcher, "#1"); Assert.IsTrue(channelDispatcher.Endpoints.Count == 1, "#2"); EndpointAddressMessageFilter filter = channelDispatcher.Endpoints [0].AddressFilter as EndpointAddressMessageFilter; Assert.IsNotNull(filter, "#3"); Assert.IsTrue(filter.Address.Equals(new EndpointAddress(ep + "/address")), "#4"); Assert.IsFalse(filter.IncludeHostNameInComparison, "#5"); Assert.IsTrue(channelDispatcher.Endpoints [0].ContractFilter is MatchAllMessageFilter, "#6"); } finally { h.Close(); } }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.AddFacility <WcfFacility>(f => { f.CloseTimeout = TimeSpan.Zero; }); var returnFaults = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true, HttpHelpPageEnabled = true }; container.Register(Component.For <IServiceBehavior>().Instance(returnFaults)); var endpoint = ConfigurationManager.AppSettings.Get("Endpoint_Service"); container.Register(Component.For <IClockServiceCallback>() .ImplementedBy <ClockCallback>() .LifestyleTransient()); container.Register(Component.For <IClockService>() //.AsWcfClient(new DefaultClientModel //{ // Endpoint = WcfEndpoint.BoundTo(Binding.WS_DUAL_HTTP).At(endpoint) //}) .AsWcfClient(new DuplexClientModel { Endpoint = WcfEndpoint.BoundTo(Binding.WS_DUAL_HTTP).At(endpoint) }.Callback(container.Resolve <IClockServiceCallback>())) .LifestyleTransient()); }
/// <summary> /// Performs the installation in the <see cref="T:Castle.Windsor.IWindsorContainer" />. /// </summary> /// <param name="container">The container.</param> /// <param name="store">The configuration store.</param> public void Install(IWindsorContainer container, IConfigurationStore store) { container.AddFacility <WcfFacility>(f => { f.Services.AspNetCompatibility = AspNetCompatibilityRequirementsMode.Allowed; }); //Adding service behavior for service exceptions. ServiceDebugBehavior returnFaults = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true, HttpHelpPageEnabled = true, }; container.Register( Component.For <IServiceBehavior>().Instance(returnFaults)); container.Register(Classes.FromAssemblyInDirectory(new AssemblyFilter(AssemblyInstaller.AssemblyDirectory)) .BasedOn <IServiceApplication>() .WithServiceAllInterfaces() .LifestyleTransient()); var services = container.ResolveAll <IServiceApplication>(); foreach (IServiceApplication serviceApplication in services) { serviceApplication.RegisterServices(container); } }
static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof(Service), new Uri("http://localhost:8000/FormTest")); ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(Service), new WebHttpBinding(), ""); endpoint.Behaviors.Add(new FormProcessingBehavior()); ServiceMetadataBehavior smb = host.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (smb != null) { smb.HttpGetEnabled = false; smb.HttpsGetEnabled = false; } ServiceDebugBehavior sdb = host.Description.Behaviors.Find <ServiceDebugBehavior>(); if (sdb != null) { sdb.HttpHelpPageEnabled = false; } host.Open(); Console.WriteLine("The service is open and listening. To interact with the service,"); Console.WriteLine("navigate to http://localhost:8000/FormTest with a web browser."); Console.ReadLine(); }
ServiceHost CreateHost() { var host = new ServiceHost(typeof(Fonlow.WorkflowDemo.Contracts.WakeupService), baseUri); host.AddServiceEndpoint("Fonlow.WorkflowDemo.Contracts.IWakeup", new NetTcpBinding(), "wakeup"); ServiceDebugBehavior debug = host.Description.Behaviors.Find <ServiceDebugBehavior>(); if (debug == null) { host.Description.Behaviors.Add( new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { // make sure setting is turned ON if (!debug.IncludeExceptionDetailInFaults) { debug.IncludeExceptionDetailInFaults = true; } } return(host); }
private void btnStart_Click(object sender, RoutedEventArgs e) { _hostGeoManager = new ServiceHost(typeof(GeoManager)); _hostMessageManager = new ServiceHost(typeof(MessageManager)); ServiceDebugBehavior behavior = _hostGeoManager.Description.Behaviors.Find <ServiceDebugBehavior>(); if (behavior == null) { behavior = new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }; _hostGeoManager.Description.Behaviors.Add(behavior); } else { behavior.IncludeExceptionDetailInFaults = true; } _hostGeoManager.Open(); _hostMessageManager.Open(); btnStart.IsEnabled = false; btnStop.IsEnabled = true; }
/// <summary> /// Opens the remote notification listener. If this is /// not a parallel testing process, then this operation /// does nothing. /// </summary> private void OpenNotificationListener() { if (!this.Configuration.RunAsParallelBugFindingTask) { return; } Uri address = new Uri("net.pipe://localhost/psharp/testing/process/" + $"{this.Configuration.TestingProcessId}/" + $"{this.Configuration.TestingSchedulerEndPoint}"); NetNamedPipeBinding binding = new NetNamedPipeBinding(); binding.MaxReceivedMessageSize = Int32.MaxValue; this.NotificationService = new ServiceHost(this); this.NotificationService.AddServiceEndpoint(typeof(ITestingProcess), binding, address); ServiceDebugBehavior debug = this.NotificationService.Description.Behaviors.Find <ServiceDebugBehavior>(); debug.IncludeExceptionDetailInFaults = true; try { this.NotificationService.Open(); } catch (AddressAccessDeniedException) { Error.ReportAndExit("Your process does not have access " + "rights to open the remote testing notification listener. " + "Please run the process as administrator."); } }
private void Start(string baseAddress, string path) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Start"); try { if (_host == null) { lock (_lock) { if (_host == null) { // Binding NetTcpBinding binding = AppNotifyServiceHelper.CreateBinding(); // Host Uri uriTcp = new Uri(new Uri(Uri.UriSchemeNetTcp + "://" + baseAddress), path); //Uri uriHttp = new Uri(new Uri(Uri.UriSchemeHttp + "://" + baseAddress), path); _host = new WcfServiceHost(typeof(AppNotifyService), _knownTypes, new Uri[] { uriTcp }); // ServiceMetadataBehavior ServiceMetadataBehavior bServiceMetadata = _host.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (bServiceMetadata == null) { bServiceMetadata = new ServiceMetadataBehavior(); _host.Description.Behaviors.Add(bServiceMetadata); } bServiceMetadata.HttpGetEnabled = false; //bServiceMetadata.HttpGetUrl = uriHttp; // ServiceDebugBehavior ServiceDebugBehavior bServiceDebug = _host.Description.Behaviors.Find <ServiceDebugBehavior>(); if (bServiceDebug == null) { bServiceDebug = new ServiceDebugBehavior(); _host.Description.Behaviors.Add(bServiceDebug); } bServiceDebug.IncludeExceptionDetailInFaults = false; // service points _host.AddServiceEndpoint(typeof(IAppNotifyService), binding, string.Empty); _host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); } } } if (_host != null && _host.State == CommunicationState.Created) { _host.Open(); Log.InfoV(PROC, "Service started at : {0}", _host.BaseAddresses[0]); _mreShutdown.Reset(); } } catch (Exception ex) { Log.Exception(PROC, ex); } }
public void Create() { this.svchost = new WebServiceHost(typeof(HexChainService), new Uri(LocalHostEndpoint)); ServiceEndpoint ep = svchost.AddServiceEndpoint(typeof(IHexChainService), new WebHttpBinding(), ""); ServiceDebugBehavior sdb = svchost.Description.Behaviors.Find <ServiceDebugBehavior>(); sdb.HttpHelpPageEnabled = false; }
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { string[] urlTokens = baseAddresses[0].AbsolutePath.Split('/'); string version = urlTokens[1].ToUpper(); Type[] contractInterfaces = serviceType.GetInterfaces().Where(i => i.GetCustomAttributes(true).Where(a => a.GetType() == typeof(System.ServiceModel.ServiceContractAttribute)).Any()).ToArray(); Type contractType = contractInterfaces.Where(i => i.Namespace.ToUpper().Contains(version)).Single(); ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses); //ServiceEndpoint endpoint = host.AddServiceEndpoint(contractType, new WSHttpBinding(SecurityMode.None), ""); WebHttpBinding webHttpBinding = new WebHttpBinding(); webHttpBinding.Security.Mode = WebHttpSecurityMode.None; webHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; webHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; webHttpBinding.BypassProxyOnLocal = true; ServiceEndpoint endpoint = host.AddServiceEndpoint(contractType, webHttpBinding, ""); WebHttpBehavior webHttpBehavior = new WebHttpBehavior(); webHttpBehavior.DefaultOutgoingRequestFormat = WebMessageFormat.Json; //behavior.DefaultBodyStyle = WebMessageBodyStyle.Bare; webHttpBehavior.DefaultBodyStyle = WebMessageBodyStyle.Wrapped; webHttpBehavior.FaultExceptionEnabled = true; endpoint.Behaviors.Add(webHttpBehavior); ServiceMetadataBehavior metadataBehaviour; if ((host.Description.Behaviors.Contains(typeof(ServiceMetadataBehavior)))) { metadataBehaviour = (ServiceMetadataBehavior)host.Description.Behaviors[typeof(ServiceMetadataBehavior)]; } else { metadataBehaviour = new ServiceMetadataBehavior(); host.Description.Behaviors.Add(metadataBehaviour); } metadataBehaviour.HttpGetEnabled = true; ServiceDebugBehavior debugBehaviour; if (host.Description.Behaviors.Contains(typeof(ServiceDebugBehavior))) { debugBehaviour = (ServiceDebugBehavior)host.Description.Behaviors[typeof(ServiceDebugBehavior)]; } else { debugBehaviour = new ServiceDebugBehavior(); host.Description.Behaviors.Add(debugBehaviour); } debugBehaviour.IncludeExceptionDetailInFaults = true; return(host); }
public static ServiceHost CreateHost <T>(bool asynchronousSendEnabled, bool customBinding, bool faultDetail, bool streamed, HttpMessageHandlerFactory httpMessageHandlerFactory) where T : TestServiceBase { var webHost = new WebServiceHost(typeof(T), TestServiceCommon.ServiceAddress); if (faultDetail && webHost.Description.Behaviors.Contains(typeof(ServiceDebugBehavior))) { var debug = webHost.Description.Behaviors[typeof(ServiceDebugBehavior)] as ServiceDebugBehavior; debug.IncludeExceptionDetailInFaults = true; } Binding httpBinding = null; if (customBinding) { var bindingElement = new HttpMessageHandlerBindingElement(); bindingElement.MessageHandlerFactory = httpMessageHandlerFactory; var httpMsgBinding = new HttpBinding(); if (streamed) { httpMsgBinding.TransferMode = TransferMode.Streamed; } var bindingElements = httpMsgBinding.CreateBindingElements(); bindingElements.Insert(0, bindingElement); httpBinding = new CustomBinding(bindingElements); } else { var httpMsgBinding = new HttpBinding() { MessageHandlerFactory = httpMessageHandlerFactory }; if (streamed) { httpMsgBinding.TransferMode = TransferMode.Streamed; } httpBinding = httpMsgBinding; } var endpoint = webHost.AddServiceEndpoint(typeof(ITestServiceContract), httpBinding, ""); ServiceDebugBehavior debugBehavior = webHost.Description.Behaviors.Find <ServiceDebugBehavior>(); DispatcherSynchronizationBehavior synchronizationBehavior = new DispatcherSynchronizationBehavior() { AsynchronousSendEnabled = asynchronousSendEnabled }; endpoint.Behaviors.Add(synchronizationBehavior); endpoint.Behaviors.Add(new TestHttpBindingParameterBehavior(debugBehavior, synchronizationBehavior)); webHost.Open(); return(webHost); }
//Overriding ApplyConfiguration() allows us to //alter the ServiceDescription prior to opening //the service host. protected override void ApplyConfiguration() { //First, we call base.ApplyConfiguration() //to read any configuration that was provided for //the service we're hosting. After this call, //this.ServiceDescription describes the service //as it was configured. base.ApplyConfiguration(); Description.Behaviors.Add(new CustomErrorHandlerBehavior()); var serviceBehavior = Description.Behaviors.Find <ServiceBehaviorAttribute>(); if (serviceBehavior != null) { serviceBehavior.InstanceContextMode = InstanceContextMode.PerCall; serviceBehavior.AddressFilterMode = AddressFilterMode.Any; } ServiceDebugBehavior debugBehavior = this.Description.Behaviors.Find <ServiceDebugBehavior>(); if (debugBehavior == null) { debugBehavior = new ServiceDebugBehavior(); Description.Behaviors.Add(debugBehavior); } debugBehavior.IncludeExceptionDetailInFaults = true; //Now that we've populated the ServiceDescription, we can reach into it //and do interesting things (in this case, we'll add an instance of //ServiceMetadataBehavior if it's not already there. ServiceMetadataBehavior mexBehavior = Description.Behaviors.Find <ServiceMetadataBehavior>(); if (mexBehavior == null) { mexBehavior = new ServiceMetadataBehavior(); mexBehavior.HttpGetEnabled = true; mexBehavior.HttpsGetEnabled = true; Description.Behaviors.Add(mexBehavior); } else { //Metadata behavior has already been configured, //so we don't have any work to do. return; } //Add a metadata endpoint at http or https base address foreach (Uri baseAddress in BaseAddresses) { if (baseAddress.Scheme == Uri.UriSchemeHttp || baseAddress.Scheme == Uri.UriSchemeHttps) { mexBehavior.HttpGetEnabled = true; AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); } } }
static void Main(string[] args) { //aby baza sie mogla zaktualizowac do obecnego modelu klasy Database.SetInitializer <EFDbContext>(new DropCreateDatabaseIfModelChanges <EFDbContext>()); //korzystanie z log4neta log4net.Config.XmlConfigurator.Configure(); ServiceRepository Repository; try { //wybranie czy korzystamy z bazy danych czy mock Console.WriteLine("Service with Database ? (y/n)"); if (Console.ReadLine().ToLower() == "y") { Repository = new ServiceRepository(); } else { Repository = new ServiceRepository(false); } //pobranie adresu servRep z app.config string serviceRepoAddress = ConfigurationSettings.AppSettings["serviceRepoAddress"]; //odpalenie serwisu var Server = new ServiceRepositoryHost(Repository, serviceRepoAddress); Server.AddDefaultEndpoint(serviceRepoAddress); ServiceDebugBehavior debug = Server.Description.Behaviors.Find <ServiceDebugBehavior>(); // if not found - add behavior with setting turned on if (debug == null) { Server.Description.Behaviors.Add( new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { // make sure setting is turned ON if (!debug.IncludeExceptionDetailInFaults) { debug.IncludeExceptionDetailInFaults = true; } } Server.Open(); log.Info("Uruchomienie Serwera"); Console.WriteLine("Uruchomienie Serwera"); //komunikacja z innymi serwisami Console.ReadLine(); } catch (ServiceRepositoryException Ex) { log.Info("Złapano wyjatek: " + Ex.Message); Console.WriteLine(Ex.Message); } Console.ReadLine(); log.Info("Zatrzymanie Serwera"); }
public static void Configure(ServiceDebugBehavior behavior) { if (behavior == null) { throw new ArgumentException("Argument 'behavior' cannot be null. Cannot configure debug behavior."); } behavior.IncludeExceptionDetailInFaults = true; }
public static void Start() { Uri baseAddress = new Uri(Core.Cmn.ConfigHelper.GetConfigValue <string>("TraceServiceUri")); Uri metadataAddress = new Uri("mex", UriKind.Relative); ServiceHost = new ServiceHost(typeof(TraceHostService), baseAddress); NetTcpBinding binding = new NetTcpBinding(); binding.MaxBufferPoolSize = int.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; binding.ReaderQuotas.MaxArrayLength = int.MaxValue; binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue; binding.ReaderQuotas.MaxDepth = int.MaxValue; binding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue; binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; binding.Security.Mode = SecurityMode.None; binding.CloseTimeout = new TimeSpan(0, 2, 0); binding.OpenTimeout = new TimeSpan(0, 2, 0); binding.ReceiveTimeout = new TimeSpan(0, 2, 0); binding.SendTimeout = new TimeSpan(0, 2, 0); ServiceHost.AddServiceEndpoint(typeof(ITraceHostService), binding, baseAddress); // Add metadata exchange behavior to the service ServiceDebugBehavior 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; } } var serviceBehavior = new ServiceMetadataBehavior(); ServiceHost.Description.Behaviors.Add(serviceBehavior); // Add a service Endpoint for the metadata exchange ServiceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), metadataAddress); // Run the service ServiceHost.Open(); }
static void Main(string[] args) { string address_TCP = "net.tcp://localhost:5002/ArticleLibrary/ArticleService"; Uri[] address_base = { new Uri(address_TCP) }; ServiceHost service_host = new ServiceHost(typeof(ArticleLibrary.ArticleService), address_base); ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); service_host.Description.Behaviors.Add(behavior); ServiceDebugBehavior debug = service_host.Description.Behaviors.Find <ServiceDebugBehavior>(); if (debug == null) { service_host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { if (!debug.IncludeExceptionDetailInFaults) { debug.IncludeExceptionDetailInFaults = true; } } XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas(); readerQuotas.MaxArrayLength = int.MaxValue; readerQuotas.MaxBytesPerRead = int.MaxValue; readerQuotas.MaxNameTableCharCount = int.MaxValue; readerQuotas.MaxDepth = int.MaxValue; readerQuotas.MaxStringContentLength = int.MaxValue; NetTcpBinding binding_tcp = new NetTcpBinding(); binding_tcp.MaxReceivedMessageSize = int.MaxValue; binding_tcp.OpenTimeout = new TimeSpan(0, 5, 0); binding_tcp.CloseTimeout = new TimeSpan(0, 5, 0); binding_tcp.SendTimeout = new TimeSpan(0, 5, 0); binding_tcp.ReceiveTimeout = new TimeSpan(24, 0, 0); binding_tcp.ReaderQuotas = readerQuotas; 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(ArticleLibrary.IArticleService), binding_tcp, address_TCP); service_host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); service_host.Open(); Console.WriteLine("Service works"); Console.ReadLine(); service_host.Close(); }
/// <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); int restPort = 8732; if (!OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Id.Equals(String.Empty)) { try { restPort = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Value); } catch (FormatException ex) { this.Log.Error("Error pulling REST port from property (not a valid number)", ex); } catch (OverflowException ex) { this.Log.Error("Error pulling REST port from property (too large)", ex); } catch (ArgumentNullException ex) { this.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 }); } this.Log.Info("Starting Rest Interface"); serviceHost.Open(); } catch (Exception ex) { this.Log.Error("Error starting RESTful web service", ex); } }
public void should_be_able_to_show_that_interceptor_was_called_when_wcf_service_is_invoked() { ServiceDebugBehavior returnFaults = new ServiceDebugBehavior(); returnFaults.IncludeExceptionDetailInFaults = true; returnFaults.HttpHelpPageEnabled = true; ServiceMetadataBehavior metadata = new ServiceMetadataBehavior(); metadata.HttpGetEnabled = true; using ( new WindsorContainer() .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero) .Register( Component.For <TestInterceptor>(), // The interceptor must be registered like this. Component.For <IServiceBehavior>().Instance(returnFaults), Component.For <IServiceBehavior>().Instance(metadata), Component .For <IOperations>() .ImplementedBy <Operations>() .Interceptors(InterceptorReference.ForType <TestInterceptor>()).Anywhere // Don't care what order this is called in (and there is only one interceptor on this any case). .DependsOn(new { value = Expected }) // Notice how this constant is injected in to the service. .AsWcfService( new DefaultServiceModel() //.OpenEagerly() // This is useful to force immediate creation of services and to see any errors that may result. .AddBaseAddresses(BaseAddress) .AddEndpoints( WcfEndpoint .ForContract <IOperations>() .BoundTo(new WSHttpBinding()) .At(RelativeAddress) ) ))) { // This sleep is useful if/when you'd like to browse to http://localhost:8000/Operations.svc // to verify that meta-data is being published for this service. //Thread.Sleep(100000); // Notice that we're using the standard WCF channel factory here, // rather than the castle proxies. IOperations client = ChannelFactory <IOperations> .CreateChannel( new WSHttpBinding(), new EndpointAddress(BaseAddress + "/" + RelativeAddress) ); int result = client.GetValueFromConstructor(); Assert.AreEqual(Expected, result); Assert.That(TestInterceptor.mostRecentMethodCallIntercepoted, Is.EqualTo("GetValueFromConstructor")); } }
public void CreateHost() { if (IsStarted) { host.Close(); IsStarted = false; } else { using (host) { Address = new Uri(textBox1.Text); host = new ServiceHost(typeof(Level2Service), Address); ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); ServiceDebugBehavior debug = host.Description.Behaviors.Find <ServiceDebugBehavior>(); behavior.HttpGetEnabled = BehaviorEnable; host.Description.Behaviors.Add(behavior); // host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX"); if (checkBox1.Checked == true) { host.AddServiceEndpoint(contractType, new BasicHttpBinding(), "LoginInformation"); } else { host.AddServiceEndpoint(contractType, new NetMsmqBinding(), "NetMsmqBinding"); } // if not found - add behavior with setting turned on if (debug == null) { host.Description.Behaviors.Add( new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { // make sure setting is turned ON if (!debug.IncludeExceptionDetailInFaults) { debug.IncludeExceptionDetailInFaults = true; } } } host.Open(); progressBar1.Value = 0; timer1.Start(); lblstatus.Text = "Host Option is running......"; button2.Enabled = true; button1.Enabled = false; new Thread(new ThreadStart(TestTrace)).Start(); IsStarted = true; } }
public void Defaults() { ServiceDebugBehavior behavior = new ServiceDebugBehavior(); Assert.AreEqual(true, behavior.HttpHelpPageEnabled, "HttpHelpPageEnabled"); Assert.IsNull(behavior.HttpHelpPageUrl, "HttpHelpPageUrl"); Assert.AreEqual(true, behavior.HttpsHelpPageEnabled, "HttpsHelpPageEnabled"); Assert.IsNull(behavior.HttpsHelpPageUrl, "HttpsHelpPageUrl"); Assert.AreEqual(false, behavior.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults"); }