private static void OpenConnection(common.configuration.wsConnectionInfo wsInfo) { if (_myClient != null) _myClient.Abort(); _myClient = new ServiceReference1.StockServiceClient(); System.ServiceModel.WSHttpBinding binding = (_myClient.Endpoint.Binding as System.ServiceModel.WSHttpBinding); binding.OpenTimeout = TimeSpan.FromSeconds(wsInfo.timeoutInSecs); binding.CloseTimeout = TimeSpan.FromSeconds(wsInfo.timeoutInSecs); binding.SendTimeout = TimeSpan.FromSeconds(wsInfo.timeoutInSecs); binding.MaxReceivedMessageSize = constMaxReceivedMessageSize; binding.ReaderQuotas.MaxStringContentLength = constMaxStringContentLength; binding.ReaderQuotas.MaxBytesPerRead = constMaxBytesPerRead; //Proxy must befor setting Endpoint ? if (wsInfo.useProxy) { //Chua loi proxy http://chrishaas.wordpress.com/2009/11/02/fixing-the-remote-server-returned-an-error-417-expectation-failed/ ServicePointManager.Expect100Continue = false; if (wsInfo.useDefaultProxy) binding.UseDefaultWebProxy = true; else { if (wsInfo.proxyAddress.Trim() != "" && wsInfo.proxyPort.Trim() != "") { binding.ProxyAddress = new Uri(wsInfo.proxyAddress.Trim() + ":" + wsInfo.proxyPort.Trim()); binding.BypassProxyOnLocal = true; binding.UseDefaultWebProxy = false; } } } //Endpoint settings _myClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(wsInfo.URI); if (wsInfo.isWindowAuthentication) { _myClient.ClientCredentials.Windows.ClientCredential.UserName = wsInfo.account; _myClient.ClientCredentials.Windows.ClientCredential.Password = wsInfo.password; } else { _myClient.ClientCredentials.UserName.UserName = wsInfo.account; _myClient.ClientCredentials.UserName.Password = wsInfo.password; } //For testing //_myClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:8731/wsServices/DataLibs/?wsdl"); //_myClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost/DataLibs.svc"); //_myClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:8731/wsServices/DataLibs"); //_myClient.ClientCredentials.Windows.ClientCredential.UserName = ""; //_myClient.ClientCredentials.Windows.ClientCredential.Password = ""; //ServicePointManager.UseNagleAlgorithm = true; //ServicePointManager.CheckCertificateRevocationList = true; //ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit; _myClient.Open(); }
private static void CloseConnection() { if (_myClient != null && (_myClient.State == System.ServiceModel.CommunicationState.Opened) ) { _myClient.Close(); } _myClient = null; }
private static bool OpenConnection(common.wsConnectionInfo wsInfo) { if (_myClient != null) _myClient.Abort(); //Basic binding _myClient = new ServiceReference1.StockServiceClient("basicEndpoint"); //_myClient.Endpoint=new System.ServiceModel.Description.ServiceEndpoint( System.ServiceModel.BasicHttpBinding binding = (_myClient.Endpoint.Binding as System.ServiceModel.BasicHttpBinding); //Secure binding //_myClient = new ServiceReference1.StockServiceClient("wsEndpoint"); //System.ServiceModel.WSHttpBinding binding = (_myClient.Endpoint.Binding as System.ServiceModel.WSHttpBinding); binding.OpenTimeout = TimeSpan.FromSeconds(wsInfo.timeoutInSecs); binding.CloseTimeout = TimeSpan.FromSeconds(wsInfo.timeoutInSecs); binding.SendTimeout = TimeSpan.FromSeconds(wsInfo.timeoutInSecs); binding.MaxBufferSize = constMaxReceivedMessageSize; //Basic HTTP require MaxBufferSize=MaxReceivedMessageSize binding.MaxReceivedMessageSize = constMaxReceivedMessageSize; binding.ReaderQuotas.MaxStringContentLength = constMaxStringContentLength; binding.ReaderQuotas.MaxBytesPerRead = constMaxBytesPerRead; //Proxy must before setting Endpoint ? binding.UseDefaultWebProxy = false; if (wsInfo.useProxy) { if (wsInfo.useDefaultProxy) binding.UseDefaultWebProxy = true; else { if (wsInfo.proxyAddress.Trim() != "" && wsInfo.proxyPort.Trim() != "") { binding.ProxyAddress = new Uri(wsInfo.proxyAddress.Trim() + ":" + wsInfo.proxyPort.Trim()); binding.BypassProxyOnLocal = true; binding.UseDefaultWebProxy = false; } } } //Endpoint settings _myClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(wsInfo.URI); if (wsInfo.isWindowAuthentication) { _myClient.ClientCredentials.Windows.ClientCredential.UserName = wsInfo.account; _myClient.ClientCredentials.Windows.ClientCredential.Password = wsInfo.password; } else { _myClient.ClientCredentials.UserName.UserName = wsInfo.account; _myClient.ClientCredentials.UserName.Password = wsInfo.password; } ServicePointManager.Expect100Continue = false; //loi proxy http://chrishaas.wordpress.com/2009/11/02/fixing-the-remote-server-returned-an-error-417-expectation-failed/ ServicePointManager.UseNagleAlgorithm = true; ServicePointManager.CheckCertificateRevocationList = true; //ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit; //For testing if (Settings.sysDebugMode) { if (Settings.environmentMode == Settings.environmentDebugMode.localHP || Settings.environmentMode == Settings.environmentDebugMode.localT440) { _myClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:8731/wsServices/DataLibs"); _myClient.ClientCredentials.Windows.ClientCredential.UserName = ""; _myClient.ClientCredentials.Windows.ClientCredential.Password = ""; } } //End testing _myClient.Open(); myConnState = ConnState.Connected; return true; }
private void OpenConn() { //DataAccess.Libs.G(); if (client == null || client.State != System.ServiceModel.CommunicationState.Opened) { client = new ServiceReference1.StockServiceClient("basicEndpoint"); client.ClientCredentials.Windows.ClientCredential.UserName = "******"; client.ClientCredentials.Windows.ClientCredential.Password = "******"; // client.ClientCredentials.Windows.ClientCredential.UserName = ""; //client.ClientCredentials.Windows.ClientCredential.Password = ""; } }
public static void tryOpenConnect() { if (client == null || client.State != System.ServiceModel.CommunicationState.Opened) { client = new ServiceReference1.StockServiceClient("basicEndpoint"); client.ClientCredentials.Windows.ClientCredential.UserName = "******"; client.ClientCredentials.Windows.ClientCredential.Password = "******"; } }