title: Issues on converting the java code to c#
body: <p>I tried to convert java code into cSharp .I struct on how to encode the data so please help me how to do that..</p>
  
  <p>I tried to pass the values directly without encoding then i got the error as </p>
  
  <pre><code>The remote server returned an error: (400) Bad Request. 
  </code></pre>
  
  <p>if i removed the headers then the error is not coming and i placed the break point in the web site the execution sequence is not stopped at the break point</p>
  
  <p>this is my java code </p>
  
  <pre><code>packagename=encodeData("some value");
  username=encodeData("some value");
  password=encodeData("some value");
  
  hc= new DefaultHttpClient();
  get= new HttpGet("http://techpalle.com/skillgun_App.svc/mobile/papers/"+chap_id+"/app");
  get.setHeader(PaperActivity.this.getString(R.string.username),username);
  get.setHeader(PaperActivity.this.getString(R.string.password),password);
  get.setHeader(PaperActivity.this.getString(R.string.packagename),packagename);
  </code></pre>
  
  <p>Converted csharp code is</p>
  
  <pre><code>string username=null;
  string password=null;
  string packagename=null;
  
  HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://localhost:2850/TechpalleNew/Skillgun_App.svc/mobile/chapters/" + "16" + "/app");
  wr.Headers["username"] = "username";
  wr.Headers["password"] = "password";
  wr.Headers["packagename"] = "packagename";
  WebResponse resp = wr.GetResponse();
  StreamReader read = new StreamReader(resp.GetResponseStream());
  string res = read.ReadToEnd();
  </code></pre>
  
  <p>My website code</p>
  
  <pre><code>namespace ISkillgun_App
  {
    [ServiceContract]
   public interface ISkillgun_App
   {
      [OperationContract]
      [System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/chapters/{sub_topic_id}/app")]
      List&lt;ChapterNames&gt; Chapters_Names(string sub_topic_id);
  
      [OperationContract]
      [System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/papers/{chapter_id}/app")]
      List&lt;Paper_Ids&gt; Paper_ids(string chapter_id);
  
      [OperationContract]
      [System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/questions/{paper_id}/app")]
      List&lt;Qtions_data&gt; Qtions_data(string paper_id);        
   }
  }
  
  namespace Skillgun_App:ISkillgun_App
  {
   public List&lt;ChapterNames&gt; Chapters_Names(string sub_topic_id)
   Breakppoint    {
          List&lt;ChapterNames&gt; chptrsdetails = new List&lt;ChapterNames&gt;();
          using (SqlConnection cn = new SqlConnection(strConnection))
          {
              using (SqlCommand cmd = new SqlCommand("skillgun_mobile_app_Qtions_data", cn))
              {                    
                  cmd.CommandType = CommandType.StoredProcedure;                    
                  try
                  {
                      SqlParameter p1 = new SqlParameter("@type", SqlDbType.VarChar, 20);
                      SqlParameter p2 = new SqlParameter("@topic_or_paper_id", SqlDbType.Int);
                      p1.Value = "chapters_data";
                      p2.Value = sub_topic_id;
                      cmd.Parameters.Add(p1);
                      cmd.Parameters.Add(p2);
  
                      cmd.Parameters.Add("@username", SqlDbType.VarChar, 40);
                      cmd.Parameters["@username"].Direction = ParameterDirection.Output;
  
                      cmd.Parameters.Add("@password", SqlDbType.VarChar, 40);
                      cmd.Parameters["@password"].Direction = ParameterDirection.Output;
  
                      cmd.Parameters.Add("@package_name", SqlDbType.VarChar, 50);
                      cmd.Parameters["@package_name"].Direction = ParameterDirection.Output;
  
                      cn.Open();
                      SqlDataReader drtopics = cmd.ExecuteReader();
                      while (drtopics.Read())
                      {
                          ChapterNames qbsubchapter = new ChapterNames();
                          qbsubchapter.Qbc_id = (int)drtopics["qbc_id"];
                          qbsubchapter.Qbc_nameofChapter = drtopics["qbc_nameofChapter"].ToString();
                          qbsubchapter.Qbc_no_of_papers = (int)drtopics["qbc_no_of_papers"];
                          qbsubchapter.Qbc_no_of_questions = (int)drtopics["qbc_no_of_questions"];
  
                          chptrsdetails.Add(qbsubchapter);
                      }
                      drtopics.Close();
  
                      cn.Close();
  
                      string topic_username = cmd.Parameters["@username"].Value.ToString();
                      string topic_password = cmd.Parameters["@password"].Value.ToString();
                      string topic_package_name = cmd.Parameters["@package_name"].Value.ToString();                        
                      bool result = check_user(topic_username, topic_password, topic_package_name);
  
                      if (result == true)                                              
                          return chptrsdetails;                        
                      else
                          return null;
                  }
                  catch (SqlException ex)
                  {
                      return null;
                  }
                  finally
                  {
                      if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
                  }
              }
          }
      }
  
    public bool check_user(string topic_username, string topic_password, string topic_package_name)
      {
          string requestedUrl = OperationContext.Current.IncomingMessageHeaders.To.AbsoluteUri;
          if (WebOperationContext.Current != null)
          {
              if (WebOperationContext.Current.IncomingRequest != null)
              {
                  if (WebOperationContext.Current.IncomingRequest.Headers["username"] != null &amp;&amp; WebOperationContext.Current.IncomingRequest.Headers["password"] != null &amp;&amp; WebOperationContext.Current.IncomingRequest.Headers["packagename"] != null)
                  {
                      string username = WebOperationContext.Current.IncomingRequest.Headers["username"];
                      string pwd = WebOperationContext.Current.IncomingRequest.Headers["password"];
                      string pckgname = WebOperationContext.Current.IncomingRequest.Headers["packagename"];
                      bool result = Base64Decode(username, pwd, pckgname, topic_username, topic_password, topic_package_name);
                      if (result == true)
                          return true;
                      else
                          return false;
                  }
              }
          }
          return false;
      }
  </code></pre>