void StartProxy(object startParameters) { try { SimulatorStartParameters parameters = (SimulatorStartParameters)startParameters; InitializeProxies(parameters); foreach (ServiceProxy proxy in _proxies) { proxy.Start(); } if (Started != null) { Started(); } } catch (Exception exc) { foreach (ServiceProxy proxy in _proxies) { if (proxy.Started) { proxy.Stop(); } } if (StartFailed != null) { StartFailed(exc.Message); } } }
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(); } }
void InitializeProxies(SimulatorStartParameters parameters) { _proxies = new List <ServiceProxy>(); string deviceAddress = parameters.IPAddress + "onvif/device_service/"; DeviceServiceProxy deviceProxy = new DeviceServiceProxy(deviceAddress, parameters.DeviceAddress); deviceProxy.DataTransmitted += new NetworkEvent(Proxy_DataTransmitted); _proxies.Add(deviceProxy); // // initialize other proxies // CustomBinding custombindingSoap12 = new CustomBinding(); custombindingSoap12.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8)); custombindingSoap12.Elements.Add(new HttpTransportBindingElement()); Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add(OnvifService.DEVICE, deviceAddress); DeviceClient deviceClient = new DeviceClient(custombindingSoap12, new EndpointAddress(parameters.DeviceAddress)); Service[] services; try { services = deviceClient.GetServices(false); } catch (FaultException exc) { deviceClient.Close(); deviceClient = new DeviceClient(custombindingSoap12, new EndpointAddress(parameters.DeviceAddress)); deviceClient.Endpoint.Behaviors.Add(new Transport.SecurityBehavior() { UserName = parameters.Username, Password = parameters.Password }); services = deviceClient.GetServices(false); } deviceClient.Close(); foreach (Service service in services) { string localAddress = string.Empty; switch (service.Namespace) { case OnvifService.ACCESSCONTROL: localAddress = "onvif/access_control/"; break; case OnvifService.DOORCONTROL: localAddress = "onvif/door_control/"; break; } if (!string.IsNullOrEmpty(localAddress)) { string address = parameters.IPAddress + localAddress; ServiceProxy proxy = new ServiceProxy(address, service.XAddr); proxy.DataTransmitted += new NetworkEvent(Proxy_DataTransmitted); _proxies.Add(proxy); replacements.Add(service.Namespace, address); } } deviceProxy.SetReplacements(replacements); }
public void Start(SimulatorStartParameters parameters) { System.Threading.Thread thread = new Thread(new ParameterizedThreadStart(StartProxy)); thread.Start(parameters); //StartProxy(parameters); }