[英]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. 我创建了一个小项目,可以通过RESTful WCF服务从iPhone读取数据并将数据插入到SQL Server。 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 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. 因此,第二步是如何将数据从iPhone写入和插入sql服务器。 for this, I created first the method that insert data in my webservice:
为此,我首先创建了在Web服务中插入数据的方法:
In WCF interface: ( .cs ) 在WCF界面中:(.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 ) 实施中:(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 因此,当我在浏览器上测试Web服务(localhost / JsonWcfService / GetEmployees.svc / json / InsertEmployee / myName / MylastName / 6565)时,出现此错误:找不到服务端点
any one can help ? 有人可以帮忙吗? and if it is possible can someone help with the xcode code to send data to the web service ?
如果有人可以帮助xcode代码将数据发送到Web服务? thanks
谢谢
由于其方法是POST,因此您可以使用以下AddOn https://addons.mozilla.org/en-US/firefox/addon/restclient/测试您的Web服务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.