本文整理汇总了C#中System.ServiceModel.ServiceHost.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceHost.ToString方法的具体用法?C# ServiceHost.ToString怎么用?C# ServiceHost.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.ServiceHost
的用法示例。
在下文中一共展示了ServiceHost.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitialiseServiceHost
// Initialise and put to listening either the message or command service, listens on a http or https port
internal void InitialiseServiceHost(ServiceHost host)
{
Log(host);
Uri baseAddress = new Uri(_settingProcessor.GetString(enmSetting.hosttype.ToString()) + "://" + _settingProcessor.GetString(enmSetting.IpAddress.ToString()) + ":" + _settingProcessor.GetString(enmSetting.Port.ToString()) + "/" + host.ToString());
host = new ServiceHost(host, new Uri[] { baseAddress });
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.OpenTimeout = new TimeSpan(0, 0, 20);
host.CloseTimeout = new TimeSpan(0, 0, 20);
}
示例2: GetOrCreateAsyncThread
/// <summary>
/// Gets the or create async thread.
/// </summary>
/// <returns>The or create async thread.</returns>
/// <param name="artefactTypes">Artefact types.</param>
/// <param name="timeout">Timeout.</param>
/// <param name="output">Output.</param>
/// <param name="error">Error.</param>
public static Thread GetOrCreateAsyncThread(Type[] artefactTypes = null, TimeSpan timeout = default(TimeSpan), TextWriter output = null, TextWriter error = null)
{
if (output == null)
// Console.SetOut(output);
output = Console.Out;
if (error == null)
// Console.SetError(error);
error = output == Console.Out ? Console.Error : output;
if (_serviceHostThread != null && _serviceHostThread.IsAlive)
return _serviceHostThread;
_exitServiceHost = false;
_serviceHostThread = new Thread(() =>
{
// if (artefactTypes != null)
// {
//// ArtefactRepository.ArtefactTypes.AddRange(artefactTypes);
// //or
// Artefact.ArtefactTypes.AddRange(artefactTypes);
// }
FileStream _logFileStream = null;
try
{
_serviceInstance = new Repository();
if (LogFilePath != null)
output = error = /*TextWriter.Synchronized(*/ new StreamWriter(_logFileStream = File.OpenWrite(LogFilePath));//);
_output = output;
_error = error;
_serviceHost = BuildServiceHost(_serviceInstance, timeout, false);
_serviceHost.Open();
output.WriteLine(_serviceHost.ToString());
while (!_exitServiceHost)
Thread.Sleep(333);
}
catch (Exception ex)
{
error.WriteLine("\nServiceHost Exception (State={0}):\n{1}\n", (_serviceHost == null ? "(null)" : _serviceHost.State.ToString()), ex.ToString());
}
finally
{
if (_serviceHost != null && _serviceHost.State != CommunicationState.Closed && _serviceHost.State != CommunicationState.Closing)
_serviceHost.Close();
if (LogFilePath != null && _logFileStream != null)
{
_logFileStream.Flush(true);
_logFileStream.Close();
_logFileStream = null;
}
}
});
_serviceHostThread.Priority = ThreadPriority.BelowNormal; // this thread doesn't run the service host itself, and i don't think the thread created
_serviceHostThread.Start();
return _serviceHostThread;
// by sh.Open() will inherit this lower priority (should b e normal??)
}
示例3: Main
static void Main(string[] args)
{
//Creating the binding use windows security
NetTcpBinding netBinding = new NetTcpBinding();
netBinding.Security.Mode = SecurityMode.None;
//The Server Needs a Uri to start
Console.WriteLine("Starting Server...");
Uri address = new Uri(ADDRESS);
//Starts the Service
ServiceHost mainHost = new ServiceHost(typeof(Server));
mainHost.AddServiceEndpoint(typeof(IServer), netBinding, address);
//Opens the service
mainHost.Open();
Console.WriteLine("Server Running... ", mainHost.ToString());
Console.WriteLine("Press 'Q' to quit");
//Waits for command to quit
while (Console.ReadKey(true).Key != ConsoleKey.Q) { }
//Closes the service before closing the program
mainHost.Close();
}