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(); } }
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(); } }
public void WfcServiceHost_Parse_BehaviorXML() { // Verify that we can parse behavior XML. WcfServiceHost host; host = new WcfServiceHost(new TestService()); host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>"); host.ExposeServiceDescription(null, null); host.AddBehaviors( @"<behavior> <serviceSecurityAudit auditLogLocation=""Application"" suppressAuditFailure=""true"" serviceAuthorizationAuditLevel=""Success"" messageAuthenticationAuditLevel=""SuccessOrFailure"" /> <serviceThrottling maxConcurrentCalls=""121"" maxConcurrentInstances=""122"" maxConcurrentSessions=""123"" /> <serviceTimeouts transactionTimeout=""10m"" /> </behavior> "); ServiceBehaviorAttribute serviceBehavior = (ServiceBehaviorAttribute)host.Host.Description.Behaviors[typeof(ServiceBehaviorAttribute)]; ServiceSecurityAuditBehavior serviceSecurityAudit = (ServiceSecurityAuditBehavior)host.Host.Description.Behaviors[typeof(ServiceSecurityAuditBehavior)]; ServiceThrottlingBehavior serviceThrottling = (ServiceThrottlingBehavior)host.Host.Description.Behaviors[typeof(ServiceThrottlingBehavior)]; Assert.IsNotNull(serviceBehavior); Assert.IsNotNull(serviceSecurityAudit); Assert.IsNotNull(serviceThrottling); Assert.AreEqual("00:10:00", serviceBehavior.TransactionTimeout); Assert.AreEqual(AuditLogLocation.Application, serviceSecurityAudit.AuditLogLocation); Assert.IsTrue(serviceSecurityAudit.SuppressAuditFailure); Assert.AreEqual(AuditLevel.Success, serviceSecurityAudit.ServiceAuthorizationAuditLevel); Assert.AreEqual(AuditLevel.SuccessOrFailure, serviceSecurityAudit.MessageAuthenticationAuditLevel); Assert.AreEqual(121, serviceThrottling.MaxConcurrentCalls); Assert.AreEqual(122, serviceThrottling.MaxConcurrentInstances); Assert.AreEqual(123, serviceThrottling.MaxConcurrentSessions); }