111,129
社区成员
发帖
与我相关
我的任务
分享
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "InsertAOrder")]
Dictionary<string, string> InsertAOrder(Stream stream);
public Dictionary<string, string> InsertAOrder(Stream stream)
{
StreamReader reader = new StreamReader(stream);
string str = reader.ReadToEnd();
reader.Dispose();
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> paramDic = serializer.Deserialize<Dictionary<string, object>>(str);
Dictionary<string, string> dic = new Dictionary<string, string>();
string sqlString = " insert into [C1NWind].[dbo].[Order] (ID,CustomerID,ProductID,PurchaseDate,Time,PaymentType,PaymentAmount,Quantity) values(2001,200,200,GETDATE(),GETDATE(),'Candy',100,9)";
SqlCommand com = new SqlCommand(sqlString,FJCon);
FJCon.Open();
try{
int rcount = com.ExecuteNonQuery();
if(rcount > 0){
dic.Add("result","1");
dic.Add("Pinsert", "AOrder");
} else{
dic.Add("result","0");
}
}
catch (Exception ex)
{
dic.Add("result","0");
dic.Add("exception", ex.Message.ToString());
}
FJCon.Close();
return dic;
}
[RequestManager POST:@"InsertAOrder" params:dictionary success:^(id response) {
NSLog(@"%@",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/html",@"text/plain", nil];
// 请求超时时间
manager.requestSerializer.timeoutInterval = 30;
NSString *postStr = URL;
if (![URL hasPrefix:@"http"]) {
postStr = [NSString stringWithFormat:@"%@%@", ServerUrl,URL] ;
}
NSMutableDictionary *dict = [params mutableCopy];
// 发送post请求
[manager POST:postStr parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
// 请求成功
NSDictionary *responseDict = (NSDictionary *)responseObject;
success(responseDict);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {// 请求失败
Error( operation,error);
}];