static void Main(string[] args) { Configure(); //authClient = new AuthServiceClient("NetTcpBinding_IAuthService"); authClient = new AuthServiceClient("WSHttpBinding_IAuthService"); //secureClient = new SecureServiceClient("NetTcpBinding_ISecureService"); secureClient = new SecureServiceClient("WSHttpBinding_ISecureService"); Tuple <string, string> usernamepw = PromptUserNamePassword(); Login(usernamepw.Item1, usernamepw.Item2); if (IsUserLoggedIn) { GetDataWithValidCredentials(usernamepw.Item1, usernamepw.Item2); } else { Console.WriteLine("User credentials not valid"); } Console.ReadLine(); }
static void Main(string[] args) { var client = new SecureServiceClient("WSHttpBinding_ISecureService"); //var client = new SecureServiceClient("NetTcpBinding_ISecureService"); //var client = new InSecureServiceClient("BasicHttpBinding_IInSecureService"); //var client = new InSecureServiceClient("NetTcpBinding_IInSecureService"); //Remove the certificate authority validation --> dont do this in production ServicePointManager.ServerCertificateValidationCallback = (obj, certificate, chain, errors) => true; //Communicate credentials with every request to the web service //Unfortunate, but otherwise we would need another scheme. eg tokenbased auth //In your web application, you will store the credentials in memory, this is also problematic, however we will have to make do for now client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = "******"; try { client.Open(); while (true) { try { var input = Convert.ToInt32(Console.ReadLine()); var response = client.GetData(input); // var response = client.DoSomethingInsecure(input.ToString()); Console.WriteLine(response); } catch (Exception e) { Console.WriteLine("Incorrect input.. valid values er int.MinValue to int.MaxValue"); } } } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } }
void Timeout(object sender) { try { if (SecureService.State == CommunicationState.Opened) { SecureService.ToServerHelloAsync(); } else { SecureService.CloseAsync(); SecureService = new SecureServiceClient(new InstanceContext(this), Config); RegistTask(); //tmr.Change(System.Threading.Timeout.Infinite, 0); //tmr.Dispose(); } } catch (Exception ex) { Console.WriteLine(ex.Message); ; } }
public MyClient(string config,bool IsAutoRegister) { this.Config = config; this.SecureService = this.SecureService = new SecureServiceClient(new InstanceContext(this), config);// new SecureServiceObject(new InstanceContext(this), config); if (IsAutoRegister) { RegistTask(); } tmr = new System.Threading.Timer(new System.Threading.TimerCallback(Timeout), null, 1000 * 120, 1000 * 30); }