title: Calling PHP Web -Service from C# Windows Form
body: <p>I am trying to verify username, password, and software token number of a C# Windows Form to values in MySQL database. </p>
  
  <p>My C# Code:</p>
  
  <pre><code> private void btnlogin_Click(object sender, EventArgs e)
      {
          if (String.IsNullOrEmpty(txtusername.Text))
          {
              MessageBox.Show("Please insert username");
          }
  
          if (String.IsNullOrEmpty(txtpassword.Text))
          {
              MessageBox.Show("Please insert password");
          }
  
          var username = txtusername.Text;
          var password = txtpassword.Text;
          string Token = "28956";
          var SoftwareToken = token;
          WebRequest request = WebRequest.Create("https://mydomain.com.au/Verification.php?username=username&amp;password=password&amp;Token=SoftwareToken");
          request.Method = "GET";
          WebResponse response = request.GetResponse();
          Console.WriteLine(((HttpWebResponse)response).StatusDescription);
          Stream dataStream = response.GetResponseStream();
          // Open the stream using a StreamReader for easy access.  
          StreamReader reader = new StreamReader(dataStream);
          // Read the content.  
          var responseFromServer = reader.ReadToEnd();
          responseFromServer.ToArray();
          /*I have tried:
          responseFromServer.ToArray();(because result on php page is an array.
    I have tried responseFromServer.ToString();*/
          MessageBox.Show(responseFromServer);
      }
  </code></pre>
  
  <p>My PHP code (Web service):</p>
  
  <pre><code>&lt;?php
  // Database Structure 
  require_once('connect.php');
  
  //Get password from the database for the user
  $stmtus = $conn-&gt;prepare("SELECT password from `Users` where `email` = :Username");
  $stmtus-&gt;bindParam(':Username', $username);
  $username= $_GET['username'];;
  $stmtus -&gt; execute();
  $password = $stmtus-&gt;fetch();
  
  $un = $_GET['username'];
  $pw = $_GET['password'];
  $ust = $_GET['Token'];
  
  if(password_verify($pw, $password[0])){
      $stmt = $conn-&gt;prepare("SELECT 
      COUNT(Token) AS cnt FROM `SoftwareToken` 
      LEFT JOIN User ON iduser = SoftwareToken.Consultant 
      WHERE Token = '$ust' 
      AND username = '$un'");
      $stmt-&gt;bindValue(':Username', $un);
      $stmt-&gt;bindValue(':Token', $ust);
      $stmt-&gt;execute();
      $result= array();
      while($SToken= $stmt-&gt;fetch(PDO::FETCH_OBJ)){
      array_push($result, $SToken-&gt;cnt);  
      }
  echo json_encode($result);
  
  }
  
  $conn = null;
  
  ?&gt;
  </code></pre>
  
  <p>I am battling to understand how I call the web service from the C# application, how do I pass the variables from the C# application to the web service and how do I return the json_encode to the C# application from the web service. </p>
  
  <p>I am not a full-time programmer and this is my first encounter with web services. If there are any suggestions on how to improve either of the codes, I would much appreciate. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have updated my code as assisted. When I run the php code with variables it runs and gives me a $result (array). A numeral answer 1.</p>
  
  <p>When I test my code to display the result in a MessageBox, the MessageBox is empty. Why ?</p>