예제 #1
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()
        {
            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);

            // Enable metadata publishing
            var smb = new ServiceMetadataBehavior
            {
                HttpGetEnabled = true,
                MetadataExporter = { PolicyVersion = PolicyVersion.Policy15 }
            };
            serviceHost.Description.Behaviors.Add(smb);

            // 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 PhoneAutomationController(phoneAutomationService, AutomationIdentification);
            _serviceHost = serviceHost;
        }