Question

this question could be completely redundant and I apologize for that. But I have this code in my android app using flash builder to send data to the webservice

     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);

And I want to insert this data returned into a SQLServer. And for that I have written this webservice.

 [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;
        }
    }

But, I don't see any data inserted and I don't see any error. So, I am not sure what is wrong. Probably this entire this is wrong. But, please tell me what is the problem with this code? And is there a way to see the data sent by my flex HTTPService? Thank you so much!

Was it helpful?

Solution

Well I used Webserivce in flex instead of the HTTP Service, since I was working with a .net Webservice. And that worked like a charm.

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

And all I had to do in the event where I wanted to send the data to my webservice was to just have something like this

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

Where ResultsQuestion is a Array Collection.

But, I am not sure what is the disadvantage/advantage of using Webservice over HTTPSerive? Thank you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top