public override void Start() { WebHttpBinding binding = new WebHttpBinding(); binding.MaxReceivedMessageSize = 1024*1024; _singletonInstance = new SourceService(); _singletonInstance.LogGenerator += _singletonInstance_LogGenerator; _singletonInstance.Scenario = Scenario; _host = new WebServiceHost(_singletonInstance); _host.UnknownMessageReceived += _host_UnknownMessageReceived; binding.CrossDomainScriptAccessEnabled = true; if(!AllowRemoteConnections) binding.HostNameComparisonMode = HostNameComparisonMode.Exact; //AppendHeader("Access-Control-Allow-Origin", "*"); ServiceEndpoint endpoint = _host.AddServiceEndpoint(typeof(SourceService), binding, string.Format("http://localhost:{0}/", _port)); endpoint.Behaviors.Add(new ReplyFormatSwitchBehaviour()); endpoint.Behaviors.Add(new EnableCrossOriginResourceSharingBehavior()); // int sslPort = _port + 1000; // endpoint = _host.AddServiceEndpoint(typeof(SourceService), binding, string.Format("https://localhost:{0}/", sslPort)); // endpoint.Behaviors.Add(new ReplyFormatSwitchBehaviour()); try { Running = false; _host.Open(); Log("Veneer, by Flow Matters: http://www.flowmatters.com.au"); Log(string.Format("Started Source RESTful Service on port:{0}", _port)); Running = true; } catch (AddressAlreadyInUseException) { _port++; // Keep retrying until we run out of allocated ports Start(); } catch (AddressAccessDeniedException) { Log(String.Format("For details, see: https://github.com/flowmatters/veneer")); if (AllowRemoteConnections) { Log("If you require external connections, you must select a port where Veneer has permissions to accept external connections."); Log( String.Format( "Veneer does not have permission to accept external (ie non-local) connections on port {0}", _port)); } else { Log("Alternatively, enable 'Allow Remote Connections' and restart Veneer."); Log("To establish a local-only connection, select a port where Veneer is NOT registered for external connections."); Log(String.Format( "This is most likely because Veneer is registered to accept external/non-local connections on port {0}.", _port)); Log(String.Format( "Veneer does not have permission to accept local-only connections on port {0}", _port)); } Log(String.Format("COULD NOT START VENEER ON PORT {0}",_port)); } catch (Exception e) { Log("COULD NOT START VENEER"); Log(e.Message); Log(e.StackTrace); } _host.Faulted += _host_Faulted; }