0

这个问题可能完全是多余的,对此我深表歉意。但是我在我的 android 应用程序中有这段代码,使用 flash builder 将数据发送到 web 服务

     var ResponseValue:int = 1;
    var QuestionID:int = data.QuestionID;
  ResultsQuestion = new ArrayCollection();
                            ResultsQuestion.addItem({"ResultSEQ":10000});
                            ResultsQuestion.addItem({"QuestionID":QuestionID});
                            ResultsQuestion.addItem({"ResponsePromptID":chk1.name});
                            ResultsQuestion.addItem({"ResponseValue":ResponseValue});
                                                    var service:HTTPService = new HTTPService();
service.url = "http://IPaddress:443/InsertData/Service1.asmx/HelloWorld";

//service.url = "http://localhost/InsertData/InsertData/Service1.asmx/HelloWorld";
service.method="POST";
var parameters:Object = new Object();
parameters["ResponsePromptID"]= ResultsQuestion.getItemAt(2).ResponsePromptID;
parameters["QuestionID"]= ResultsQuestion.getItemAt(1).QuestionID;
parameters["ResponseValue"]= ResultsQuestion.getItemAt(3).ResponseValue;

service.send(parameters);

我想将返回的这些数据插入到 SQLServer 中。为此,我编写了这个网络服务。

 [WebMethod]
        public string HelloWorld()
        {
            string Message;
            string MyConString = "Data Source=.\\SQLEXPRESS;Server=nameof server;Database=dbname;User ID=id;Password=password;Trusted_Connection=False; ";

  System.Data.SqlClient.SqlConnection DbConnection = new System.Data.SqlClient.SqlConnection(MyConString);
            DbConnection.Open();
            SqlCommand DbCommand = DbConnection.CreateCommand();
         string QuestionID= System.Web.HttpContext.Current.Request.Params["QuestionID"];

         // string QuestionID = "89";
            string ResultSEQ = "1999";
           string ResponsePromptID =System.Web.HttpContext.Current.Request.Params["ResponsePromptID"];
    //  string ResponsePromptID ="343";
            string ResponseValue = "12";
            DbCommand.CommandText = "Insert into [dbo].[tablename] (ResultSEQ,QuestionID,ResponsePromptID,ResponseValue) Values( @ResultSEQ,@QuestionID,@ResponsePromptID,@ResponseValue)";
            DbCommand.Parameters.AddWithValue("@ResultSEQ", ResultSEQ);
            DbCommand.Parameters.AddWithValue("@QuestionID", QuestionID);
            DbCommand.Parameters.AddWithValue("@ResponsePromptID", ResponsePromptID);
            DbCommand.Parameters.AddWithValue("@ResponseValue", ResponseValue);

            int result = DbCommand.ExecuteNonQuery();
            if (result == 1)
            {
                Message = "1";

            }
            else
            {
                Message = "2"; ;
            }
            DbConnection.Close();

            return Message;
        }
    }

但是,我没有看到任何插入的数据,也没有看到任何错误。所以,我不确定出了什么问题。可能这整个这都是错误的。但是,请告诉我这段代码有什么问题?有没有办法查看我的 flex HTTPService 发送的数据?非常感谢!

4

1 回答 1

0

好吧,我在 flex 中使用了 Webserivce 而不是 HTTP 服务,因为我正在使用 .net Web 服务。这就像一个魅力。

<fx:Declarations>
    <s:WebService id="ws" wsdl="http://uraddress:443/TestWebserives/Service1.asmx?WSDL">
        <s:operation
            name="HelloWorld"/>
    </s:WebService>
                    </fx:Declarations>

如果我想将数据发送到我的网络服务,我所要做的就是拥有这样的东西

ws.HelloWorld(ResultsQuestion.getItemAt(0).ResultSEQ,ResultsQuestion.g etItemAt(1).QuestionID,ResultsQuestion.getItemAt(2).ResponsePromptID,R esultsQuestion.getItemAt(3).ResponseValue);

ResultsQuestion 是一个数组集合。

但是,我不确定使用 Webservice 而不是 HTTPSerive 的缺点/优点是什么?谢谢

于 2012-11-14T17:59:12.593 回答