陈斌彬的技术博客

Stay foolish,stay hungry

iOS 星级评分

测试结果

进入页面

img

编辑内容

img

选择星数

img

调试输出

img

服务器数据库查看结果

img

C#核心代码

[WebMethod]
   public bool feedbackInsertInfo(string txt,int starnum)
   {
       //连接SQL数据库
       System.Data.SqlClient.SqlConnection SqlCnn = new System.Data.SqlClient.SqlConnection("Data Source=JOHN;Initial Catalog=webservice;User ID=sa;Password=12345678;");
       //打开数据库连接
       SqlCnn.Open();
       string sqlstr = "insert into dbo.feedback (txtcontent,starnumber) values('" + txt + "','" + starnum +"')";
       System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
       cmd.Connection = SqlCnn;
       cmd.CommandType = System.Data.CommandType.Text;
       cmd.CommandText = sqlstr;
       //执行 
       cmd.ExecuteNonQuery();
       //关闭数据库
       SqlCnn.Close();
       return true;
      }

iOS核心代码

img

    -(void)startRequest
{
    NSString *strURL = [[NSString alloc] initWithFormat:@"http://192.168.40.10/FeedBack/WebService1.asmx"];
    NSURL *url = [NSURL URLWithString:[strURL URLEncodedString]];

    NSString * envelopeText = [NSString stringWithFormat:@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                               "<soap:Body>"
                               "<feedbackInsertInfo xmlns=\"http://tempuri.org/\">"
                               "<txt>%@</txt>"
                               "<starnum>%d</starnum>"
                               "</feedbackInsertInfo>"
                               "</soap:Body>"
                               "</soap:Envelope>",_contentTextView.text,[singleManager sharedInstance].number];

    NSData *envelope = [envelopeText dataUsingEncoding:NSUTF8StringEncoding];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:envelope];
    [request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", [envelope length]] forHTTPHeaderField:@"Content-Length"];

    NSURLConnection *connection = [[NSURLConnection alloc]
                                   initWithRequest:request delegate:self];

    if (connection) {
    }
}

Resource Reference