title: Web service asp.net POST method
body: <p>Based on this tutorial (<a href="http://www.codeproject.com/Articles/405189/How-to-access-SQL-database-from-an-iPhone-app-Via" rel="nofollow">http://www.codeproject.com/Articles/405189/How-to-access-SQL-database-from-an-iPhone-app-Via</a>)</p>
  
  <p>I try to do a WebServices in asp.net.
  the GET method works... but the POST method don't.
  (I verify with the app of chrome "POSTMAN") and have and error: 
  <strong><em>Error 404, no found
  End not found</em></strong></p>
  
  <p>I hope u can help me with that, i'm started with web services.</p>
  
  <p>code ASP.net
  <strong>The Interface</strong></p>
  
  <pre><code>namespace JsonWcfService {
  [ServiceContract]
  public interface IGetEmployees
  {
      [OperationContract]
      [WebInvoke(Method = "GET",
          ResponseFormat = WebMessageFormat.Json,
          BodyStyle = WebMessageBodyStyle.Wrapped,
          UriTemplate = "json/employees")]
      List&lt;Employee&gt; GetAllEmployeesMethod();
  }
  [ServiceContract]
  public interface IPostEmployees
  {
      [OperationContract]
      [WebInvoke(Method = "POST",
          ResponseFormat = WebMessageFormat.Json,
          RequestFormat = WebMessageFormat.Json,
          BodyStyle = WebMessageBodyStyle.Wrapped,
          UriTemplate = "json/InsertEmployee/{id1}/{id2}")]
      bool InsertEmployeeMethod(string id1, string id2);
  }   
  </code></pre>
  
  <p>}</p>
  
  <p><strong>The WFC</strong></p>
  
  <pre><code>namespace JsonWcfService
  {
   public class GetEmployees : IGetEmployees 
   {
     public List&lt;Employee&gt; GetAllEmployeesMethod()
      {
           List&lt;Employee&gt; mylist = new List&lt;Employee&gt;();
  
           using (SqlConnection conn = new SqlConnection("data source=SQLREPORTES;database=prueba;persist security info=True;user id=myuser;password=mypassword;multipleactiveresultsets=True;"))
          {
              conn.Open();
  
              string cmdStr = String.Format("SELECT * FROM dbo.EmpDB");
              SqlCommand cmd = new SqlCommand(cmdStr, conn);
              SqlDataReader rd = cmd.ExecuteReader();
  
              if (rd.HasRows)
              {
                  while (rd.Read())
                  {
                      mylist.Add(new Employee(rd.GetString(0), rd.GetString(1))); //, rd.GetDecimal(2)));
                  }
              }
              conn.Close();
          }
          return mylist;
      }
     //insert to DataBase
     public bool InsertEmployeeMethod(string id1, string id2)
     {
         int success = 0;
         using (SqlConnection conn = new SqlConnection("data source=SQLREPORTES;database=prueba;persist security info=True;user id=myuser;password=mypassword;multipleactiveresultsets=True;"))
         {
             conn.Open();
  
             //decimal value = Decimal.Parse(id3);
             string cmdStr = string.Format("INSERT INTO dbo.EmpDB VALUES('{0}','{1}')", id1, id2);
             SqlCommand cmd = new SqlCommand(cmdStr, conn);
             success = cmd.ExecuteNonQuery();
  
             conn.Close();
         }
         return (success != 0 ? true : false);
     }
     public bool UseHttpGet { get; set; }
  }
  
  [DataContract]
  public class Employee
  {
      [DataMember]
      public string firstname { get; set; }
      [DataMember]
      public string lastname { get; set; }
      [DataMember]
      public decimal salary { get; set; }
      public Employee(string first, string last)
      {
          firstname=first;
          lastname=last;
          //salary=sal;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And the web.config (Download <a href="https://www.dropbox.com/s/ebbgaly7dtu4s4s/Web.config?dl=0" rel="nofollow">Here</a>)</p>
  
  <pre><code>&lt;services&gt;
    &lt;service name="JsonWcfService.GetEmployees" behaviorConfiguration="EmpServiceBehaviour"&gt;
      &lt;endpoint address ="" binding="webHttpBinding" contract="JsonWcfService.IGetEmployees" behaviorConfiguration="web"&gt;
      &lt;/endpoint&gt;
    &lt;/service&gt;
   &lt;/services&gt;
  </code></pre>