【发布时间】:2013-12-11 13:48:40
【问题描述】:
谁能告诉我创建将 JSON 发送到 MS SQL 服务器的 Web 服务的最佳方法是什么。(php 或 .net POST Web 服务?) 如果可能的话,我想在 IIS 上托管 Web 服务。教程的链接将非常有用。 非常感谢。
【问题讨论】:
标签: ios sql objective-c json web-services
谁能告诉我创建将 JSON 发送到 MS SQL 服务器的 Web 服务的最佳方法是什么。(php 或 .net POST Web 服务?) 如果可能的话,我想在 IIS 上托管 Web 服务。教程的链接将非常有用。 非常感谢。
【问题讨论】:
标签: ios sql objective-c json web-services
//Create the request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"your script name.php"]];
// create the Method "GET" or "POST"
[request setHTTPMethod:@"POST"];
//Pass The String to server
NSString *userUpdate =[NSString stringWithFormat:@"artist_email=%@ ",your string Name,nil];
//Check The Value what we passed
NSLog(@"the data Details is =%@", userUpdate);
//Convert the String to Data
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
//Apply the data to the body
[request setHTTPBody:data1];
//Create the response and Error
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
//This is for Response
NSLog(@"got response==%@", resSrt);
if(resSrt)
{
NSLog(@"got response");
}
else
{
NSLog(@"faield to connect");
}
【讨论】:
我建议使用 ASP.NET Web API,它支持开箱即用的 JSON 和 XML,并且开发相对容易,因为您不必管理 JSON 数据与 C# 对象之间的解析,然后您可以只需使用实体框架与数据库进行通信。
还有:http://www.entityframeworktutorial.net/EntityFramework4.3/Introduction.aspx 我认为这有点过时了,但核心将保持不变
【讨论】: