c# - Web service asp.net POST method -


based on tutorial (http://www.codeproject.com/articles/405189/how-to-access-sql-database-from-an-iphone-app-via)

i try webservices in asp.net. method works... post method don't. (i verify app of chrome "postman") , have , error: error 404, no found end not found

i hope u can me that, i'm started web services.

code asp.net the interface

namespace jsonwcfservice { [servicecontract] public interface igetemployees {     [operationcontract]     [webinvoke(method = "get",         responseformat = webmessageformat.json,         bodystyle = webmessagebodystyle.wrapped,         uritemplate = "json/employees")]     list<employee> 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); }    

}

the wfc

namespace jsonwcfservice {  public class getemployees : igetemployees   {    public list<employee> getallemployeesmethod()     {          list<employee> mylist = new list<employee>();           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 * 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 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 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;     } } 

}

and web.config (download here)

<services>   <service name="jsonwcfservice.getemployees" behaviorconfiguration="empservicebehaviour">     <endpoint address ="" binding="webhttpbinding" contract="jsonwcfservice.igetemployees" behaviorconfiguration="web">     </endpoint>   </service>  </services> 

well in web.config you're using contract igetemployees doesn't have definition insertemployee method need merge 2 interfaces in 1 interface , modify web.config instead of

contract="jsonwcfservice.igetemployees" 

with contract="jsonwcfservice.iemployees" iemployees define 2 methods , post method


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -