서버를 시작할 때 몇 가지 연결을해야합니다. 나는이 클라이언트 - 서버 응용 프로그램에 wcf 기술을 사용하고 있습니다. 문제는 서버의 생성자가 언제든지 호출되지 않기 때문에 잠시 동안 첫 번째 클라이언트가 연결을 만들 때 연결을 초기화한다는 것입니다. 그러나 이것은 문제를 더욱 발생시킵니다.어떻게 시작시 서버를 초기화 할 수 있습니까?
이 내 서버 설정입니다 : 내가 그래서 내가 그것을 초기화 할 수 있습니다 로그온하기 위해 클라이언트를 기다리지 않고 서버를 시작할 수있는 방법
private static ServiceHost _svc;
static void Main(string[] args)
{
NetTcpBinding binding = new NetTcpBinding(SecurityMode.Message);
Uri address = new Uri("net.tcp://localhost:8000");
_svc = new ServiceHost(typeof(MonitoringSystemService), address);
publishMetaData(_svc, "http://localhost:8001");
_svc.AddServiceEndpoint(typeof(IMonitoringSystemService), binding, "Monitoring Server");
_svc.Open();
Console.WriteLine("Listener service gestart op net.tcp://localhost:8000/Monitoring");
Console.ReadLine();
}
private static void publishMetaData(ServiceHost svc, string sEndpointAddress)
{
ServiceMetadataBehavior smb = svc.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb != null)
{
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri(sEndpointAddress);
}
else
{
smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri(sEndpointAddress);
svc.Description.Behaviors.Add(smb);
}
}
.
미리 감사드립니다.
"서버의 생성자가 언제든지 호출되지 않습니다."... 어떤 생성자에 대해 이야기하고 있습니까? MonitoringSystemService? 프로그램이 시작될 때 Main 메서드가 호출됩니다. 왜 거기에 연결을 초기화하지 않습니까? –
예, MonitoringSystemService의 cunstructor를 의미합니다. MonitoringSystemService에서 연결을 호출해야하며 main 메서드에서 초기화하는 경우 액세스 할 수 없습니다. – Terry