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); }
public bool Start() { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Start"); bool result = false; try { if (_host == null) { lock (_lock) { if (_host == null) { // Host string hostName = Dns.GetHostName(); // Add the base address Type serviceType = typeof(ConfigStoreService); Uri pipeUri = new Uri(ConfigStoreManager.GetPipeName(Process.GetCurrentProcess().Id)); Log.Info(PROC, pipeUri.AbsoluteUri); // default servuce if (true) { _host = new WcfServiceHost(serviceType, null, new Uri[] { pipeUri }); Type[] interfaces = serviceType.GetInterfaces(); string serviceContractAttrString = typeof(ServiceContractAttribute).ToString(); if (interfaces != null) { foreach (Type iface in interfaces) { ServiceContractAttribute serviceContractAttr = (from c in iface.GetCustomAttributes(false) where c.ToString() == serviceContractAttrString select c).FirstOrDefault() as ServiceContractAttribute; if (serviceContractAttr != null) { // named pipe _host.AddServiceEndpoint(iface, CreateNamedPipeBinding(), pipeUri); } } } } // Mex endpoings _host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex"); Log.Info(PROC, pipeUri.AbsoluteUri + "/mex"); } } } // default service host try { if (_host != null && _host.State == CommunicationState.Created) { _host.Open(); result = true; } } catch (Exception ex) { Log.Exception(PROC, ex); } } catch (Exception ex) { Log.Exception(PROC, ex); } return(result); }
/// <summary> /// Prepares the parameters for this connector and ensures that resources exist so the <seealso cref="Start"/> operation /// succeeds. /// </summary> public void Open() { // Connection string if (ConnectionString == null) { throw new ConnectorException(ConnectorException.MSG_NULL_CONNECTION_STRING, ConnectorException.ReasonType.NullConnectionString); } else if (Formatter == null) { throw new ConnectorException(ConnectorException.MSG_NULL_FORMATTER, ConnectorException.ReasonType.NullFormatter); } Dictionary <string, List <string> > conf = ConnectionStringParser.ParseConnectionString(ConnectionString); string epAddress = string.Empty, epBinding = string.Empty, epContract = string.Empty, epBindingConfig = string.Empty; // Load List <string> tmpValues; if (conf.TryGetValue("servicename", out tmpValues)) { serviceName = tmpValues[0]; } if (conf.TryGetValue("endpointaddress", out tmpValues)) { epAddress = tmpValues[0]; } if (conf.TryGetValue("bindingtype", out tmpValues)) { epBinding = tmpValues[0]; } if (conf.TryGetValue("bindingconfig", out tmpValues)) { epBindingConfig = tmpValues[0]; } epContract = typeof(IConnectorContract).FullName; // Service host svcHost = null; if (String.IsNullOrEmpty(epAddress)) { svcHost = new WcfServiceHost(serviceName, typeof(ConnectorService)); } else { svcHost = new WcfServiceHost(null, typeof(ConnectorService)); if (!String.IsNullOrEmpty(epBindingConfig)) { svcHost.AddServiceEndpoint( epContract, epBinding == "basicHttpBinding" ? (Binding)(new BasicHttpBinding(epBindingConfig)) : epBinding == "wsHttpBinding" ? (Binding)(new WSHttpBinding(epBindingConfig)) : null, epAddress ); } else { svcHost.AddServiceEndpoint( epContract, epBinding == "basicHttpBinding" ? (Binding)(new BasicHttpBinding()) : epBinding == "wsHttpBinding" ? (Binding)(new WSHttpBinding()) : null, epAddress ); } } svcHost.ConnectorHost = this; }