title: How to store device id in web service in windows phone?
body: <p>this is my web service url
  <a href="http://www.newsquizapp.com/webservice/get_question" rel="nofollow">http://www.newsquizapp.com/webservice/get_question</a></p>
  
  <p>Parameter :
  1. device_id 
  2. quiz_type</p>
  
  <p>Method: post</p>
  
  <p>i already retrieve device_id &amp; quiz_type 
  but my problem is how to send device_id &amp; quiz_type so that the device id is store in web service.</p>
  
  <pre><code>    void SendPost()
      {
          var url = "http://www.newsquizapp.com/webservice/get_question";
  
          HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
          webRequest.Method = "POST";
          webRequest.ContentType = "application/x-www-form-urlencoded";
  
          webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);
      }
      void GetRequestStreamCallback(IAsyncResult callbackResult)
      {
          HttpWebRequest webRequest = (HttpWebRequest)callbackResult.AsyncState;
          Stream postStream = webRequest.EndGetRequestStream(callbackResult);
          // static device id 
          string postData = "device_id=001&amp;quiz_type=all";
  
          byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  
          postStream.Write(byteArray, 0, byteArray.Length);
          postStream.Close();
  
          webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
      }
  
      void GetResponseCallback(IAsyncResult callbackResult)
      {
          try
          {
              HttpWebRequest webRequest = (HttpWebRequest)callbackResult.AsyncState;
              HttpWebResponse response;
              response = (HttpWebResponse)webRequest.EndGetResponse(callbackResult);
              Stream streamResponse = response.GetResponseStream();
              StreamReader streamReader = new StreamReader(streamResponse);
              var Response = streamReader.ReadToEnd();
              streamResponse.Close();
              streamReader.Close();
              response.Close();
  
          }
          catch (WebException e)
          {
              // Error treatment
              // ...             
          }
      }
      public void MainPage_Loaded(object sender, RoutedEventArgs e)
      {
          client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(download);
          client.DownloadStringAsync(new Uri("http://www.newsquizapp.com/webservice/get_question"));
      }
  
      public void download(object sender, DownloadStringCompletedEventArgs e)
      {
          var objMain = JsonConvert.DeserializeObject&lt;Main&gt;(e.Result);
          question = objMain.questions;
          DisplayQuestion();
      }
      protected void DisplayQuestion()
      {
          rb1.Visibility = Visibility.Visible;
          rb2.Visibility = Visibility.Visible;
          rb3.Visibility = Visibility.Visible;
          rb4.Visibility = Visibility.Visible;
  
          Question objQue = question[counter];
          txtquestion.Text = objQue.questionTitle;
          rb1.Content = objQue.answers[0].answer;
          rb2.Content = objQue.answers[1].answer;
          rb3.Content = objQue.answers[2].answer;
  
          if (objQue.answers.Count == 3)
          {
              rb4.Visibility = Visibility.Collapsed;
          }
          else
          {
              rb4.Visibility = Visibility.Visible;
              rb4.Content = objQue.answers[3].answer;
          }
      }
      protected void radio_checked(object sender, RoutedEventArgs e)
      {
          btnFinish.Visibility = Visibility.Collapsed;
          btnSubmit.Visibility = Visibility.Visible;
      }
      protected void btnsubmit_click(object sender, RoutedEventArgs e)
      {
          Question que = question[counter];
  
          var correctAnswerId = que.correctAnswerId;
  
          string answer = string.Empty;
  
          if (que.answers[0].answerId == correctAnswerId)
          {
              answer = que.answers[0].answer;
          }
  
          if (que.answers[1].answerId == correctAnswerId)
          {
              answer = que.answers[1].answer;
          }
  
          if (que.answers[2].answerId == correctAnswerId)
          {
              answer = que.answers[2].answer;
          }
  
          if (que.answers.Count == 3)
          {
              rb4.Visibility = Visibility.Collapsed;
          }
  
          else if (que.answers[3].answerId == correctAnswerId)
          {
              answer = que.answers[3].answer;
          }
  
          if (rb1.IsChecked == true &amp;&amp; que.answers[0].answerId == correctAnswerId)
          {
              txtanswer.Text = que.answers[0].answer;
              rb1.Visibility = Visibility.Collapsed;
              rb2.Visibility = Visibility.Collapsed;
              rb3.Visibility = Visibility.Collapsed;
              rb4.Visibility = Visibility.Collapsed;
  
          }
  
          else if (rb1.IsChecked == true &amp;&amp; que.answers[0].answerId != correctAnswerId)
          {
              rb1.Visibility = Visibility.Visible;
              rb2.Visibility = Visibility.Collapsed;
              rb3.Visibility = Visibility.Collapsed;
              rb4.Visibility = Visibility.Collapsed;
              txtanswer.Text = answer;
  
          }
  
          else if (rb2.IsChecked == true &amp;&amp; que.answers[1].answerId == correctAnswerId)
          {
              txtanswer.Text = que.answers[1].answer;
              rb1.Visibility = Visibility.Collapsed;
              rb2.Visibility = Visibility.Collapsed;
              rb3.Visibility = Visibility.Collapsed;
              rb4.Visibility = Visibility.Collapsed;
          }
          else if (rb2.IsChecked == true &amp;&amp; que.answers[1].answerId != correctAnswerId)
          {
              rb1.Visibility = Visibility.Collapsed;
              rb2.Visibility = Visibility.Visible;
              rb3.Visibility = Visibility.Collapsed;
              rb4.Visibility = Visibility.Collapsed;
              txtanswer.Text = answer;
  
          }
  
          else if (rb3.IsChecked == true &amp;&amp; que.answers[2].answerId == correctAnswerId)
          {
              txtanswer.Text = que.answers[2].answer;
              rb1.Visibility = Visibility.Collapsed;
              rb2.Visibility = Visibility.Collapsed;
              rb3.Visibility = Visibility.Collapsed;
              rb4.Visibility = Visibility.Collapsed;
          }
          else if (rb3.IsChecked == true &amp;&amp; que.answers[2].answerId != correctAnswerId)
          {
              rb1.Visibility = Visibility.Collapsed;
              rb2.Visibility = Visibility.Collapsed;
              rb3.Visibility = Visibility.Visible;
              rb4.Visibility = Visibility.Collapsed;
              txtanswer.Text = answer;
  
          }
          else if (que.answers.Count == 3)
          {
              rb4.Visibility = Visibility.Collapsed;
          }
  
          else if (rb4.IsChecked == true &amp;&amp; que.answers[3].answerId == correctAnswerId)
          {
              txtanswer.Text = que.answers[3].answer;
              rb1.Visibility = Visibility.Collapsed;
              rb2.Visibility = Visibility.Collapsed;
              rb3.Visibility = Visibility.Collapsed;
              rb4.Visibility = Visibility.Collapsed;
          }
          else if (rb4.IsChecked == true &amp;&amp; que.answers[3].answerId != correctAnswerId)
          {
              rb1.Visibility = Visibility.Collapsed;
              rb2.Visibility = Visibility.Collapsed;
              rb3.Visibility = Visibility.Collapsed;
              rb4.Visibility = Visibility.Visible;
              txtanswer.Text = answer;
  
          }
          btnNext.Visibility = Visibility.Visible;
      }
  
      protected void btnnext_click(object sender, RoutedEventArgs e)
      {
          counter++;
          if (counter &gt;= question.Count)
          {
              txtanswer.Text = "no more question right now....";
          }
          else
          {
              DisplayQuestion();
          }
      }
  }
  </code></pre>
  
  <p>once the user device id stores in database, they will not get the same question if user close the app &amp; again open it...</p>