public static SGDatabase_HClient CreateSGDatabase_HClient() { WSHttpBinding BINDING = new WSHttpBinding(); WcfClientConfig.ReadBindingConfig(BINDING, "WSHttpBinding_SGDatabase_H");//从配置文件(app.config)读取配置。 string endpoint = WcfClientConfig.GetWcfRemoteAddress("WSHttpBinding_SGDatabase_H"); return new SGDatabase_HClient(BINDING, new EndpointAddress(endpoint)); }
static IFileService CreateChannel(string url) { WSHttpBinding binding = new WSHttpBinding(); EndpointAddress address = new EndpointAddress(url); ChannelFactory<IFileService> factory = new ChannelFactory<IFileService>(binding, address); return factory.CreateChannel(); }
public void Start() { this.host = new ServiceHost(typeof(NotificationService)); var binding = new WSHttpBinding { Security = { Mode = SecurityMode.None } }; var behavior = new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetUrl = configuration.Uri }; this.host.AddServiceEndpoint(typeof(INotificationService), binding, configuration.Uri); this.host.AddDependencyInjectionBehavior<NotificationService>(this.container); this.host.Description.Behaviors.Add(behavior); this.host.Open(); }
static void Main(string[] args) { // This is a code-configured host, NOTE that // the project has no App.Config using (var host = new ServiceHost( typeof(StockLookup), new Uri("http://localhost:1701/"))) { var binding = new WSHttpBinding(); var ep = host.AddServiceEndpoint( typeof(IStockLookup), // Contract binding, // Binding "Stock"); // Address var smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); host.Open(); Console.WriteLine("Host is now running..."); Console.WriteLine(">>> Press Enter To Stop <<<"); Console.ReadLine(); host.Close(); } }
public void CanProvideInstanceForHost() { using (var container = new UnityContainer()) { //var serviceMock = new Mock<ITestService>(); //container.RegisterInstance<ITestService>(serviceMock.Object); container.RegisterInstance<TestService>(new TestService("Test")); var serviceHost = new ServiceHost(typeof(TestService), new Uri("http://localhost:55551/TestService")); serviceHost.Description.Behaviors.Add(new UnityServiceBehavior(container)); Binding binding = new WSHttpBinding(); var address = new EndpointAddress("http://localhost:55551/TestService/MyService"); var endpoint = serviceHost .AddServiceEndpoint(typeof(ITestService), binding, address.Uri); var smb = new ServiceMetadataBehavior { HttpGetEnabled = true }; serviceHost.Description.Behaviors.Add(smb); var proxy = ChannelFactory<ITestService>.CreateChannel(binding, endpoint.Address); serviceHost.Open(); var result = proxy.TestOperation(); serviceHost.Close(); Assert.AreEqual("Test", result); } }
/// <summary> /// A private function to create the soapclient to communicate with ServiceNOW /// </summary> /// <param name="UserName">The API Username</param> /// <param name="Password">The API Password</param> /// <returns>A ServiceNow SoapClient object</returns> private static ServiceNowSoapClient soapClient(string UserName, string Password, string ServiceNowUrl) { try { EndpointAddress endpoint = new EndpointAddress(new Uri(ServiceNowUrl)); WSHttpBinding binding = new WSHttpBinding(); binding.Name = "ServiceNowSoap"; binding.MaxReceivedMessageSize = 65536; binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic; binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; ServiceNowSoapClient soapClient = new ServiceNowSoapClient(binding, endpoint); soapClient.ClientCredentials.UserName.UserName = UserName; soapClient.ClientCredentials.UserName.Password = Password; return soapClient; } catch (Exception ex) { Console.WriteLine(ex.Message); return null; } }
public static WSHttpBinding GetHttpBinding() { var binding = new WSHttpBinding { MaxBufferPoolSize = 2147483647, MaxReceivedMessageSize = 2147483647, MessageEncoding = WSMessageEncoding.Mtom, TextEncoding = System.Text.Encoding.UTF8, ReceiveTimeout = new TimeSpan(0, 0, 1, 0), SendTimeout = new TimeSpan(0, 0, 1, 0), OpenTimeout = new TimeSpan(0, 0, 1, 0), ReaderQuotas = { MaxArrayLength = 2147483647, MaxDepth = 2147483647, MaxStringContentLength = 2147483647, MaxBytesPerRead = 2147483647, MaxNameTableCharCount = 2147483647 }, ReliableSession = { Enabled = true, InactivityTimeout = new TimeSpan(0, 0, 1, 0) }, Security = { Mode = SecurityMode.None , Transport = {ClientCredentialType = HttpClientCredentialType.None}} }; return binding; }
public static Object GetWcfReference(Type type, object[] info) { if (info.Length == 2) info = new object[] { info[0], null, info[1] }; if (info.Length != 3) return null; Type genType; Type factType; if (info[0] == null) { genType = typeof(ChannelFactory<>); factType = genType.MakeGenericType(new Type[] { type }); if (info[1] == null) info[1] = new WSHttpBinding(); info = new object[] { info[1], new EndpointAddress((string)info[2]) }; } else { genType = typeof(DuplexChannelFactory<>); factType = genType.MakeGenericType(new Type[] { type }); info[0] = new InstanceContext(info[0]); info[2] = new EndpointAddress((string)info[2]); if (info[1] == null) info[1] = new WSDualHttpBinding(); } object factObject = Activator.CreateInstance(factType, info); MethodInfo methodInfo = factType.GetMethod("CreateChannel", new Type[] { }); return methodInfo.Invoke(factObject, null); }
/// <summary> /// Configures the specified service host, according to the specified arguments. /// </summary> /// <param name="host"></param> /// <param name="args"></param> public void ConfigureServiceHost(ServiceHost host, ServiceHostConfigurationArgs args) { WSHttpBinding binding = new WSHttpBinding(); binding.MaxReceivedMessageSize = args.MaxReceivedMessageSize; binding.ReaderQuotas.MaxStringContentLength = args.MaxReceivedMessageSize; binding.ReaderQuotas.MaxArrayLength = args.MaxReceivedMessageSize; binding.Security.Mode = SecurityMode.Message; binding.Security.Message.ClientCredentialType = args.Authenticated ? MessageCredentialType.UserName : MessageCredentialType.None; // establish endpoint host.AddServiceEndpoint(args.ServiceContract, binding, ""); // expose meta-data via HTTP GET ServiceMetadataBehavior metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (metadataBehavior == null) { metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetEnabled = true; host.Description.Behaviors.Add(metadataBehavior); } // set up the certificate - required for WSHttpBinding host.Credentials.ServiceCertificate.SetCertificate( args.CertificateSearchDirective.StoreLocation, args.CertificateSearchDirective.StoreName, args.CertificateSearchDirective.FindType, args.CertificateSearchDirective.FindValue); }
static LegacyProvider() { WSHttpBinding wsHttpBinding = new WSHttpBinding() { Security = new WSHttpSecurity() { Mode = SecurityMode.Message, Message = { ClientCredentialType = MessageCredentialType.Windows } } }; EndpointAddress endpoint = new EndpointAddress(VirtualPathUtility.AppendTrailingSlash(DebuggerConfig.Instance.CMS.Url) + "webservices/CoreService2011.svc/wsHttp"); ChannelFactory<core.ICoreService> clientFactory = new ChannelFactory<core.ICoreService>(wsHttpBinding, endpoint) { Credentials = { Windows = { ClientCredential = CredentialCache.DefaultNetworkCredentials } } }; // Initialize the CoreServiceClient mCoreServiceClient = clientFactory.CreateChannel(); }
private static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof (EvalService)); WSHttpBinding noSecurityPlusRMBinding = new WSHttpBinding(); noSecurityPlusRMBinding.Security.Mode = SecurityMode.None; noSecurityPlusRMBinding.ReliableSession.Enabled = true; host.AddServiceEndpoint(typeof (IEvalService), new BasicHttpBinding(), "http://localhost:8080/evals/basic"); host.AddServiceEndpoint(typeof(IEvalService), noSecurityPlusRMBinding, "http://localhost:8080/evals/ws"); //host.AddServiceEndpoint(typeof (IEvalService), new NetTcpBinding(), "net.tcp://localhost:8081/evals"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri("http://localhost:8080/evals/basic/meta"); host.Description.Behaviors.Add(smb); try { host.Open(); PrintServiceInfo(host); Console.ReadLine(); host.Close(); } catch (Exception e) { Console.WriteLine(e); host.Abort(); } Console.ReadLine(); }
static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8773/WSHttpService"); WSHttpBinding binding = new WSHttpBinding(); binding.Name = "WSHttp_Binding"; binding.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard; CustomBinding customBinding = new CustomBinding(binding); SymmetricSecurityBindingElement securityBinding = (SymmetricSecurityBindingElement)customBinding.Elements.Find<SecurityBindingElement>(); /// Change the MaxClockSkew to 2 minutes on both service and client settings. TimeSpan newClockSkew = new TimeSpan(0, 2, 0); securityBinding.LocalServiceSettings.MaxClockSkew = newClockSkew; securityBinding.LocalClientSettings.MaxClockSkew = newClockSkew; using (ServiceHost host = new ServiceHost(typeof(WSHttpService), baseAddress)) { host.AddServiceEndpoint(typeof(IWSHttpService), customBinding, "http://localhost:8773/WSHttpService/mex"); // Enable metadata publishing. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(smb); host.Open(); Console.WriteLine("The service is ready at {0}", baseAddress); Console.WriteLine("Press <Enter> to stop the service."); Console.ReadLine(); // Close the ServiceHost. host.Close(); } }
static void Main(string[] args) { // Configure IoC Container.Register( Component.For<IStockLookup>() .ImplementedBy<StockLookup>()); // Configure Host using (var host = new ServiceHost( typeof(StockLookup), new Uri("http://localhost:1701/"))) { var binding = new WSHttpBinding(); var ep = host.AddServiceEndpoint( typeof(IStockLookup), // Contract binding, // Binding "Stock"); // Address var ioc = new WindsorServiceBehavior(); host.Description.Behaviors.Add(ioc); host.Open(); Console.WriteLine("Host is now running..."); Console.WriteLine(">>> Press Enter To Stop <<<"); Console.ReadLine(); host.Close(); } }
public static void Main () { ServiceHost host = new ServiceHost (typeof (Foo)); WSHttpBinding binding = new WSHttpBinding (); binding.Security.Message.EstablishSecurityContext = false; binding.Security.Message.NegotiateServiceCredential = false; binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; binding.ReceiveTimeout = TimeSpan.FromSeconds (5); host.AddServiceEndpoint ("IFoo", binding, new Uri ("http://localhost:8080")); ServiceCredentials cred = new ServiceCredentials (); cred.ServiceCertificate.Certificate = new X509Certificate2 ("test.pfx", "mono"); cred.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; host.Description.Behaviors.Add (cred); host.Description.Behaviors.Find<ServiceDebugBehavior> () .IncludeExceptionDetailInFaults = true; foreach (ServiceEndpoint se in host.Description.Endpoints) se.Behaviors.Add (new StdErrInspectionBehavior ()); ServiceMetadataBehavior smb = new ServiceMetadataBehavior (); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl"); host.Description.Behaviors.Add (smb); host.Open (); Console.WriteLine ("Hit [CR] key to close ..."); Console.ReadLine (); host.Close (); }
public void ConfigureServiceHost(ServiceHost host, ServiceHostConfigurationArgs args) { WSHttpBinding binding = new WSHttpBinding(); binding.MaxReceivedMessageSize = args.MaxReceivedMessageSize; binding.ReaderQuotas.MaxStringContentLength = args.MaxReceivedMessageSize; binding.ReaderQuotas.MaxArrayLength = args.MaxReceivedMessageSize; binding.Security.Mode = WebServicesSettings.Default.SecurityMode; binding.Security.Message.ClientCredentialType = args.Authenticated ? MessageCredentialType.UserName : MessageCredentialType.None; // establish endpoint host.AddServiceEndpoint(args.ServiceContract, binding, ""); // expose meta-data via HTTP GET ServiceMetadataBehavior metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (metadataBehavior == null) { metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetEnabled = true; host.Description.Behaviors.Add(metadataBehavior); } // set up the certificate if (WebServicesSettings.Default.SecurityMode == SecurityMode.Message || WebServicesSettings.Default.SecurityMode==SecurityMode.TransportWithMessageCredential) { host.Credentials.ServiceCertificate.SetCertificate( StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, args.HostUri.Host); } }
public static SGDatabase_WClient CreateSGDatabase_WClient() { WSHttpBinding BINDING = new WSHttpBinding(); SoapClientConfig.ReadBindingConfig(BINDING, "http_ISGDatabase_W");//从配置文件(app.config)读取配置。 string endpoint = SoapClientConfig.GetSoapRemoteAddress("http_ISGDatabase_W"); return new SGDatabase_WClient(BINDING, new EndpointAddress(endpoint));//构建WCF客户端实例 }
private static TService HttpCreate <TService>(string uri, int TimeOut) { WSHttpBinding binding = new System.ServiceModel.WSHttpBinding(); binding.SendTimeout = TimeSpan.FromSeconds(TimeOut); binding.ReceiveTimeout = TimeSpan.FromSeconds(TimeOut); binding.MaxReceivedMessageSize = int.MaxValue; binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; binding.ReaderQuotas.MaxArrayLength = int.MaxValue; binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue; #region 设置一些配置信息 binding.Security.Mode = SecurityMode.None; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; #endregion #region 务令牌处理 string token = string.Empty; AddressHeader[] addressHeaders = new AddressHeader[] { }; if (string.IsNullOrEmpty(token) && OperationContext.Current != null) { int index = OperationContext.Current.IncomingMessageHeaders.FindHeader("token", ""); if (index >= 0) { token = OperationContext.Current.IncomingMessageHeaders.GetHeader <string>(index); } } if (string.IsNullOrEmpty(token) && WebOperationContext.Current != null) { if (WebOperationContext.Current.IncomingRequest.Headers["token"] != null) { token = WebOperationContext.Current.IncomingRequest.Headers["token"].ToString(); } } if (!string.IsNullOrEmpty(token)) { //若存在令牌,则继续添加令牌,不存在,则不管令牌 AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("token", "", token); addressHeaders = new AddressHeader[] { addressHeader1 }; } #endregion EndpointAddress endpoint = new EndpointAddress(new Uri(uri), addressHeaders); ChannelFactory <TService> channelfactory = new ChannelFactory <TService>(binding, endpoint); //返回工厂创建MaxItemsInObjectGraph foreach (OperationDescription op in channelfactory.Endpoint.Contract.Operations) { DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior; if (dataContractBehavior != null) { dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue; } } TService tservice = channelfactory.CreateChannel(); return(tservice); }
static void Main(string[] args) { var baseAddress = new Uri("https://localhost:44355"); using (var host = new ServiceHost(typeof(HelloWorldService), baseAddress)) { var binding = new WSHttpBinding(SecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "localhost"); host.Credentials.ClientCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck; host.Credentials.ClientCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine; host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.ChainTrust; var endpoint = typeof(IHelloWorldService); host.AddServiceEndpoint(endpoint, binding, baseAddress); var metaBehavior = new ServiceMetadataBehavior(); metaBehavior.HttpGetEnabled = true; metaBehavior.HttpGetUrl = new Uri("http://localhost:9000/mex"); metaBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(metaBehavior); host.Open(); Console.WriteLine("Service is ready. Hit enter to stop service."); Console.ReadLine(); host.Close(); } }
protected override void OnStart(string[] args) { if (serviceHost != null) { serviceHost.Close(); } String hostString = Dns.GetHostName(); IPHostEntry hostinfo = Dns.GetHostEntry(hostString); System.Net.IPAddress[] addresses = hostinfo.AddressList; String localIp=null; foreach (IPAddress address in addresses) { if (!address.IsIPv6LinkLocal) { localIp = address.ToString(); break; } } WSHttpBinding ws = new WSHttpBinding(); Uri baseAddress = new Uri("http://" + localIp + ":8000/ServiceModelSamples/service"); serviceHost = new ServiceHost(typeof(FileDigger), baseAddress); serviceHost.Open(); }
static void Main( string[] args ) { EndpointAddress address = new EndpointAddress("http://localhost:8001/TradeService"); WSHttpBinding binding = new WSHttpBinding(); System.ServiceModel.ChannelFactory<ITradeService> cf = new ChannelFactory<ITradeService>(binding, address); ITradeService proxy = cf.CreateChannel(); Console.WriteLine("\nTrade IBM"); try { double result = proxy.TradeSecurity("IBM", 1000); Console.WriteLine("Cost was " + result); Console.WriteLine("\nTrade MSFT"); result = proxy.TradeSecurity("MSFT", 2000); Console.WriteLine("Cost was " + result); } catch (Exception ex) { Console.Write("Can not perform task. Error Message - " + ex.Message); } Console.WriteLine("\n\nPress <enter> to exit..."); Console.ReadLine(); }
static void Main(string[] args) { try { ServiceHost dataExchangeService = null; Uri httpBaseAddress = new Uri(args.Length == 0 ? "http://127.0.0.1:8080" : args[0]); dataExchangeService = new ServiceHost(typeof(Service), httpBaseAddress); WSHttpBinding binding = new WSHttpBinding(); binding.Security = new WSHttpSecurity { Mode = SecurityMode.None }; binding.Security.Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None }; binding.MaxBufferPoolSize = 1073741824; binding.MaxReceivedMessageSize = 1073741824; binding.ReceiveTimeout = TimeSpan.FromHours(1); binding.SendTimeout = TimeSpan.FromHours(1); binding.ReaderQuotas.MaxArrayLength = 1073741824; binding.ReaderQuotas.MaxBytesPerRead = 1073741824; binding.ReaderQuotas.MaxDepth = 1073741824; binding.ReaderQuotas.MaxStringContentLength = 1073741824; dataExchangeService.AddServiceEndpoint(typeof(IDataTranslation), binding, ""); dataExchangeService.AddServiceEndpoint(typeof(IDataSimulation), binding, ""); dataExchangeService.Open(); logger.log("Service is now at: " + httpBaseAddress); while (true) { Thread.Sleep(10000); } } catch (Exception ex) { logger.log( ex.Message, Logger.LogType.ERROR); } }
private void Form1_Load(object sender, EventArgs e) { //Banking_Library.IService1 proxy = new Banking_Library.Service1(); EndpointAddress adddress = new EndpointAddress("http://localhost:8080/QuanLyDanhBa/QuanLyDanhBa"); WSHttpBinding binding = new WSHttpBinding(); ServiceLibrary.IQuanLyDanhBa proxy; proxy = ChannelFactory<ServiceLibrary.IQuanLyDanhBa>.CreateChannel(binding, adddress); // = new ServiceLibrary.ServiceQuanLyDanhBa(); //IServiceBank proxy = new ServiceBankClient(); textBox1.Text = proxy.GetAuthor(); //*/ //Dung ChannelFactory cho phep tao nhieu doi tuong proxy voi cac endpoint khac nhau //EndpointAddress address = new EndpointAddress("http://localhost:8000/BankService"); //BasicHttpBinding binding = new BasicHttpBinding(); //Banking_Library.IService1 proxy = ChannelFactory<Banking_Library.IService1>.CreateChannel(binding, address); //txtResult.Text = proxy.GetBalance("aaa").ToString(); //IBankService proxy = ChannelFactory<IBankService>.CreateChannel(binding, address); //decimal balance = proxy.GetBalance("ABC123"); //Dung ChannelFactory cho phep tao nhieu doi tuong proxy voi cac endpoint khac nhau //EndpointAddress address1 = new EndpointAddress("http://localhost:8000/BankService1"); //WSHttpBinding binding1 = new WSHttpBinding(); //IBankService proxy1 = ChannelFactory<IBankService>.CreateChannel(binding1, address1); //decimal balance1 = proxy1.GetBalance("ABC123"); //label1.Text = Convert.ToString(balance) + " and " + Convert.ToString(balance1); }
// Host the service within this EXE console application. public static void Main() { WSHttpBinding binding = new WSHttpBinding(); binding.Name = "binding1"; binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; binding.Security.Mode = SecurityMode.Message; binding.ReliableSession.Enabled = false; binding.TransactionFlow = false; Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service"); // Create a ServiceHost for the CalculatorService type and provide the base address. using(ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress)) { serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, baseAddress); // Open the ServiceHostBase to create listeners and start listening for messages. serviceHost.Open(); // The service can now be accessed. Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); } }
public static ProductManagerClient CreateProductManager() { //BasicHttpBinding wsd = new BasicHttpBinding(); var wsd = new WSHttpBinding(); wsd.Name = "WSHttpBinding_IProductManager"; wsd.SendTimeout = new TimeSpan(0,5,0); wsd.MessageEncoding = WSMessageEncoding.Mtom; wsd.AllowCookies = false; wsd.BypassProxyOnLocal = false; wsd.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; wsd.TextEncoding = Encoding.UTF8; //wsd.TransferMode = TransferMode.Buffered; wsd.UseDefaultWebProxy = true; wsd.MaxReceivedMessageSize = 1048576 * 30; // 30 mb //wsd.MaxBufferSize = 1048576 * 30; wsd.Security.Mode = SecurityMode.None; // BasicHttpSecurityMode.None; wsd.Security.Message.ClientCredentialType = MessageCredentialType.None; //BasicHttpMessageCredentialType.UserName; wsd.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default; wsd.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; wsd.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; wsd.Security.Transport.Realm = string.Empty; Uri baseAddress = new Uri("http://www.halan.se/service/ProductManager.svc/mtom"); // EndpointAddress ea = new EndpointAddress(baseAddress); // EndpointIdentity.CreateDnsIdentity("localhost")); return new ProductManagerClient(wsd, ea); //new ProductManagerClient("BasicHttpBinding_IProductManager"); }
static void Main(string[] args) { var binding = new WSHttpBinding(SecurityMode.Transport); binding.Name = "binding"; binding.MaxReceivedMessageSize = 500000; binding.AllowCookies = true; var client = new SyncReplyClient(binding, new EndpointAddress("https://platform.gaelenlighten.com/api/soap12")); using (new OperationContextScope(client.InnerChannel)) { var requestMessage = new HttpRequestMessageProperty(); requestMessage.Headers["Tenant"] = "tenant.gaelenlighten.com"; // Add your tenant var token = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("username:password")); // Add your username and password here requestMessage.Headers["Authorization"] = token; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; var response = client.GetReports(new GetReports { //// Specify filters ReportStatus = ReportStatus.New, Take = 100, Skip = 0 }); var reportList = response.Reports; foreach (var report in reportList) { ////Example of iterating through the report list } response.PrintDump(); Console.ReadLine(); } }
/// <summary> /// Configures the specified service host, according to the specified arguments. /// </summary> /// <param name="host"></param> /// <param name="args"></param> public void ConfigureServiceHost(ServiceHost host, ServiceHostConfigurationArgs args) { var binding = new WSHttpBinding(); binding.MaxReceivedMessageSize = args.MaxReceivedMessageSize; if (args.SendTimeoutSeconds > 0) binding.SendTimeout = TimeSpan.FromSeconds(args.SendTimeoutSeconds); binding.ReaderQuotas.MaxStringContentLength = args.MaxReceivedMessageSize; binding.ReaderQuotas.MaxArrayLength = args.MaxReceivedMessageSize; binding.Security.Mode = SecurityMode.Message; binding.Security.Message.ClientCredentialType = args.Authenticated ? MessageCredentialType.UserName : MessageCredentialType.None; // establish endpoint host.AddServiceEndpoint(args.ServiceContract, binding, ""); // expose meta-data via HTTP GET var metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (metadataBehavior == null) { metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetEnabled = true; host.Description.Behaviors.Add(metadataBehavior); } //TODO (Rockstar): remove this after refactoring to do per-sop edits foreach (var endpoint in host.Description.Endpoints) foreach (var operation in endpoint.Contract.Operations) operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = args.MaxReceivedMessageSize; // set up the certificate - required for WSHttpBinding host.Credentials.ServiceCertificate.SetCertificate( args.CertificateSearchDirective.StoreLocation, args.CertificateSearchDirective.StoreName, args.CertificateSearchDirective.FindType, args.CertificateSearchDirective.FindValue); }
/// <summary> /// Configures and returns an instance of the specified service channel factory, according to the specified arguments. /// </summary> /// <param name="args"></param> /// <returns></returns> public ChannelFactory ConfigureChannelFactory(ServiceChannelConfigurationArgs args) { var binding = new WSHttpBinding(); binding.Security.Mode = SecurityMode.Message; binding.Security.Message.ClientCredentialType = args.AuthenticationRequired ? MessageCredentialType.UserName : MessageCredentialType.None; binding.MaxReceivedMessageSize = args.MaxReceivedMessageSize; if (args.SendTimeoutSeconds > 0) binding.SendTimeout = TimeSpan.FromSeconds(args.SendTimeoutSeconds); // allow individual string content to be same size as entire message binding.ReaderQuotas.MaxStringContentLength = args.MaxReceivedMessageSize; binding.ReaderQuotas.MaxArrayLength = args.MaxReceivedMessageSize; //binding.ReceiveTimeout = new TimeSpan(0, 0 , 20); //binding.SendTimeout = new TimeSpan(0, 0, 10); var channelFactory = (ChannelFactory)Activator.CreateInstance(args.ChannelFactoryClass, binding, new EndpointAddress(args.ServiceUri)); channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = args.CertificateValidationMode; channelFactory.Credentials.ServiceCertificate.Authentication.RevocationMode = args.RevocationMode; //TODO (Rockstar): remove this after refactoring to do per-sop edits foreach (var operation in channelFactory.Endpoint.Contract.Operations) operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = args.MaxReceivedMessageSize; return channelFactory; }
/// <summary> /// 启动服务 /// </summary> private void OpenWCFServer() { WSHttpBinding wsHttp = new WSHttpBinding(); wsHttp.MaxBufferPoolSize = 524288; wsHttp.MaxReceivedMessageSize = 2147483647; wsHttp.ReaderQuotas.MaxArrayLength = 6553600; wsHttp.ReaderQuotas.MaxStringContentLength = 2147483647; wsHttp.ReaderQuotas.MaxBytesPerRead = 6553600; wsHttp.ReaderQuotas.MaxDepth = 6553600; wsHttp.ReaderQuotas.MaxNameTableCharCount = 6553600; wsHttp.CloseTimeout = new TimeSpan(0, 1, 0); wsHttp.OpenTimeout = new TimeSpan(0, 1, 0); wsHttp.ReceiveTimeout = new TimeSpan(0, 10, 0); wsHttp.SendTimeout = new TimeSpan(0, 10, 0); wsHttp.Security.Mode = SecurityMode.None; Uri baseAddress = new Uri("http://127.0.0.1:9999/wcfserver"); ServiceHost host = new ServiceHost(typeof(WCFServer), baseAddress); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); ServiceBehaviorAttribute sba = host.Description.Behaviors.Find<ServiceBehaviorAttribute>(); sba.MaxItemsInObjectGraph = 2147483647; host.AddServiceEndpoint(typeof(IWCFServer), wsHttp, ""); host.Open(); }
protected override void OnStart(string[] args) { eventLog1.WriteEntry("Service Starting"); // perform rename worker starting functions eventLog1.WriteEntry("Entering the startup routine"); _RenameWorker.Startup(); eventLog1.WriteEntry("Finished startup routine"); // Create the Uri to be accessed Uri baseAddress = new Uri("http://" + NetOps.GetLocalIP() + ":8080/SystemRenameService"); // Create Binding to be used by the service WSHttpBinding binding = new WSHttpBinding(); // begin the self-hosting of the service // Create a ServiceHost for the SystemRenameService type. serviceHost = new ServiceHost(myService, baseAddress); { serviceHost.AddServiceEndpoint(typeof(ISystemRenameService), binding, baseAddress); // Enable metadata publishing. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = baseAddress; smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; serviceHost.Description.Behaviors.Add(smb); // Open the ServiceHost to create listeners // and start listening for messages. eventLog1.WriteEntry("Opening listening port"); serviceHost.Open(); } }
WSHttpContextBinding(WSHttpBinding wsHttpBinding) { WSHttpContextBindingPropertyTransferHelper helper = new WSHttpContextBindingPropertyTransferHelper(); helper.InitializeFrom(wsHttpBinding); helper.SetBindingElementType(typeof(WSHttpContextBinding)); helper.ApplyConfiguration(this); }
private static TService HttpsCreate <TService>(string url, int TimeOut) { Uri uri = new Uri(url); ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); WSHttpBinding binding = new System.ServiceModel.WSHttpBinding(); binding.SendTimeout = new TimeSpan(0, TimeOut / 60, TimeOut % 60); binding.ReceiveTimeout = new TimeSpan(0, TimeOut / 60, TimeOut % 60); #region 设置一些配置信息 binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; #endregion System.ServiceModel.Web.WebOperationContext ctx = System.ServiceModel.Web.WebOperationContext.Current; var token = ctx.IncomingRequest.Headers["token"].ToString(); AddressHeaderCollection addressHeaderColl; if (!string.IsNullOrEmpty(token)) { AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("token", "", token); AddressHeader[] addressHeaders = new AddressHeader[] { addressHeader1 }; addressHeaderColl = new AddressHeaderCollection(addressHeaders); } else { addressHeaderColl = new AddressHeaderCollection(); } // //string[] cers = ZH.Security.Client.CertUtil.GetHostCertificate(uri); //TODO 证书处理 string[] cers = "".Split('.'); var IdentityDns = EndpointIdentity.CreateDnsIdentity(cers[0]); // System.ServiceModel.EndpointAddress endpoint = new EndpointAddress(uri, IdentityDns, addressHeaderColl); ChannelFactory <TService> channelfactory = new ChannelFactory <TService>(binding, endpoint); foreach (OperationDescription op in channelfactory.Endpoint.Contract.Operations) { DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior; if (dataContractBehavior != null) { dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue; } } // channelfactory.Credentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(Convert.FromBase64String(cers[1])); // new X509Certificate2(x509certificate); \ // //返回工厂创建 TService tservice = channelfactory.CreateChannel(); // return(tservice); }
/// <summary> /// Default constructor /// </summary> /// <param name="endPointAddress">The specific end point address</param> /// <param name="binding">Contains the binding elements that specify the protocols, /// transports, and message encoders used for communication between clients and services.</param> /// <param name="username">The UserName username</param> /// <param name="password">The UserName password</param> /// <param name="usernameWindows">The Windows ClientCredential username</param> /// <param name="passwordWindows">The Windows ClientCredential password</param> /// <param name="clientCertificate">The client x509 certificate.</param> /// <param name="validationMode">An enumeration that lists the ways of validating a certificate.</param> /// <param name="x509CertificateValidator">The certificate validator. If null then the certificate is always passed.</param> public Client(string endPointAddress, System.ServiceModel.WSHttpBinding binding, string username = null, string password = null, string usernameWindows = null, string passwordWindows = null, X509Certificate2 clientCertificate = null, X509CertificateValidationMode validationMode = X509CertificateValidationMode.Custom, X509CertificateValidator x509CertificateValidator = null) : base( new Uri(endPointAddress), binding, username, password, usernameWindows, passwordWindows, clientCertificate, validationMode, x509CertificateValidator) { OnCreated(); }
/// <summary> /// Default constructor /// </summary> /// <param name="binding">Contains the binding elements that specify the protocols, /// transports, and message encoders used for communication between clients and services.</param> /// <param name="username">The UserName username</param> /// <param name="password">The UserName password</param> /// <param name="usernameWindows">The Windows ClientCredential username</param> /// <param name="passwordWindows">The Windows ClientCredential password</param> /// <param name="clientCertificate">The client x509 certificate.</param> /// <param name="validationMode">An enumeration that lists the ways of validating a certificate.</param> /// <param name="x509CertificateValidator">The certificate validator. If null then the certificate is always passed.</param> public Client(System.ServiceModel.WSHttpBinding binding, string username = null, string password = null, string usernameWindows = null, string passwordWindows = null, X509Certificate2 clientCertificate = null, X509CertificateValidationMode validationMode = X509CertificateValidationMode.Custom, X509CertificateValidator x509CertificateValidator = null) : base( new Uri(Nequeo.Management.ServiceModel.Properties.Settings.Default.ServiceAddress), binding, username, password, usernameWindows, passwordWindows, clientCertificate, validationMode, x509CertificateValidator) { OnCreated(); }
/// <summary> /// Gets the remote ref. /// </summary> /// <param name="remoteEP">The remote endpoint.</param> /// <param name="epType">WCF interface that the remote object implements. /// Only needed for WCF RemotingMechanisms. /// It can be null when RemotingMechanisem TcpBinary is used.</param> /// <param name="remoteObjectPrefix">The remote object prefix.</param> /// <returns></returns> public static EndPointReference GetRemoteRef(EndPoint remoteEP, Type epType, string remoteObjectPrefix) { EndPointReference epr = null; switch (remoteEP.RemotingMechanism) { case RemotingMechanism.TcpBinary: { #region TcpBinary epr = new EndPointReference(); string uri = "tcp://" + remoteEP.Host + ":" + remoteEP.Port + "/" + remoteObjectPrefix; epr.Instance = Activator.GetObject(typeof(GNode), uri); break; #endregion } case RemotingMechanism.WCFCustom: { #region WCFCustom System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; epr = new EndPointReference(); switch (epType.Name) { case "IExecutor": { facExe = new ChannelFactory <IExecutor>(remoteEP.ServiceConfigurationName); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { facMan = new ChannelFactory <IManager>(remoteEP.ServiceConfigurationName); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { facOwn = new ChannelFactory <IOwner>(remoteEP.ServiceConfigurationName); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } case RemotingMechanism.WCFTcp: { #region WCFTcp System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; remoteEP.Binding = WCFBinding.NetTcpBinding; epr = new EndPointReference(); switch (epType.Name) { case "IExecutor": { System.ServiceModel.NetTcpBinding tcpBin = (System.ServiceModel.NetTcpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facExe = new ChannelFactory <IExecutor>(tcpBin); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { System.ServiceModel.NetTcpBinding tcpBin = (System.ServiceModel.NetTcpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facMan = new ChannelFactory <IManager>(tcpBin); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { System.ServiceModel.NetTcpBinding tcpBin = (System.ServiceModel.NetTcpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facOwn = new ChannelFactory <IOwner>(tcpBin); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } case RemotingMechanism.WCFHttp: { #region WCFHttp System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; epr = new EndPointReference(); remoteEP.Binding = WCFBinding.WSHttpBinding; switch (epType.Name) { case "IExecutor": { System.ServiceModel.WSHttpBinding wsHttpBin = (System.ServiceModel.WSHttpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facExe = new ChannelFactory <IExecutor>(wsHttpBin); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { System.ServiceModel.WSHttpBinding wsHttpBin = (System.ServiceModel.WSHttpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facMan = new ChannelFactory <IManager>(wsHttpBin); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { System.ServiceModel.WSHttpBinding wsHttpBin = (System.ServiceModel.WSHttpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facOwn = new ChannelFactory <IOwner>(wsHttpBin); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } case RemotingMechanism.WCF: { #region WCF System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; epr = new EndPointReference(); switch (epType.Name) { case "IExecutor": { System.ServiceModel.Channels.Binding binding = Utility.WCFUtils.GetWCFBinding(remoteEP); facExe = new ChannelFactory <IExecutor>(binding); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { System.ServiceModel.Channels.Binding binding = Utility.WCFUtils.GetWCFBinding(remoteEP); facMan = new ChannelFactory <IManager>(binding); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { System.ServiceModel.Channels.Binding binding = Utility.WCFUtils.GetWCFBinding(remoteEP); facOwn = new ChannelFactory <IOwner>(binding); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } default: return(null); } return(epr); }
public SurveyManagerServiceV3.ManagerServiceV3Client GetClient() { SurveyManagerServiceV3.ManagerServiceV3Client client; Configuration config = Configuration.GetNewInstance(); if (config.Settings.WebServiceAuthMode == 1) // Windows Authentication { System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.OpenTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = config.Settings.WebServiceMaxBufferPoolSize; binding.MaxReceivedMessageSize = config.Settings.WebServiceMaxReceivedMessageSize; binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = System.ServiceModel.TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas.MaxDepth = config.Settings.WebServiceReaderMaxDepth; binding.ReaderQuotas.MaxStringContentLength = config.Settings.WebServiceReaderMaxStringContentLength; binding.ReaderQuotas.MaxArrayLength = config.Settings.WebServiceReaderMaxArrayLength; binding.ReaderQuotas.MaxBytesPerRead = config.Settings.WebServiceReaderMaxBytesPerRead; binding.ReaderQuotas.MaxNameTableCharCount = config.Settings.WebServiceReaderMaxNameTableCharCount; binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.UserName; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(config.Settings.WebServiceEndpointAddress); client = new SurveyManagerServiceV3.ManagerServiceV3Client(binding, endpoint); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; } else { if (config.Settings.WebServiceBindingMode.Equals("wshttp", StringComparison.OrdinalIgnoreCase)) { System.ServiceModel.WSHttpBinding binding = new System.ServiceModel.WSHttpBinding(); binding.Name = "WSHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.OpenTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.BypassProxyOnLocal = false; binding.TransactionFlow = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = config.Settings.WebServiceMaxBufferPoolSize; binding.MaxReceivedMessageSize = config.Settings.WebServiceMaxReceivedMessageSize; binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.UseDefaultWebProxy = true; binding.AllowCookies = false; binding.ReaderQuotas.MaxDepth = config.Settings.WebServiceReaderMaxDepth; binding.ReaderQuotas.MaxStringContentLength = config.Settings.WebServiceReaderMaxStringContentLength; binding.ReaderQuotas.MaxArrayLength = config.Settings.WebServiceReaderMaxArrayLength; binding.ReaderQuotas.MaxBytesPerRead = config.Settings.WebServiceReaderMaxBytesPerRead; binding.ReaderQuotas.MaxNameTableCharCount = config.Settings.WebServiceReaderMaxNameTableCharCount; binding.ReliableSession.Ordered = true; binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0); binding.ReliableSession.Enabled = false; binding.Security.Mode = System.ServiceModel.SecurityMode.Message; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; binding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.Windows; binding.Security.Message.NegotiateServiceCredential = true; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(config.Settings.WebServiceEndpointAddress); client = new SurveyManagerServiceV3.ManagerServiceV3Client(binding, endpoint); } else { System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.OpenTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = config.Settings.WebServiceMaxBufferPoolSize; binding.MaxReceivedMessageSize = config.Settings.WebServiceMaxReceivedMessageSize; binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = System.ServiceModel.TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas.MaxDepth = config.Settings.WebServiceReaderMaxDepth; binding.ReaderQuotas.MaxStringContentLength = config.Settings.WebServiceReaderMaxStringContentLength; binding.ReaderQuotas.MaxArrayLength = config.Settings.WebServiceReaderMaxArrayLength; binding.ReaderQuotas.MaxBytesPerRead = config.Settings.WebServiceReaderMaxBytesPerRead; binding.ReaderQuotas.MaxNameTableCharCount = config.Settings.WebServiceReaderMaxNameTableCharCount; binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(config.Settings.WebServiceEndpointAddress); client = new SurveyManagerServiceV3.ManagerServiceV3Client(binding, endpoint); } } return(client); }
public static EWEManagerService.EWEManagerServiceClient GetClient(string pEndPointAddress, bool pIsAuthenticated, bool pIsWsHttpBinding = true) { EWEManagerService.EWEManagerServiceClient result = null; try { if (pIsAuthenticated) // Windows Authentication { System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.OpenTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = long.Parse(ConfigurationManager.AppSettings["MaxBufferPoolSize"]);//524288; binding.MaxReceivedMessageSize = long.Parse(ConfigurationManager.AppSettings["MaxReceivedMessageSize"]); binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = System.ServiceModel.TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas.MaxDepth = int.Parse(ConfigurationManager.AppSettings["MaxDepth"]); //32; binding.ReaderQuotas.MaxStringContentLength = int.Parse(ConfigurationManager.AppSettings["MaxStringContentLength"]); //8192; binding.ReaderQuotas.MaxArrayLength = int.Parse(ConfigurationManager.AppSettings["MaxArrayLength"]); //16384; binding.ReaderQuotas.MaxBytesPerRead = int.Parse(ConfigurationManager.AppSettings["MaxBytesPerRead"]); //4096; binding.ReaderQuotas.MaxNameTableCharCount = int.Parse(ConfigurationManager.AppSettings["MaxNameTableCharCount"]); //16384; binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.UserName; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(pEndPointAddress); result = new EWEManagerService.EWEManagerServiceClient(binding, endpoint); result.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; result.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; } else { if (pIsWsHttpBinding) { System.ServiceModel.WSHttpBinding binding = new System.ServiceModel.WSHttpBinding(); binding.Name = "WSHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.OpenTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.BypassProxyOnLocal = false; binding.TransactionFlow = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = long.Parse(ConfigurationManager.AppSettings["MaxBufferPoolSize"]);//524288; binding.MaxReceivedMessageSize = long.Parse(ConfigurationManager.AppSettings["MaxReceivedMessageSize"]); binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.UseDefaultWebProxy = true; binding.AllowCookies = false; binding.ReaderQuotas.MaxDepth = int.Parse(ConfigurationManager.AppSettings["MaxDepth"]); //32; binding.ReaderQuotas.MaxStringContentLength = int.Parse(ConfigurationManager.AppSettings["MaxStringContentLength"]); //8192; binding.ReaderQuotas.MaxArrayLength = int.Parse(ConfigurationManager.AppSettings["MaxArrayLength"]); //16384; binding.ReaderQuotas.MaxBytesPerRead = int.Parse(ConfigurationManager.AppSettings["MaxBytesPerRead"]); //4096; binding.ReaderQuotas.MaxNameTableCharCount = int.Parse(ConfigurationManager.AppSettings["MaxNameTableCharCount"]); //16384; binding.ReliableSession.Ordered = true; binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0); binding.ReliableSession.Enabled = false; binding.Security.Mode = System.ServiceModel.SecurityMode.Message; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; binding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.Windows; binding.Security.Message.NegotiateServiceCredential = true; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(pEndPointAddress); result = new EWEManagerService.EWEManagerServiceClient(binding, endpoint); } else { System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.OpenTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = long.Parse(ConfigurationManager.AppSettings["MaxBufferPoolSize"]);//524288; binding.MaxReceivedMessageSize = long.Parse(ConfigurationManager.AppSettings["MaxReceivedMessageSize"]); binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = System.ServiceModel.TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas.MaxDepth = int.Parse(ConfigurationManager.AppSettings["MaxDepth"]); //32; binding.ReaderQuotas.MaxStringContentLength = int.Parse(ConfigurationManager.AppSettings["MaxStringContentLength"]); //8192; binding.ReaderQuotas.MaxArrayLength = int.Parse(ConfigurationManager.AppSettings["MaxArrayLength"]); //16384; binding.ReaderQuotas.MaxBytesPerRead = int.Parse(ConfigurationManager.AppSettings["MaxBytesPerRead"]); //4096; binding.ReaderQuotas.MaxNameTableCharCount = int.Parse(ConfigurationManager.AppSettings["MaxNameTableCharCount"]); //16384; binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(pEndPointAddress); result = new EWEManagerService.EWEManagerServiceClient(binding, endpoint); } } } catch (FaultException <CustomFaultException> cfe) { throw cfe; } catch (FaultException fe) { throw fe; } catch (SecurityNegotiationException sne) { throw sne; } catch (CommunicationException ce) { throw ce; } catch (TimeoutException te) { throw te; } catch (Exception ex) { throw ex; } return(result); }
/// <summary> /// Remotes this instance across a channel /// - if the own end point is valid: /// - register a new channel, if not already done. /// - if successful, then marshal this GNode object over the remoting channel /// </summary> private void RemoteSelf() { if (_OwnEP != null) { switch (_OwnEP.RemotingMechanism) { case (RemotingMechanism.TcpBinary): { #region .NET Remoting Publish if (!_ChannelRegistered) { try { _Channel = new TcpChannel(_OwnEP.Port); //Hashtable properties = new Hashtable(); //// the name must be Empty in order to allow multiple TCP channels //properties.Add("name", String.Empty); //properties.Add("port", _OwnEP.Port); //_Channel = new TcpChannel( // properties, // new BinaryClientFormatterSinkProvider(), // new BinaryServerFormatterSinkProvider()); ChannelServices.RegisterChannel(_Channel, false); _ChannelRegistered = true; } catch (Exception e) { if ( object.ReferenceEquals(e.GetType(), typeof(System.Runtime.Remoting.RemotingException)) /* assuming: "The channel tcp is already registered." */ | object.ReferenceEquals(e.GetType(), typeof(SocketException)) /* assuming: "Only one usage of each socket address (protocol/network address/port) is normally permitted" */ ) { _ChannelRegistered = true; } else { UnRemoteSelf(); throw new RemotingException("Could not register channel while trying to remote self: " + e.Message, e); } } } if (_ChannelRegistered) { try { logger.Info("Trying to publish a GNode at : " + _RemoteObjPrefix); RemotingServices.Marshal(this, _RemoteObjPrefix); logger.Info("GetObjectURI from remoting services : " + RemotingServices.GetObjectUri(this)); logger.Info("Server object type: " + RemotingServices.GetServerTypeForUri(RemotingServices.GetObjectUri(this)).FullName); } catch (Exception e) { UnRemoteSelf(); throw new RemotingException("Could not remote self.", e); } } break; #endregion } case RemotingMechanism.WCFCustom: { #region Custom WCF Publish try { _ServiceHost = new ServiceHost(this, new Uri(_OwnEP.FullAddress)); _ServiceHost.Open(); } catch (Exception e) { UnRemoteSelf(); throw e; //throw new Exception("Could not remote self.", e); } break; #endregion } case RemotingMechanism.WCFTcp: { #region Tcp WCF Publish try { //create a new binding _OwnEP.Binding = WCFBinding.NetTcpBinding; System.ServiceModel.NetTcpBinding tcpBin = (System.ServiceModel.NetTcpBinding)Utility.WCFUtils.GetWCFBinding(_OwnEP); Type contractType = null; if (this is Alchemi.Core.IExecutor) { contractType = typeof(Alchemi.Core.IExecutor); } else if (this is Alchemi.Core.IManager) { contractType = typeof(Alchemi.Core.IManager); } else if (this is Alchemi.Core.IOwner) { contractType = typeof(Alchemi.Core.IOwner); } _ServiceHost = new ServiceHost(this, new Uri(_OwnEP.FullPublishingAddress)); Utility.WCFUtils.SetPublishingServiceHost(_ServiceHost); _ServiceHost.AddServiceEndpoint(contractType, tcpBin, _OwnEP.FullPublishingAddress); _ServiceHost.Open(); } catch (Exception e) { UnRemoteSelf(); throw e; //throw new Exception("Could not remote self.", e); } break; #endregion } case RemotingMechanism.WCFHttp: { #region Http WCF Publish try { //create a new binding _OwnEP.Binding = WCFBinding.WSHttpBinding; System.ServiceModel.WSHttpBinding wsHttpBin = (System.ServiceModel.WSHttpBinding)Utility.WCFUtils.GetWCFBinding(_OwnEP); Type contractType = null; if (this is Alchemi.Core.IExecutor) { contractType = typeof(Alchemi.Core.IExecutor); } else if (this is Alchemi.Core.IManager) { contractType = typeof(Alchemi.Core.IManager); } else if (this is Alchemi.Core.IOwner) { contractType = typeof(Alchemi.Core.IOwner); } _ServiceHost = new ServiceHost(this, new Uri(_OwnEP.FullPublishingAddress)); Utility.WCFUtils.SetPublishingServiceHost(_ServiceHost); _ServiceHost.AddServiceEndpoint(contractType, wsHttpBin, _OwnEP.FullPublishingAddress); _ServiceHost.Open(); } catch (Exception e) { UnRemoteSelf(); throw e; //throw new Exception("Could not remote self.", e); } break; #endregion } case RemotingMechanism.WCF: { #region WCF Publish try { //create a new binding System.ServiceModel.Channels.Binding binding = Utility.WCFUtils.GetWCFBinding(_OwnEP); Type contractType = null; if (this is Alchemi.Core.IExecutor) { contractType = typeof(Alchemi.Core.IExecutor); } else if (this is Alchemi.Core.IManager) { contractType = typeof(Alchemi.Core.IManager); } else if (this is Alchemi.Core.IOwner) { contractType = typeof(Alchemi.Core.IOwner); } _ServiceHost = new ServiceHost(this, new Uri(_OwnEP.FullPublishingAddress)); Utility.WCFUtils.SetPublishingServiceHost(_ServiceHost); _ServiceHost.AddServiceEndpoint(contractType, binding, _OwnEP.FullPublishingAddress); _ServiceHost.Open(); } catch (Exception e) { UnRemoteSelf(); throw e; //throw new Exception("Could not remote self.", e); } break; #endregion } } } }
public static EWEManagerService.EWEManagerServiceClient GetClient(string pEndPointAddress, bool pIsAuthenticated, bool pIsWsHttpBinding = true) { EWEManagerService.EWEManagerServiceClient result = null; try { Configuration config = Configuration.GetNewInstance();; if (pIsAuthenticated) // Windows Authentication { System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 10, 0); binding.OpenTimeout = new TimeSpan(0, 10, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 10, 0); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = config.Settings.EWEServiceMaxBufferPoolSize; binding.MaxReceivedMessageSize = config.Settings.EWEServiceMaxReceivedMessageSize; binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = System.ServiceModel.TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas.MaxDepth = config.Settings.EWEServiceReaderMaxDepth; binding.ReaderQuotas.MaxStringContentLength = config.Settings.EWEServiceReaderMaxStringContentLength; binding.ReaderQuotas.MaxArrayLength = config.Settings.EWEServiceReaderMaxArrayLength; binding.ReaderQuotas.MaxBytesPerRead = config.Settings.EWEServiceReaderMaxBytesPerRead; binding.ReaderQuotas.MaxNameTableCharCount = config.Settings.EWEServiceReaderMaxNameTableCharCount; //binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; //binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; //binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; //binding.Security.Transport.Realm = string.Empty; //binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.UserName; //System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(pEndPointAddress); //result = new EWEManagerService.EWEManagerServiceClient(binding, endpoint); //result.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; //result.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(pEndPointAddress); if (endpoint.Uri.Scheme == "http") { binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; } else { binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None; } binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.UserName; result = new EWEManagerService.EWEManagerServiceClient(binding, endpoint); result.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; result.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { return(true); }; } else { if (pIsWsHttpBinding) { System.ServiceModel.WSHttpBinding binding = new System.ServiceModel.WSHttpBinding(); binding.Name = "WSHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 10, 0); binding.OpenTimeout = new TimeSpan(0, 10, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 10, 0); binding.BypassProxyOnLocal = false; binding.TransactionFlow = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = config.Settings.EWEServiceMaxBufferPoolSize; binding.MaxReceivedMessageSize = config.Settings.EWEServiceMaxReceivedMessageSize; binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.UseDefaultWebProxy = true; binding.AllowCookies = false; binding.ReaderQuotas.MaxDepth = config.Settings.EWEServiceReaderMaxDepth; binding.ReaderQuotas.MaxStringContentLength = config.Settings.EWEServiceReaderMaxStringContentLength; binding.ReaderQuotas.MaxArrayLength = config.Settings.EWEServiceReaderMaxArrayLength; binding.ReaderQuotas.MaxBytesPerRead = config.Settings.EWEServiceReaderMaxBytesPerRead; binding.ReaderQuotas.MaxNameTableCharCount = config.Settings.EWEServiceReaderMaxNameTableCharCount; binding.ReliableSession.Ordered = true; binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0); binding.ReliableSession.Enabled = false; binding.Security.Mode = System.ServiceModel.SecurityMode.Message; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; binding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.Windows; binding.Security.Message.NegotiateServiceCredential = true; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(pEndPointAddress); result = new EWEManagerService.EWEManagerServiceClient(binding, endpoint); } else { System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding"; binding.CloseTimeout = new TimeSpan(0, 10, 0); binding.OpenTimeout = new TimeSpan(0, 10, 0); binding.ReceiveTimeout = new TimeSpan(0, 10, 0); binding.SendTimeout = new TimeSpan(0, 10, 0); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; binding.MaxBufferPoolSize = config.Settings.EWEServiceMaxBufferPoolSize; binding.MaxReceivedMessageSize = config.Settings.EWEServiceMaxReceivedMessageSize; binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = System.ServiceModel.TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas.MaxDepth = config.Settings.EWEServiceReaderMaxDepth; binding.ReaderQuotas.MaxStringContentLength = config.Settings.EWEServiceReaderMaxStringContentLength; binding.ReaderQuotas.MaxArrayLength = config.Settings.EWEServiceReaderMaxArrayLength; binding.ReaderQuotas.MaxBytesPerRead = config.Settings.EWEServiceReaderMaxBytesPerRead; binding.ReaderQuotas.MaxNameTableCharCount = config.Settings.EWEServiceReaderMaxNameTableCharCount; System.ServiceModel.EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(pEndPointAddress); if (endpoint.Uri.Scheme == "http") { binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; binding.Security.Transport.Realm = string.Empty; } else { binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None; } result = new EWEManagerService.EWEManagerServiceClient(binding, endpoint); System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { return(true); }; } } } catch (FaultException fe) { throw fe; } catch (SecurityNegotiationException sne) { throw sne; } catch (CommunicationException ce) { throw ce; } catch (TimeoutException te) { throw te; } catch (Exception ex) { throw ex; } return(result); }
private MetadataSet GetServiceMetadata(string wsdlUrl, MetadataExchangeClientMode clientMode, System.Net.NetworkCredential mexNetworkCredentials) { MetadataSet metadata = null; Binding mexBinding; if (clientMode == MetadataExchangeClientMode.HttpGet){ mexBinding = new BasicHttpBinding { MaxReceivedMessageSize = 50000000L }; } else { mexBinding = new WSHttpBinding(SecurityMode.None) { MaxReceivedMessageSize = 50000000L }; } var mexClient = new MetadataExchangeClient(mexBinding) { ResolveMetadataReferences = true, MaximumResolvedReferences = 200, HttpCredentials = mexNetworkCredentials }; try { metadata = mexClient.GetMetadata(new Uri(wsdlUrl), clientMode); } catch (Exception ex) { Console.WriteLine(String.Format("Error: {0}", ex.Message)); } return metadata; }