ossiejhmoore

Simple C# Client to Test Content Server Web Services

Dec 11th, 2018
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.ServiceModel;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace dotnet_CSWSTestClientSimple
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             try
  15.             {
  16.                 //get wsdl, username, passwrod from user
  17.  
  18.                 Console.WriteLine("Authentication URL:");
  19.                 string url = Console.ReadLine();
  20.                 Console.WriteLine("Username:");
  21.                 string userName = Console.ReadLine();
  22.                 Console.WriteLine("Password:");
  23.                 ConsoleKeyInfo key;
  24.                 string passWord = "";
  25.                 do
  26.                 {
  27.                     key = Console.ReadKey(true);
  28.                     if ((key.Key != ConsoleKey.Backspace) && (key.Key != ConsoleKey.Enter))
  29.                     {
  30.                         passWord += key.KeyChar;
  31.                         Console.Write("*");
  32.                     }
  33.                     else if (key.Key == ConsoleKey.Backspace)
  34.                     {
  35.                         if (passWord.Length > 0)
  36.                         {
  37.                             passWord = passWord.Substring(0, passWord.Length - 1);
  38.                             Console.Write("\b");
  39.                         }
  40.                     }
  41.                 }
  42.                 while (key.Key != ConsoleKey.Enter);
  43.                 Console.WriteLine();
  44.                 string userPassword = passWord;
  45.  
  46.                 //authenticate using the url/username/password provided
  47.  
  48.                 OTAuth.AuthenticationClient auth = new OTAuth.AuthenticationClient();
  49.                 auth.Endpoint.Address = new EndpointAddress(url);
  50.                 string token = auth.AuthenticateUser(userName, userPassword);
  51.                 Console.WriteLine("Authentication token: " + token);
  52.  
  53.                 //wait for user to press enter before exiting
  54.  
  55.  
  56.             }
  57.             catch (Exception ex)
  58.             {
  59.                 Console.WriteLine("Failure! {0}", ex.Message);
  60.             }
  61.             Console.WriteLine("Press enter to continue");
  62.             Console.ReadLine();
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment