简体   繁体   中英

How to enter data into SQL database from an iPhone app Via RESTful WCF service hosted on IIS 7.5

I have created a small project that can read and insert data from iPhone to sql server via RESTful WCF service. I have read the data successfully with the following the approach in this link :

http://www.codeproject.com/Articles/405189/How-to-access-SQL-database-from-an-iPhone-app-Via

So the second step is how to write and insert data from the iPhone to sql server. for this, I created first the method that insert data in my webservice:

In WCF interface: ( .cs )

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Wrapped,
    UriTemplate = "json/InsertEmployee/{id1}/{id2}/{id3}")]
bool InsertEmployeeMethod(string id1,string id2, string id3);

In Implementation: ( svc.cs )

  public bool InsertEmployeeMethod(string id1,string id2, string id3)

{

   int success = 0;

   using (SqlConnection conn = new SqlConnection("server=(local);database=EmpDB;Integrated Security=SSPI;"))
   {
       conn.Open();

       decimal value= Decimal.Parse(id3);
       string cmdStr = string.Format("INSERT INTO EmpInfo VALUES('{0}','{1}',{2})",id1,id2,value);
       SqlCommand cmd = new SqlCommand(cmdStr, conn);
       success = cmd.ExecuteNonQuery();

       conn.Close();
   }

   return (success != 0 ? true : false);

}

so when i test the web service ( localhost/JsonWcfService/GetEmployees.svc/json/InsertEmployee/myName/MylastName/6565 ) on the browser i get this error :Service Endpoint not found

any one can help ? and if it is possible can someone help with the xcode code to send data to the web service ? thanks

由于其方法是POST,因此您可以使用以下AddOn https://addons.mozilla.org/en-US/firefox/addon/restclient/测试您的Web服务

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM