public void WfcServiceHost_LillTek_Via_Factory() { // Verify that we can create a service instance and then call it // using a client proxy generated by a WcfChannelFactory using // the LillTek transport. WcfServiceHost host; ITestService client; host = new WcfServiceHost(new TestService()); try { host.AddServiceEndpoint(typeof(ITestService), "binding=lilltek;uri=lilltek.logical://wcftest"); host.ExposeServiceDescription(null, null); host.Start(); using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>("binding=lilltek;uri=lilltek.logical://wcftest")) { client = factory.CreateChannel(); using (client as IDisposable) { client.Set("Hello World!"); Assert.AreEqual("Hello World!", client.Get()); } } } finally { host.Stop(); } }
public void WfcServiceHost_Basic_Http_Via_Factory() { // Verify that we can create a service instance and then call it // using a client proxy generated by a WcfChannelFactory using // a HTTP transport. WcfServiceHost host; ITestService client; host = new WcfServiceHost(new TestService()); try { host.AddServiceEndpoint(typeof(ITestService), "binding=HTTP;uri=http://localhost:8008/Unit/Test.svc"); host.ExposeServiceDescription(null, null); host.Start(); using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>("binding=HTTP;uri=http://localhost:8008/Unit/Test.svc")) { client = factory.CreateChannel(); using (client as IDisposable) { client.Set("Hello World!"); Assert.AreEqual("Hello World!", client.Get()); } } } finally { host.Stop(); } }
public void WfcServiceHost_Http_WcfClientContext() { // Verify that we can create a service instance and then call it using WcfClientContext. WcfServiceHost host; host = new WcfServiceHost(new TestService()); try { host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>"); host.ExposeServiceDescription(null, null); host.Start(); using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>(@"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>")) using (WcfClientContext <ITestService> client = new WcfClientContext <ITestService>(factory.CreateChannel())) { client.Open(); client.Proxy.Set("Hello World!"); Assert.AreEqual("Hello World!", client.Proxy.Get()); } } finally { host.Stop(); } }
public void WfcServiceHost_Http() { // Verify that we can create a service instance and then call it. WcfServiceHost host; host = new WcfServiceHost(new TestService()); try { host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>"); host.ExposeServiceDescription(null, null); host.Start(); TestServiceClient client; client = new TestServiceClient(new WSHttpBinding(SecurityMode.None), new EndpointAddress("http://localhost:8008/Unit/Test.svc")); client.Open(); try { client.Set("Hello World!"); Assert.AreEqual("Hello World!", client.Get()); } finally { client.Close(); } } finally { host.Stop(); } }
private void StartWcfService() { if ((Settings.Instance.IsHub || Settings.Instance.UseWcf) && !wcfStopStart) { Logging.Log(LogLevelEnum.Info, "Initialize WCF service start"); serviceConnection = new WcfServiceHost <WcfService, IWcfContract>(); serviceConnection.Start(); Logging.Log(LogLevelEnum.Info, "Initialize WCF service end"); } }
protected override void OnStart(string[] args) { OnStop(); if (_wcfServiceHost == null) { _wcfServiceHost = WcfServiceHost.Create(EventLog); } _wcfServiceHost.Start(); }
public void WfcServiceHost_Verify_WSDL() { // Verify that we can obtain the service WSDL via a HTTP GET. WcfServiceHost host; string contents; HttpWebRequest request; HttpWebResponse response; StreamReader reader; host = new WcfServiceHost(new TestService()); try { host.AddServiceEndpoint(typeof(ITestService), "binding=BasicHTTP;uri=http://localhost:8008/Unit/Test.svc"); host.ExposeServiceDescription("http://localhost:8008/Unit/Test.wsdl", null); host.Start(); request = (HttpWebRequest)WebRequest.Create("http://localhost:8008/Unit/Test.wsdl"); response = null; reader = null; try { response = (HttpWebResponse)request.GetResponse(); reader = new StreamReader(response.GetResponseStream()); contents = reader.ReadToEnd(); } finally { if (reader != null) { reader.Close(); } if (response != null) { response.Close(); } } Assert.IsTrue(200 <= (int)response.StatusCode && (int)response.StatusCode <= 299); Assert.IsTrue(response.ContentType.ToUpper().StartsWith("TEXT")); Assert.IsTrue(contents.IndexOf("<wsdl:") != -1); } finally { host.Stop(); } }