本文整理汇总了C#中System.ServiceModel.ServiceHost.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceHost.Abort方法的具体用法?C# ServiceHost.Abort怎么用?C# ServiceHost.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.ServiceHost
的用法示例。
在下文中一共展示了ServiceHost.Abort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
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);
}
}
示例2: Main
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();
}
示例3: Main
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();
}
}
示例4: Main
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();
}
}
示例5: Main
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());
}
示例6: Main
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;
}
}
}
示例7: Main
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();
}
}
示例8: ServerAncClientExceptionsEndpointBehavior
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();
}
}
示例9: Main
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();
}
}
}
示例10: Can_validate_floating_license
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();
}
}
示例11: RunServer
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();
}
}
示例12: Main
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();
}
}
示例13: Main
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;
}
}
示例14: Main
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();
}
}
示例15: Main
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();
}