public void should_add_the_servicebehavior_to_the_behavior_collection() { var host = new WebServiceHost(typeof(FakeService), new[] { new Uri("net.tcp://localhost:8081") }); host.AddServiceEndpoint(typeof(IFakeService), new NetTcpBinding(), "net.tcp://localhost:8081/MyService"); host.Open(); host.Description.Behaviors.ShouldContainType<ServiceBehavior>(); host.Close(); }
public void SetUp() { webServiceHost = new WebServiceHost(typeof(TestService), new Uri(BASE_URL)); WebHttpBinding httpBinding1 = new WebHttpBinding(); httpBinding1.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly; httpBinding1.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; webServiceHost.AddServiceEndpoint(typeof(TestService), httpBinding1, "/basic"); webServiceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; webServiceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustomUserNamePasswordValidator(); webServiceHost.Open(); }
private void SimpleForm_Load(object sender, EventArgs e) { var host = new WebServiceHost(typeof(CertificateService), new Uri("http://localhost:8000/")); try { host.AddServiceEndpoint(typeof(ICertificateService), new WebHttpBinding(), ""); host.Open(); } catch (CommunicationException cex) { host.Abort(); MessageBox.Show(cex.Message, "Exception occurred", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { WebServiceHost host = new WebServiceHost(typeof(ImageGenerationService), new Uri("http://localhost:8000")); host.AddServiceEndpoint(typeof(ImageGenerationService), new WebHttpBinding(), ""); host.Open(); Console.WriteLine("This output of this sample is intended to be viewed in a web browser."); Console.WriteLine("To interact with this sample, navigate to the following URL's while this program is running: "); Console.WriteLine(" http://localhost:8000/images?text=Hello, world!"); Console.WriteLine(" http://localhost:8000/text?text=Hello, world!"); Console.WriteLine("Open!"); Console.ReadLine(); }
public void ServiceDebugBehaviorTest() { var host = new WebServiceHost(typeof(MyService), new Uri("http://localhost:8080/")); ServiceEndpoint webHttp = host.AddServiceEndpoint("MonoTests.System.ServiceModel.Web.WebServiceHostTest+MyService", new WebHttpBinding(), "WebHttpBinding"); Assert.AreEqual(true, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageEnabled, "HttpHelpPageEnabled #1"); Assert.AreEqual(true, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpsHelpPageEnabled, "HttpsHelpPageEnabled #1"); host.Open(); Assert.AreEqual(false, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageEnabled, "HttpHelpPageEnabled #2"); Assert.AreEqual(false, host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpsHelpPageEnabled, "HttpsHelpPageEnabled #2"); host.Close(); }
public static void StartService() { PersonInfoQueryService service = new PersonInfoQueryService(); Uri bassAddress = new Uri("http://127.0.0.1:7789/"); using (WebServiceHost serviceHost = new WebServiceHost(service, bassAddress)) { try { const int MAX_BUFFER = 20971520; var binding = new WebHttpBinding(); binding.TransferMode = TransferMode.Buffered; binding.MaxBufferSize = MAX_BUFFER; binding.MaxReceivedMessageSize = MAX_BUFFER; binding.MaxBufferPoolSize = MAX_BUFFER; binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; binding.Security.Mode = WebHttpSecurityMode.None; serviceHost.AddServiceEndpoint(typeof(IPersonInfoQuery), binding, bassAddress); //跨域 var crossOriginBehavior = new EnableCrossOriginResourceSharingBehavior(); foreach (ServiceEndpoint endpoint in serviceHost.Description.Endpoints) { endpoint.Behaviors.Add(crossOriginBehavior); } serviceHost.Opened += (s, e) => { Console.WriteLine("服务已开启...http://127.0.0.1:7789/"); }; serviceHost.Closed += (s, e) => { Console.WriteLine("服务已停止..."); }; serviceHost.Open(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("any key exit..."); Console.ReadKey(); } }
// It is not working with mono! public static void Main() { string url = "http://localhost:8080/"; WebHttpBinding b = new WebHttpBinding(); var host = new WebServiceHost(typeof(MyService), new Uri(url)); ServiceEndpoint se = host.AddServiceEndpoint("MyService", b, ""); se.Behaviors.Add(new WebHttpBehavior() { DefaultBodyStyle = WebMessageBodyStyle.WrappedResponse }); host.Open(); Console.WriteLine("--- enter ---"); Console.ReadLine(); host.Close(); }
//TODO: // Currently the only way to make this work is to run the program as an administrator, or before it is // launched, typw the following into an ADMINISTRATIVE Command Prompt: // netsh http add urlacl url=http://+:9090/ user="******" sddl="D:(A;;GX;;;AU)" // I need to figure out if the Install Sheild project can do this automatically // The above TODO has been completed as install events in the installer package. public void startNetworkService() { host = new WebServiceHost(typeof(NetworkControlService), baseAddress); ServiceEndpoint ep = host.AddServiceEndpoint(typeof(INetworkControlService), new WebHttpBinding(), ""); ServiceDebugBehavior stp = host.Description.Behaviors.Find <ServiceDebugBehavior>(); stp.HttpHelpPageEnabled = false; // Open the ServiceHost to start listening for messages. Since // no endpoints are explicitly configured, the runtime will create // one endpoint per base address for each service contract implemented // by the service. host.Open(); }
public WCFServer(string uri) { var host = new WebServiceHost(typeof(WebService), new Uri(uri)); try { var ep = host.AddServiceEndpoint(typeof(IWebService), CreateBinding(), ""); host.Open(); Console.WriteLine("WCF: OK"); } catch (CommunicationException cex) { Console.WriteLine("An exception occurred: {0}", cex.Message); host.Abort(); } }
private void StartHealthCheckMonitor() { if (serviceHost != null) { serviceHost.Close(); } serviceHost = new ServiceHost(typeof(BootstrapService)); serviceHost.Open(); string httpEndPoint = ConfigurationManager.AppSettings["HttpEndPoint"]; _healthCheckServiceHost = new WebServiceHost(new NancyWcfGenericService(), new Uri(httpEndPoint)); _healthCheckServiceHost.AddServiceEndpoint(typeof(NancyWcfGenericService), new WebHttpBinding(), ""); _healthCheckServiceHost.Open(); }
private static void StartElevationService() { string url = $"{SCHEME}://{HOST}:{PORT}/{PATH}"; var binding = new WebHttpBinding(); var webServiceHost = new WebServiceHost(typeof(ElevationServiceHost)); webServiceHost.AddServiceEndpoint(typeof(ElevationServiceHost), binding, url); webServiceHost.Open(); Console.WriteLine("Listening on {0}", url); logger.Info("Listening on {0}", url); Console.WriteLine("Press enter to stop service"); Console.ReadLine(); webServiceHost.Close(); Console.WriteLine("Service stopped"); logger.Info("Service stopped"); }
static void Main(string[] args) { WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/")); ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), ""); host.Open(); using (ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), "http://localhost:8000")) { cf.Endpoint.Behaviors.Add(new WebHttpBehavior()); IService channel = cf.CreateChannel(); string s; s = channel.GetUsers(); } host.Close(); }
public void Iniciar(string uriString) { try { var service = new Service(); host = new WebServiceHost(service, new Uri(uriString)); host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), ""); host.Open(); } catch (Exception e) { Console.WriteLine("Error: " + e); throw; } }
public static void Main(string[] args) { WebServiceHost host = null; try { var n = int.TryParse(args[0], out ArcService.N); if (!n || ArcService.N < 1 || ArcService.N > 9) { throw new Exception("Argument N Incorrect"); } var baseAddress = new Uri($"http://localhost:{ArcService.PortFor()}/"); host = new WebServiceHost(typeof(ArcService), baseAddress); ServiceEndpoint ep = host.AddServiceEndpoint(typeof(INodeService), new WebHttpBinding(), ""); host.Open(); // http://localhost:8090/message?from=1,to=0,msg=... var msg = ($"Arc=0: {baseAddress}Message?from=?,to=?,msg=?"); Console.Error.WriteLine(msg); Console.WriteLine(msg); ArcService.MessageQueue[1] = Enumerable.Range(1, ArcService.N) .Select(I => new Message(0, 0, I, "+")) .ToList(); var msgloop = ArcService.MessageLoop(); msgloop.Wait(); //Console.Error.WriteLine ("Press <Enter> to stop the service."); //Console.ReadLine (); //ArcService.Done.WaitOne (); host.Close(); } catch (Exception ex) { var msg = ($"*** Exception {ex.Message}"); Console.Error.WriteLine(msg); Console.WriteLine(msg); host = null; } finally { if (host != null) { ((IDisposable)host).Dispose(); } } }
static void Main(string[] args) { //根据服务类,以及基地址来初始化一个服务宿主 WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("Http://localhost:8000/")); try { //初始化服务终结点,切记绑定的协议为WebHttpBinding ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), ""); host.Open(); using (ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), "http://localhost:8000")) { //添加一个服务的终结点行为---WebHttpBehavior实例 cf.Endpoint.EndpointBehaviors.Add(new WebHttpBehavior()); IService channel = cf.CreateChannel(); string s; Console.WriteLine("Calling EchoWithGet via HTTP GET:"); s = channel.EchoWithGet("Hello,world"); Console.WriteLine(" OutPut:{0}", s); Console.WriteLine("----------------------------------"); Console.WriteLine("This can also be accomplished by navigating to"); Console.WriteLine("http://localhost:8000/EchoWithGet?s=Hello, world!"); Console.WriteLine("in a web browser while this sample is running."); Console.WriteLine("----------------------------------"); Console.WriteLine("Calling EchoWithPost via HTTP POST: "); s = channel.EchoWithPost("Hello, world"); Console.WriteLine(" Output: {0}", s); Console.WriteLine(""); Console.WriteLine("Press <ENTER> to terminate"); Console.ReadLine(); } } catch (CommunicationException cex) { Console.WriteLine("An exception occurred: {0}", cex.Message); host.Abort(); } finally { host.Close(); } }
public static void OpenConnection() { host = new WebServiceHost(typeof(Service), new Uri("http://127.0.0.1:8000/")); try { ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), string.Empty); host.Open(); ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), "http://127.0.0.1:8000"); cf.Endpoint.EndpointBehaviors.Add(new WebHttpBehavior()); IService channel = cf.CreateChannel(); } catch (CommunicationException ex) { Console.WriteLine("An exception occurred: {0}", ex.Message); host.Abort(); } }
static void Main(string[] args) { //*========================================================== //* CODE REVIEW : See Interfaces\MockAPIMainProcess() for Processing //*========================================================== WebServiceHost hostWeb = new WebServiceHost(typeof(MockAPIMainProcess)); ServiceEndpoint ep = hostWeb.AddServiceEndpoint(typeof(IMockAPISummary), new WebHttpBinding(), ""); ServiceDebugBehavior stp = hostWeb.Description.Behaviors.Find <ServiceDebugBehavior>(); stp.HttpHelpPageEnabled = false; hostWeb.Open(); Console.WriteLine("Sample API Service started @ " + DateTime.Now.ToString()); Console.WriteLine("URI: http://localhost.com:8080/summary"); Console.Read(); }
private static void Main() { Console.Write("Your Service Namespace Domain (ex. https://<DOMAIN>.servicebus.windows.net/): "); string serviceNamespaceDomain = Console.ReadLine(); // By setting EndToEndWebHttpSecurityMode.Transport we use HTTPS. // If you want to use HTTP please set EndToEndWebHttpSecurityMode.None. // In this sample we need to authenticate client via Access Control Service so // RelayClientAuthenticationType.RelayAccessToken is set. You can set RelayClientAuthenticationType.None // If you don't want to authenticate client via Access Control Service. WebHttpRelayBinding binding = new WebHttpRelayBinding(EndToEndWebHttpSecurityMode.Transport, RelayClientAuthenticationType.RelayAccessToken); // Replace above code with the following one to test in browser // WebHttpRelayBinding binding = new WebHttpRelayBinding(EndToEndWebHttpSecurityMode.Transport, RelayClientAuthenticationType.None); // Initialize ServiceHost using custom binding Uri address = ServiceBusEnvironment.CreateServiceUri("https", serviceNamespaceDomain, "DataService"); WebServiceHost host = new WebServiceHost(typeof(NorthwindDataService), address); host.AddServiceEndpoint("System.Data.Services.IRequestHandler", binding, address); var eb = new TransportClientEndpointBehavior() { CredentialType = TransportClientCredentialType.SharedSecret }; eb.Credentials.SharedSecret.IssuerName = "owner"; eb.Credentials.SharedSecret.IssuerSecret = "[Your Secret]"; host.Description.Endpoints[0].Behaviors.Add(eb); // The following behavior is used to work around exception caused by PUT/POST // requests when exposing via Service Bus MyBehavior mb = new MyBehavior(); host.Description.Endpoints[0].Behaviors.Add(mb); // Start service host.Open(); Console.WriteLine("Test the following URI in browser: "); Console.WriteLine(address + "Customers"); Console.WriteLine("Use the following URI if you want to generate client proxy for this service"); Console.WriteLine(address); Console.WriteLine(); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); host.Close(); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. _webServiceHost = new WebServiceHost(typeof(YoutubeFeed)); _webServiceHost.AddServiceEndpoint( typeof(IYoutubeFeed), new WebHttpBinding(), new Uri($"http://{RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["SyndicationEndpoint"].IPEndpoint}/FeedService")); _webServiceHost.Open(); return(base.OnStart()); }
static void Main(string[] args) { Thread thread = new Thread(new ThreadStart(SocketPhoto.SERVICE)); thread.Start(); RestDemoServices DemoServices = new RestDemoServices(); WebHttpBinding binding = new WebHttpBinding(); WebHttpBehavior behavior = new WebHttpBehavior(); WebServiceHost _serviceHost = new WebServiceHost(DemoServices, new Uri("http://localhost:8008/DEMOService")); _serviceHost.AddServiceEndpoint(typeof(IRESTDemoServices), binding, ""); _serviceHost.Open(); Console.ReadKey(); _serviceHost.Close(); }
public void Start() { try { m_Host = new WebServiceHost(m_restApi, m_baseUri); ServiceEndpoint ep = m_Host.AddServiceEndpoint(m_restApi.GetType(), new WebHttpBinding(), ""); ServiceDebugBehavior stp = m_Host.Description.Behaviors.Find <ServiceDebugBehavior>(); stp.HttpHelpPageEnabled = false; m_Host.Open(); Console.WriteLine(string.Format("Host started at {0}", m_baseUri)); } catch (Exception ex) { Console.WriteLine(string.Format("Starting host failed for {0}\n{1}", m_baseUri, ex)); } }
private void StartWebService() { try { if (config == null) { config = new Config(); } config.ReadConfig(); string port = config.ServicePort; h.WriteToLog("Listening on port" + port); // THESE LINES FOR HTTPS //Uri httpsUrl = new Uri("https://0.0.0.0:" + port + "/"); //host = new WebServiceHost(typeof(WebService), httpsUrl); //WebHttpBinding binding = new WebHttpBinding(); //binding.Security.Mode = WebHttpSecurityMode.Transport; //binding.MaxReceivedMessageSize = 1024 * 1024; // 1 MB // this is for basic auth // binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; //System.ServiceModel.Description.ServiceCredentials sc = new ServiceCredentials(); //sc.UserNameAuthentication.UserNamePasswordValidationMode = System.ServiceModel.Security.UserNamePasswordValidationMode.Custom; //customUserNameValidator = new CustomUserNameValidator(); //sc.UserNameAuthentication.CustomUserNamePasswordValidator = customUserNameValidator; // THIS IS FOR NORMAL HTTP Uri httpUrl = new Uri("http://localhost:" + port + "/"); host = new WebServiceHost(typeof(WebService), httpUrl); var binding = new WebHttpBinding(); // NetTcpBinding(); binding.MaxReceivedMessageSize = int.MaxValue; host.AddServiceEndpoint(typeof(iContract), binding, ""); ServiceDebugBehavior stp = host.Description.Behaviors.Find <ServiceDebugBehavior>(); stp.HttpHelpPageEnabled = true; // probably remove for prod stp.HttpsHelpPageEnabled = true; stp.IncludeExceptionDetailInFaults = true; host.Open(); } catch (Exception e) { eventLog1.WriteEntry("Error in StartWebService" + e.Message); } }
/// <summary> /// This function will initialize the publishing services. search server will not run if /// those services didn't initialize correctly. /// </summary> /// <param name="clientPort">Port for client publishing server</param> /// <param name="sellerPort">Port for sellers registration publishing server</param> public void Initialize(string clientPort, string sellerPort, string logFileName) { tsrHost = new WebServiceHost(typeof(AirSellerRegisteration), new Uri(@"http://*****:*****@"/Services/FlightsSearchReg")); cqsHost = new WebServiceHost(typeof(ClientQueryService), new Uri(@"http://*****:*****@"/Services")); // ServiceEndpoint regEndPoint = tsrHost.AddServiceEndpoint(typeof(IAirSellerRegisteration), new WebHttpBinding(), @"http://*****:*****@"/Services/FlightsSearchReg"); ServiceEndpoint sellerEndPoint = cqsHost.AddServiceEndpoint(typeof(IClientQueryService), new WebHttpBinding(), @"http://*****:*****@"/Services/FlightsSearch"); ExOpBehavior logBehavior = new ExOpBehavior(logFileName); foreach (OperationDescription description in sellerEndPoint.Contract.Operations) { if (description.Name.Equals("GetFlights")) { description.Behaviors.Add(logBehavior); } } isInitialized = true; }
public static void Main() { var host = new WebServiceHost(typeof(HogeService)); /* * host.Description.Behaviors.Add ( * new ServiceMetadataBehavior () { HttpGetEnabled = true, * HttpGetUrl = new Uri ("http://localhost:8080/HogeService/wsdl") }); */ var binding = new WebHttpBinding(); host.AddServiceEndpoint(typeof(IHogeService), binding, "http://localhost:8080"); host.Open(); Console.WriteLine("Type [CR] to close"); Console.ReadLine(); host.Close(); }
public static void Main() { Service handler = new Service(); Uri serviceUri = new Uri(ConfigurationManager.AppSettings["ListenAddress"]); WebServiceHost host = new WebServiceHost(handler, serviceUri); WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.Transport) { HostNameComparisonMode = HostNameComparisonMode.Exact, MaxReceivedMessageSize = int.MaxValue, }; var endpoint = host.AddServiceEndpoint(handler.GetType(), binding, string.Empty); host.Open(); }
/* Methods */ private WebServiceHost GetServiceHost(Uri serviceUri, Type serviceType, Type contractType) { var wsHost = new WebServiceHost(serviceType, serviceUri); var wsBehaviour = new ServiceMetadataBehavior(); wsHost.AddServiceEndpoint(contractType, new WebHttpBinding(), serviceUri); wsBehaviour.HttpGetEnabled = false; wsHost.Description.Behaviors.Add(wsBehaviour); ServiceDebugBehavior wsDebugBehaviour = wsHost.Description.Behaviors.Find <ServiceDebugBehavior>(); wsDebugBehaviour.HttpHelpPageEnabled = false; wsHost.Open(); return(wsHost); }
void CreateResponseTest(Action <IHogeService> a) { var host = new WebServiceHost(typeof(HogeService)); host.AddServiceEndpoint(typeof(IHogeService), new WebHttpBinding(), new Uri("http://localhost:37564")); host.Description.Behaviors.Find <ServiceDebugBehavior> ().IncludeExceptionDetailInFaults = true; host.Open(); try { using (var cf = new ChannelFactory <IHogeService> (new WebHttpBinding(), new EndpointAddress("http://localhost:37564"))) { cf.Endpoint.Behaviors.Add(new WebHttpBehavior()); cf.Open(); var ch = cf.CreateChannel(); a(ch); } } finally { host.Close(); } }
public static void Main() { // Initialize Module List : if (!ModuleManager.Instance.Load()) { Console.WriteLine("Loading module failed"); } string url = "http://localhost:8080/"; WebHttpBinding b = new WebHttpBinding(); WebServiceHost host = new WebServiceHost(typeof(CommandService), new Uri(url)); host.AddServiceEndpoint(typeof(ICommandService), b, ""); host.Open(); Console.WriteLine("--- type [CR] to quit ---"); Console.ReadLine(); host.Close(); }
private static void Main(string[] args) { PostAppInit.Do(); using (WebServiceHost host = new WebServiceHost( new NancyWcfGenericService(), new Uri(HostSetting.Default.WebHostAddress))) { host.AddServiceEndpoint( typeof(NancyWcfGenericService), new WebHttpBinding(), ""); host.Open(); Console.ReadLine(); host.Close(); } }
public static void OpenService(Type serviceType) { host = new WebServiceHost(serviceType, new Uri(ConfigurationManager.AppSettings["OsoFx.LogServiceUrl"])); try { // Start WCF REST Service ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IWebManagementLog), new WebHttpBinding(), ""); host.Description.Behaviors.Find <ServiceDebugBehavior>().HttpHelpPageEnabled = false; host.Open(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
private static void Main(string[] args) { while (true) { WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:9000/")); try { ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), ""); host.Open(); using (ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), "http://localhost:9000")) { cf.Endpoint.Behaviors.Add(new WebHttpBehavior()); IService channel = cf.CreateChannel(); Console.WriteLine("Calling AccountBalance via HTTP GET: "); var results = channel.AccountBalance(); Console.WriteLine(" Output: {0}", results); Console.WriteLine(""); Console.WriteLine("This can also be accomplished by navigating to"); Console.WriteLine("http://localhost:9000/AccountBalance"); Console.WriteLine("Calls with parameters can be done like..."); Console.WriteLine("http://localhost:9000/SymbolInfoTick?symbol=EURUSD"); Console.WriteLine("in a web browser while this sample is running."); Console.WriteLine(""); } Console.WriteLine("Press <ENTER> to terminate"); Console.ReadLine(); host.Close(); break; } catch (CommunicationException cex) { Console.WriteLine("An exception occurred: {0}", cex.Message); host.Abort(); Console.WriteLine("Restarting........"); //Console.ReadLine(); } } }