예제 #1
0
 public void Stop()
 {
     _automationController = null;
     if (_serviceHost != null)
     {
         InvokeTrace("closing host");
         _serviceHost.Close();
         InvokeTrace("host closed");
         _serviceHost = null;
     }
 }
예제 #2
0
        public void Start(Uri bindingAddress)
        {
            if (_serviceHost != null)
            {
                throw new InvalidOperationException("_serviceHost already started");
            }

            if (_automationController != null)
            {
                throw new InvalidOperationException("_automationController already created");
            }

            InvokeTrace("building host...");

            // build the service
            var phoneAutomationService = new PhoneAutomationService();

            phoneAutomationService.Trace += (sender, args) => InvokeTrace(args);
            var serviceHost = new ServiceHost(phoneAutomationService, bindingAddress);

            if (!IsRunningOnMono())
            {
                // Enable metadata publishing
                var smb = new ServiceMetadataBehavior
                {
                    HttpGetEnabled   = true,
                    MetadataExporter = new WsdlExporter()
#if !MONO
                    {
                        PolicyVersion = PolicyVersion.Policy15
                    }
#endif //!MONO
                };
                serviceHost.Description.Behaviors.Add(smb);
            }

            if (!IsRunningOnMono())
            {
                // build SOAP ServiceEndpoint
                serviceHost.AddServiceEndpoint(
                    typeof(IPhoneAutomationService),
                    GetHttpBinding(),
                    bindingAddress + "/automate");
            }

            // build JSON ServiceEndpoint
            var jsonServiceEndpoint = serviceHost.AddServiceEndpoint(
                typeof(IPhoneAutomationService),
                GetWebHttpBinding(),
                bindingAddress + "/jsonAutomate");
            var webHttpBehavior = new WebHttpBehavior()
            {
                DefaultOutgoingRequestFormat  = WebMessageFormat.Json,
                DefaultOutgoingResponseFormat = WebMessageFormat.Json,
                DefaultBodyStyle = WebMessageBodyStyle.Wrapped
            };

            jsonServiceEndpoint.Behaviors.Add(webHttpBehavior);

            // open the host
            InvokeTrace("opening host...");
            serviceHost.Open();
            InvokeTrace("host open");

            _automationController = new ApplicationAutomationController(phoneAutomationService, AutomationIdentification);
            _serviceHost          = serviceHost;
        }
        public void Start(Uri bindingAddress)
        {
            if (_serviceHost != null)
                throw new InvalidOperationException("_serviceHost already started");

            if (_automationController != null)
                throw new InvalidOperationException("_automationController already created");

            InvokeTrace("building host...");

            // build the service
            var phoneAutomationService = new PhoneAutomationService();
            phoneAutomationService.Trace += (sender, args) => InvokeTrace(args);
            var serviceHost = new ServiceHost(phoneAutomationService, bindingAddress);

            if (!IsRunningOnMono())
            {
                // Enable metadata publishing
                var smb = new ServiceMetadataBehavior
                    {
                        HttpGetEnabled = true,
                        MetadataExporter = new WsdlExporter 
#if !MONO
                            {PolicyVersion = PolicyVersion.Policy15}
#endif
                        //!MONO
                    };
                serviceHost.Description.Behaviors.Add(smb);
            }

            if (!IsRunningOnMono())
            {
                // build SOAP ServiceEndpoint
                serviceHost.AddServiceEndpoint(
                    typeof (IPhoneAutomationService),
                    GetHttpBinding(),
                    bindingAddress + "/automate");
            }

            // build JSON ServiceEndpoint
            var jsonServiceEndpoint = serviceHost.AddServiceEndpoint(
                typeof (IPhoneAutomationService),
                GetWebHttpBinding(),
                bindingAddress + "/jsonAutomate");
            var webHttpBehavior = new WebHttpBehavior
                {
                    DefaultOutgoingRequestFormat = WebMessageFormat.Json,
                    DefaultOutgoingResponseFormat = WebMessageFormat.Json,
                    DefaultBodyStyle = WebMessageBodyStyle.Wrapped
                };
            jsonServiceEndpoint.Behaviors.Add(webHttpBehavior);

            // open the host
            InvokeTrace("opening host...");
            serviceHost.Open();
            InvokeTrace("host open");

            _automationController = new ApplicationAutomationController(phoneAutomationService, AutomationIdentification);
            _serviceHost = serviceHost;
        }
 public void Stop()
 {
     _automationController = null;
     if (_serviceHost != null)
     {
         InvokeTrace("closing host");
         _serviceHost.Close();
         InvokeTrace("host closed");
         _serviceHost = null;
     }
 }