Esempio n. 1
0
        public void Start(SimulatorStartParameters parameters)
        {
            _totalLog = new List <RequestProcessingLog>();

            ServiceConfiguration configuration = new ServiceConfiguration();

            configuration.BaseAddress = parameters.IPAddress;

            CustomBinding custombindingSoap12 = ServiceBinding();

            // update simulator configuration
            BaseService.UpdateConfiguration(parameters.SimulatorConfiguration);

            _deviceService.UpdateParameters(configuration);
            _deviceServiceHost = new ServiceHost(_deviceService, new Uri(parameters.IPAddress + _deviceService.GetLocalAddress()));
            _deviceServiceHost.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
            ServiceEndpoint deviceEndpoint = _deviceServiceHost.AddServiceEndpoint(typeof(Onvif.Device), custombindingSoap12, String.Empty);

            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();

            behavior.HttpGetEnabled   = true;
            behavior.HttpGetUrl       = deviceEndpoint.ListenUri;
            behavior.MetadataExporter = new WsdlExporter();
            _deviceServiceHost.Description.Behaviors.Add(behavior);
            //_deviceServiceHost.AddServiceEndpoint(typeof(IMetadataExchange),
            //                                      MetadataExchangeBindings.CreateMexHttpBinding(), "/mex/");


            _doorControlService.UpdateParameters(configuration);
            _doorControlServiceHost = new ServiceHost(_doorControlService, new Uri(parameters.IPAddress + _doorControlService.GetLocalAddress()));
            _doorControlServiceHost.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
            ServiceEndpoint doorEndpoint = _doorControlServiceHost.AddServiceEndpoint(typeof(Onvif.DoorControlPort), custombindingSoap12, String.Empty);

            _accessControlService.UpdateParameters(configuration);
            _accessControlServiceHost = new ServiceHost(_accessControlService, new Uri(parameters.IPAddress + _accessControlService.GetLocalAddress()));
            _accessControlServiceHost.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
            ServiceEndpoint accessControlEndpoint = _accessControlServiceHost.AddServiceEndpoint(typeof(Onvif.PACSPort), custombindingSoap12, String.Empty);


            if (parameters.AuthenticationMode == AuthenticationMode.WS)
            {
                Transport.Security.UsersList.Current.AddUser(parameters.Username, parameters.Password);

                Transport.Security.SecurityBehavior security = new Transport.Security.SecurityBehavior(_logger);

                deviceEndpoint.Behaviors.Add(security);
                doorEndpoint.Behaviors.Add(security);
                accessControlEndpoint.Behaviors.Add(security);
            }

            _deviceServiceHost.Open();
            _doorControlServiceHost.Open();
            _accessControlServiceHost.Open();

            _running = true;
            if (Started != null)
            {
                Started();
            }
        }