static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof(CarCentalService)); try { host.Open(); Console.WriteLine("The car rental service is up."); Console.ReadLine(); host.Close(); } catch (CommunicationException ex) { host.Abort(); Console.WriteLine(ex); } catch (TimeoutException ex) { host.Abort(); Console.WriteLine(ex); } catch (Exception ex) { host.Abort(); Console.WriteLine(ex); } }
static void Main(string[] args) { Console.WriteLine("Calculator Service Demo Server - Version 4\n"); // Step 1 Create a string address and URI to serve as the base address. string strAdr = @"http://localhost:8002/CalculatorService"; Uri baseAddress = new Uri(strAdr); // Step 2 Create a ServiceHost instance ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress); try { // Step 3 Add a service endpoint. //The WSHttpBinding is similar to the BasicHttpBinding but provides more Web service features. //It uses the HTTP transport and provides message security, as does BasicHttpBinding, but it also provides transactions, //reliable messaging, and WS-Addressing, either enabled by default or available through a single control setting. //BasicHttpBinding httpb = new BasicHttpBinding(); //OR WSHttpBinding wshttp = new WSHttpBinding(); //selfHost.AddServiceEndpoint(typeof(ICalculator), httpb, strAdr); //OR selfHost.AddServiceEndpoint(typeof(ICalculator), wshttp, baseAddress); // Step 4 Enable metadata exchange. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); selfHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); // Step 5 Start the service. selfHost.Open(); Console.WriteLine("The service is ready at {0}\n", strAdr); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. selfHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); selfHost.Abort(); } catch (Exception ex) { Console.WriteLine("An exception occurred: {0}", ex.Message); selfHost.Abort(); } Console.WriteLine("Press <ENTER> to terminate the program."); Console.ReadLine(); }
static void Main(string[] args) { // TODO: extract into a properties file string serviceName = "CAService"; string baseAddress = "net.tcp://localhost:3333/"; ServiceHost caHost = new ServiceHost(typeof(Simulation), new Uri(baseAddress + serviceName)); try { // Configure the TCP binding NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.MaxReceivedMessageSize = Int32.MaxValue; tcpBinding.MaxBufferPoolSize = Int32.MaxValue; tcpBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; // Configure a binary message encoding binding element BinaryMessageEncodingBindingElement binaryBinding = new BinaryMessageEncodingBindingElement(); binaryBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; binaryBinding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue; binaryBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; // Configure a MEX TCP binding to send metadata CustomBinding mexBinding = new CustomBinding(MetadataExchangeBindings.CreateMexTcpBinding()); mexBinding.Elements.Insert(0, binaryBinding); mexBinding.Elements.Find<TcpTransportBindingElement>().MaxReceivedMessageSize = Int32.MaxValue; // Configure the host ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; caHost.Description.Behaviors.Add(smb); caHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, baseAddress + serviceName + "/mex"); caHost.AddServiceEndpoint(typeof(ICAService), tcpBinding, baseAddress + serviceName); ServiceDebugBehavior debug = caHost.Description.Behaviors.Find<ServiceDebugBehavior>(); if (debug == null) caHost.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); else if (!debug.IncludeExceptionDetailInFaults) debug.IncludeExceptionDetailInFaults = true; // Open the host and run until Enter is pressed caHost.Open(); Console.WriteLine("CA Simulator Server is running. Press Enter to exit."); Console.ReadLine(); caHost.Close(); } catch (CommunicationException e) { Console.WriteLine(e.Message); caHost.Abort(); } catch (InvalidOperationException e) { Console.WriteLine(e.Message); caHost.Abort(); } }
private void CreateWcfHost(Type contract, System.ServiceModel.Channels.Binding bind, string addr, params IEndpointBehavior[] ebh) { new Thread(delegate() { ServiceHost host = new ServiceHost(typeof (TestService)); try { var se = host.AddServiceEndpoint(contract, bind, addr); if (ebh != null && ebh.Length > 0) { foreach (var i in ebh) { se.Behaviors.Add(i); } } host.Open(); Hosts.Add(host); } catch { host.Abort(); } }).Start(); WindowState = FormWindowState.Minimized; }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8080/EcUtbildning.SocialSecurityNumber"); ServiceHost selfsServiceHost = new ServiceHost(typeof(GetSocialSecurityNumberService), baseAddress); try { selfsServiceHost.AddServiceEndpoint (typeof (IGetSocialSecurityNumber), new WSHttpBinding(), "GetSocialSecurityNumberService"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfsServiceHost.Description.Behaviors.Add(smb); selfsServiceHost.Open(); Console.WriteLine($"Servicen är nu öppen på: {baseAddress}"); Console.WriteLine("Tryck ENTER för att avsluta"); Console.ReadLine(); } catch (CommunicationException ex) { Console.WriteLine($"Ett kommunikationsfel har inträffat!, {ex.Message}"); selfsServiceHost.Abort(); Console.ReadLine(); throw; } }
static void Main(string[] args) { Uri uri = new Uri("http://localhost:8080/ServiceModel/Service"); ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), uri); try { serviceHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService"); System.ServiceModel.Description.ServiceMetadataBehavior serviceMetadataBehavior = new System.ServiceModel.Description.ServiceMetadataBehavior(); serviceMetadataBehavior.HttpGetEnabled = true; serviceHost.Description.Behaviors.Add(serviceMetadataBehavior); serviceHost.Open(); Console.WriteLine("This service is ready"); Console.WriteLine("Press <Enter> to terminate"); Console.WriteLine(); Console.ReadLine(); serviceHost.Close(); } catch (CommunicationException ex) { Console.WriteLine("Error occured"); serviceHost.Abort(); } }
public static void Main() { Console.WriteLine(" **** ICalculatorService service ****"); Uri baseAddress = new Uri("http://localhost:8000/" + Guid.NewGuid().ToString()); ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress); try { // Discovery is being added through config serviceHost.Open(); Console.WriteLine("Calculator Service started at {0}", baseAddress); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate the service."); Console.WriteLine(); Console.ReadLine(); serviceHost.Close(); } catch (CommunicationException e) { Console.WriteLine(e.Message); } catch (TimeoutException e) { Console.WriteLine(e.Message); } if (serviceHost.State != CommunicationState.Closed) { Console.WriteLine("Aborting service..."); serviceHost.Abort(); } }
private static void RunServer() { //get URI of service from config Uri serviceAddress = new Uri(GetUriSetting()); //new instance of service host ServiceHost selfHostServer = new ServiceHost(typeof(SentinelService), serviceAddress); try { //adding service endpoint selfHostServer.AddServiceEndpoint(typeof(ISentinelService), new WSHttpBinding(), "SentinelServer"); //enable metadata exchange ServiceMetadataBehavior serverBehavior = new ServiceMetadataBehavior(); serverBehavior.HttpGetEnabled = true; selfHostServer.Description.Behaviors.Add(serverBehavior); //running selfHostServer.Open(); Console.WriteLine("Server started at {0}. Press <ENTER> to terminate service.", DateTime.Now); Console.WriteLine(); Console.ReadLine(); Console.WriteLine("Connection Closed."); //close for termination selfHostServer.Close(); } catch (Exception ex) { Console.WriteLine("The following exception occurred when running the Sentinel Server. {0}", ex.Message); selfHostServer.Abort(); } }
static void Main(string[] args) { IPHostEntry entry = Dns.GetHostEntry(""); string addr = "localhost"; for (int i = 0; i < entry.AddressList.Length; i++) { if (entry.AddressList[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { addr = entry.AddressList[i].ToString(); break; } } Uri baseAddress = new Uri("http://" + addr + ":8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D"); ServiceHost serviceHost = new ServiceHost(typeof(ServiceHelloWCF), baseAddress); try { ServiceEndpoint wsEndpoint = serviceHost.AddServiceEndpoint(typeof(IServiceHelloWCF), new WSHttpBinding(SecurityMode.None), string.Empty); EndpointDiscoveryBehavior endpointDiscoveryBehavior = new EndpointDiscoveryBehavior(); // Add the discovery behavior to the endpoint. wsEndpoint.Behaviors.Add(endpointDiscoveryBehavior); // Make the service discoverable over UDP multicast serviceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior()); serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscovery11)); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = baseAddress; serviceHost.Description.Behaviors.Add(smb); serviceHost.Open(); Console.WriteLine("Hello World WCF Service started at {0}", baseAddress); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate the service."); Console.WriteLine(); Console.ReadLine(); serviceHost.Close(); } catch (CommunicationException e) { Console.WriteLine(e.Message); } catch (TimeoutException e) { Console.WriteLine(e.Message); } if (serviceHost.State != CommunicationState.Closed) { Console.WriteLine("Aborting service..."); serviceHost.Abort(); } }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8080/EcUtbildning.Hobby"); ServiceHost selfServiceHost = new ServiceHost(typeof(MyHobbyService), baseAddress); try { selfServiceHost.AddServiceEndpoint (typeof (IMyHobby), new WSHttpBinding(), "MyServiceHobby"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfServiceHost.Description.Behaviors.Add(smb); selfServiceHost.Open(); Console.WriteLine($"Servicen är nu öppen på {baseAddress}"); Console.WriteLine("Tryck ENTER för att avsluta"); Console.ReadLine(); } catch (CommunicationException ex) { selfServiceHost.Abort(); Console.WriteLine($"Error, please see exception {ex.Message}"); Console.ReadLine(); throw; } }
public static void Main() { Uri baseAddress = new Uri("http://localhost:8000/" + Guid.NewGuid().ToString()); ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress); try { // Add an endpoint to the service ServiceEndpoint discoverableCalculatorEndpoint = serviceHost.AddServiceEndpoint( typeof(ICalculatorService), new WSHttpBinding(), "/DiscoverableEndpoint"); // Add a Scope to the endpoint EndpointDiscoveryBehavior discoverableEndpointBehavior = new EndpointDiscoveryBehavior(); discoverableEndpointBehavior.Scopes.Add(new Uri("ldap:///ou=engineering,o=exampleorg,c=us")); discoverableCalculatorEndpoint.Behaviors.Add(discoverableEndpointBehavior); // Add an endpoint to the service ServiceEndpoint nonDiscoverableCalculatorEndpoint = serviceHost.AddServiceEndpoint (typeof(ICalculatorService), new WSHttpBinding(), "/NonDiscoverableEndpoint"); // Disable discoverability of the endpoint EndpointDiscoveryBehavior nonDiscoverableEndpointBehavior = new EndpointDiscoveryBehavior(); nonDiscoverableEndpointBehavior.Scopes.Add(new Uri("ldap:///ou=engineering,o=exampleorg,c=us")); nonDiscoverableEndpointBehavior.Enabled = false; nonDiscoverableCalculatorEndpoint.Behaviors.Add(nonDiscoverableEndpointBehavior); // Make the service discoverable over UDP multicast serviceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior()); serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint()); serviceHost.Open(); Console.WriteLine("Calculator Service started at {0}", baseAddress); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate the service."); Console.WriteLine(); Console.ReadLine(); serviceHost.Close(); } catch (CommunicationException e) { Console.WriteLine(e.Message); } catch (TimeoutException e) { Console.WriteLine(e.Message); } if (serviceHost.State != CommunicationState.Closed) { Console.WriteLine("Aborting the service..."); serviceHost.Abort(); } }
private static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof (EvalService)); WSHttpBinding noSecurityPlusRMBinding = new WSHttpBinding(); noSecurityPlusRMBinding.Security.Mode = SecurityMode.None; noSecurityPlusRMBinding.ReliableSession.Enabled = true; host.AddServiceEndpoint(typeof (IEvalService), new BasicHttpBinding(), "http://localhost:8080/evals/basic"); host.AddServiceEndpoint(typeof(IEvalService), noSecurityPlusRMBinding, "http://localhost:8080/evals/ws"); //host.AddServiceEndpoint(typeof (IEvalService), new NetTcpBinding(), "net.tcp://localhost:8081/evals"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri("http://localhost:8080/evals/basic/meta"); host.Description.Behaviors.Add(smb); try { host.Open(); PrintServiceInfo(host); Console.ReadLine(); host.Close(); } catch (Exception e) { Console.WriteLine(e); host.Abort(); } Console.ReadLine(); }
static void Main(string[] args) { // Step 1 of the address configuration procedure: Create a URI to serve as the base address. Uri baseAddressDRS = new Uri("http://localhost:8088/CrewFieldServiceManagement/"); // Step 2 of the hosting procedure: Create ServiceHost ServiceHost dataRepositoryService = new ServiceHost(typeof(DataRepositoryServiceLib.DataRepositoryService), baseAddressDRS); try { // Step 3 of the hosting procedure: Add a service endpoint. dataRepositoryService.AddServiceEndpoint(typeof(IDataRepositoryService), new WSHttpBinding(), "DataRepositoryService"); // Step 4 of the hosting procedure: Enable metadata exchange. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; dataRepositoryService.Description.Behaviors.Add(smb); // Step 5 of the hosting procedure: Start (and then stop) the service. dataRepositoryService.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); CrFSMLogger.CrFSMLogger.Instance.WriteToLog("Data repository service is up"); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. dataRepositoryService.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); dataRepositoryService.Abort(); } }
static void Main(string[] args) { // Step 1 Create a URI to serve as the base address. Uri baseAddress = new Uri("http://localhost:8000/GettingStarted/"); // Step 2 Create a ServiceHost instance ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress); try { // Step 3 Add a service endpoint. selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService"); // Step 4 Enable metadata exchange. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); // Step 5 Start the service. selfHost.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. selfHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); selfHost.Abort(); } }
static void StartService() { var localV4Address = GetLocalV4Address(); var localAddress = "http://" + localV4Address + ":8000/zpd"; var baseAddress = new Uri(localAddress); var host = new ServiceHost(typeof(ZPDService), baseAddress); try { //host.AddServiceEndpoint(typeof(IZPDService), new WSHttpBinding(), "Service"); var smb = new ServiceMetadataBehavior {HttpGetEnabled = true, MetadataExporter = {PolicyVersion = PolicyVersion.Policy15}}; host.Description.Behaviors.Add(smb); host.Open(); Console.WriteLine("Service is ready at {0}. Press <ENTER> to terminate", localAddress); Console.ReadLine(); host.Close(); ZuneMediaPlayerManager.ClosePlayer(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); host.Abort(); } Console.WriteLine("Press <ENTER> to close"); Console.ReadLine(); }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8000/GlydeServiceModelExamples/Service"); ServiceHost selfHost = new ServiceHost(typeof(StringManipulatorService), baseAddress); try { selfHost.AddServiceEndpoint( typeof(IStringManipulator), new WSHttpBinding(), "StringManipulatorService"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); // Step 5 of the hosting procedure: Start (and then stop) the service. selfHost.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. selfHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); selfHost.Abort(); } }
/// <summary> /// Override ServiceBase OnStart, trigger when the service is started /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { //Thread.Sleep(30000); //Debugging purpose try { base.OnStart(args); _gameHost.Open(); PrintServiceInfo(_gameHost); eventLog1.WriteEntry("The poker game service has started."); } catch (Exception e) { eventLog1.WriteEntry(e.StackTrace, EventLogEntryType.Error); _gameHost.Abort(); } }
static void Main(string[] args) { string command; Uri baseAddress = new Uri("http://localhost:8000/wob/Login"); ServiceHost selfHost = null; try { selfHost = new ServiceHost(typeof(LoginService), baseAddress); selfHost.AddServiceEndpoint(typeof(ILogin), new WSDualHttpBinding(), "LoginService"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); selfHost.Open(); Console.WriteLine("Open"); while (true) { command = Console.ReadLine(); if (command == "e") break; } } catch (CommunicationException ce) { Console.WriteLine("Failure!"); Console.WriteLine(ce); Console.ReadLine(); selfHost.Abort(); } }
static void Main() { //run the program and visit this URI to confirm the service is working Uri baseAddress = new Uri("http://localhost:8000/GPSSim"); ServiceHost host = new ServiceHost(typeof(GPSSim), baseAddress); //basicHttpBinding is used because WS binding is currently unsupported host.AddServiceEndpoint(typeof(IGPSSim), new BasicHttpBinding(), "GPS Sim Service"); try { ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); } catch (CommunicationException e) { Console.WriteLine("An exception occurred: {0}", e.Message); host.Abort(); } host.Open(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8733/Design_Time_Addresses/GetDate/"); ServiceHost selfHost = new ServiceHost(typeof(DateService), baseAddress); try { selfHost.AddServiceEndpoint(typeof(IDateService), new WSHttpBinding(), "Date Service"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); using (selfHost) { selfHost.Open(); Console.WriteLine("Service is ready\nPress any key to exit"); Console.WriteLine(); Console.ReadKey(); } } catch (CommunicationException ex) { Console.WriteLine("An exception occured: {0}", ex.Message); selfHost.Abort(); } }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8290/MyAgeService"); using (var selfServiceHost = new ServiceHost(typeof(MyAgeService), baseAddress)) { try { selfServiceHost.AddServiceEndpoint(typeof(IMyAgeService), new WSHttpBinding(), "MyAgeService"); ServiceMetadataBehavior smBehavior = new ServiceMetadataBehavior(); smBehavior.HttpGetEnabled = true; selfServiceHost.Description.Behaviors.Add(smBehavior); selfServiceHost.Open(); Console.WriteLine("Tjänsten är ööppppeennnnn!"); Console.WriteLine("Tryck ENTER för att avsluta selfservice"); Console.ReadLine(); } catch (CommunicationException ex) { Console.WriteLine($"Ett kommunikationsfel har inträffat! {ex.Message}"); selfServiceHost.Abort(); Console.ReadLine(); throw; } } }
static void Main(string[] args) { ServiceHost selfHost = new ServiceHost(typeof(Controller)); try { // Add a service endpoint. selfHost.AddServiceEndpoint(typeof(IController), new NetTcpBinding(), Constants.URI); // Start the service. selfHost.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. selfHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); selfHost.Abort(); } }
public static void Main() { Uri baseAddress = new Uri("http://localhost:8000/" + Guid.NewGuid().ToString()); ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress); try { // ServiceDiscoveryBehavior is added through the configuration // UdpDiscoveryEndpoint is added through the configuration serviceHost.Open(); Console.WriteLine("Calculator Service started {0}", baseAddress); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate the service"); Console.WriteLine(); Console.ReadLine(); serviceHost.Close(); } catch (CommunicationException e) { Console.WriteLine(e.Message); } catch (TimeoutException e) { Console.WriteLine(e.Message); } if (serviceHost.State != CommunicationState.Closed) { Console.WriteLine("Aborting the service..."); serviceHost.Abort(); } }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service"); ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress); try { selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); selfHost.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); selfHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); selfHost.Abort(); } }
public void ServerAncClientExceptionsEndpointBehavior() { var hook = new ExceptionsEndpointBehaviour(); var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; var serv = new ExceptionService(); using (var host = new ServiceHost(serv, new Uri[] { new Uri(address), })) { var b = new NetNamedPipeBinding(); var serverEndpoint = host.AddServiceEndpoint(typeof(IExceptionService), b, address); serverEndpoint.Behaviors.Add(hook); host.Open(); var f = new ChannelFactory<IExceptionService>(b); f.Endpoint.Behaviors.Add(hook); var c = f.CreateChannel(new EndpointAddress(address)); try { c.DoException("message"); } catch (InvalidOperationException ex) { StringAssert.AreEqualIgnoringCase("message", ex.Message); } host.Abort(); } }
static void Main(string[] args) { Console.Title = "ClaimsEnumerationHost"; using (ServiceHost serviceHost = new ServiceHost(typeof(ClaimsEnumeratorService.ClaimsEnumerator))) { try { serviceHost.Open(); Console.WriteLine("The ClaimsEnumerations service is now running."); Console.WriteLine("EndPoints: "); foreach (ServiceEndpoint ep in serviceHost.Description.Endpoints) Console.WriteLine(" " + ep.Address.Uri.ToString()); Console.WriteLine("Press <ENTER> to terminate Service."); Console.ForegroundColor = ConsoleColor.Magenta; // The service can now be accessed. Console.ReadLine(); serviceHost.Close(); } catch (CommunicationException exc) { serviceHost.Abort(); Console.WriteLine(exc.Message); Console.ReadLine(); } } }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8080/WCF_Service_1000"); using (ServiceHost selfServiceHost = new ServiceHost(typeof(Birthday1000Service), baseAddress)) { try { selfServiceHost.AddServiceEndpoint( typeof(IBirthday), new WSHttpBinding(), "Birthday1000Service"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfServiceHost.Description.Behaviors.Add(smb); selfServiceHost.Open(); Console.WriteLine("Nu är tjänsten öppen"); Console.WriteLine("Tryck på ENTER för att stänga tjänsten"); Console.ReadLine(); } catch (CommunicationException exception) { Console.WriteLine($"Ett fel inträffade {exception.Message}"); selfServiceHost.Abort(); Console.ReadLine(); } } }
public void Can_validate_floating_license() { string fileName = WriteFloatingLicenseFile(); GenerateLicenseFileInLicensesDirectory(); LicensingService.SoftwarePublicKey = public_only; LicensingService.LicenseServerPrivateKey = floating_private; var host = new ServiceHost(typeof(LicensingService)); const string address = "http://localhost:19292/license"; host.AddServiceEndpoint(typeof(ILicensingService), new WSHttpBinding(), address); host.Open(); try { var validator = new LicenseValidator(public_only, fileName, address, Guid.NewGuid()); validator.AssertValidLicense(); } finally { host.Abort(); } }
public void Can_only_get_license_per_allocated_licenses() { string fileName = WriteFloatingLicenseFile(); GenerateLicenseFileInLicensesDirectory(); LicensingService.SoftwarePublicKey = public_only; LicensingService.LicenseServerPrivateKey = floating_private; var host = new ServiceHost(typeof(LicensingService)); var address = "http://localhost:29292/license"; host.AddServiceEndpoint(typeof(ILicensingService), new WSHttpBinding(), address); host.Open(); try { var validator = new LicenseValidator(public_only, fileName, address, Guid.NewGuid()); validator.AssertValidLicense(); var validator2 = new LicenseValidator(public_only, fileName, address, Guid.NewGuid()); Assert.Throws<FloatingLicenseNotAvialableException>(() => validator2.AssertValidLicense()); } finally { host.Abort(); } }
static void Main(string[] args) { //BaseAddress var baseAddress = new Uri("http://localhost:8080/SelfService.NextThousand"); //ServiceHost ServiceHost selfServiceHost = new ServiceHost(typeof(NextThousandCheckerService),baseAddress); try { //Abc - endpoint selfServiceHost.AddServiceEndpoint(typeof(INextThousand), new WSHttpBinding(), "NextThousandCheckerService"); //Metadata ServiceMetadataBehavior smBehavior = new ServiceMetadataBehavior { HttpGetEnabled = true }; selfServiceHost.Description.Behaviors.Add(smBehavior); //startar tjänsten selfServiceHost.Open(); Console.WriteLine("Tjänsten är öppen!"); Console.ReadKey(); } catch (CommunicationException ex) { Console.WriteLine($"Kommunikations fel{ex.Message}"); selfServiceHost.Abort(); Console.ReadKey(); throw; } }
private static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof (DiproveService)); /* host.AddServiceEndpoint(typeof(IEvalService), new BasicHttpBinding(), "http://localhost:8080/evals/basic"); host.AddServiceEndpoint(typeof(IEvalService), new WSHttpBinding(), "http://localhost:8080/evals/ws"); host.AddServiceEndpoint(typeof(IEvalService), new NetTcpBinding(), "net.tcp://localhost:8081/evals"); */ try { host.Open(); PrintServiceInfo(host); Console.ReadLine(); host.Close(); } catch (Exception e) { Console.WriteLine(e); host.Abort(); } }
static void Main(string[] args) { System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(ClienteService)); host.AddServiceEndpoint(typeof(IClienteService), new BasicHttpBinding(), new Uri("http://localhost:8080/clientes")); try { host.Open(); Console.ReadLine(); host.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); host.Abort(); Console.ReadLine(); } }