private Service1Client InitializeClient() { var url = WebConfigurationManager.AppSettings["client-url"]; var serviceBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport) { MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxBufferPoolSize = int.MaxValue }; var myReaderQuotas1 = new XmlDictionaryReaderQuotas { MaxStringContentLength = int.MaxValue, MaxDepth = int.MaxValue, MaxArrayLength = int.MaxValue, MaxBytesPerRead = int.MaxValue, MaxNameTableCharCount = int.MaxValue }; serviceBinding.GetType().GetProperty("ReaderQuotas").SetValue(serviceBinding, myReaderQuotas1, null); var client = new Service1Client(serviceBinding, new EndpointAddress(url)); var debugBehavior = _resolver.Resolve <IEndpointBehavior>(); client.Endpoint.EndpointBehaviors.Add(debugBehavior); return(client); //((ClientBase<ResourceSchedulerServiceSoap>)_resourceSchedulerClient).Endpoint.EndpointBehaviors.Add(new TracingMessageBehavior()); }
public static void Main(string[] args) { Console.WriteLine("Starting test service..."); var binding = new BasicHttpBinding(); //var binding = new NetTcpBinding(); var baseAddress = new Uri("http://localhost:8090"); //var endpointAddress = new Uri("net.tcp://localhost:1111"); var endpointAddress = new Uri("http://localhost:8090"); // ---- ServiceHost & adding endpoints... var host = new ServiceHost(typeof(TestService), baseAddress); host.AddServiceEndpoint(typeof(ITestService), binding, endpointAddress); // Add the MEX var smb = host.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (smb == null) { smb = new ServiceMetadataBehavior(); host.Description.Behaviors.Add(smb); } smb.HttpGetEnabled = true; host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); host.Open(); Console.WriteLine("Testing the connection using {0}...", binding.GetType().Name); var sw = new Stopwatch(); sw.Start(); var channelFactory = new ChannelFactory <ITestService>(binding, new EndpointAddress(endpointAddress)); var channel = channelFactory.CreateChannel(); for (int i = 0; i < 5; i++) { Console.WriteLine("Connecting..."); Console.WriteLine(channel.GetTime()); } channelFactory.Close(); sw.Stop(); Console.WriteLine("Took {0}ms", sw.ElapsedMilliseconds); Console.WriteLine("Type [Enter] to stop..."); Console.ReadLine(); host.Close(); }
/// <summary> /// Initialize a basic http binding with /// - transport security mode /// - maxed-out request/response buffer sizes /// - Client credential type/proxy credential type - windows /// - Message credential type - username /// - Message algo suite - default /// </summary> private IService1 InitializeHttpClient() { var serviceBinding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly) { MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxBufferPoolSize = int.MaxValue, Security = new BasicHttpSecurity { Mode = BasicHttpSecurityMode.TransportCredentialOnly, Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.Windows, ProxyCredentialType = HttpProxyCredentialType.Windows, Realm = string.Empty, }, Message = new BasicHttpMessageSecurity { AlgorithmSuite = SecurityAlgorithmSuite.Default, ClientCredentialType = BasicHttpMessageCredentialType.UserName }, }, }; var myReaderQuotas1 = new XmlDictionaryReaderQuotas { MaxStringContentLength = int.MaxValue, MaxDepth = int.MaxValue, MaxArrayLength = int.MaxValue, MaxBytesPerRead = int.MaxValue, MaxNameTableCharCount = int.MaxValue }; var url = WebConfigurationManager.AppSettings["client-url"]; serviceBinding.GetType().GetProperty("ReaderQuotas").SetValue(serviceBinding, myReaderQuotas1, null); ChannelFactory <IService1> factory = new ChannelFactory <IService1>(serviceBinding, new EndpointAddress(url)); factory.Endpoint.Behaviors.Add(_resolver.Resolve <IEndpointBehavior>()); IService1 channel = factory.CreateChannel(); return(channel); }