Wednesday, October 19, 2011

Step 2 : From SOAP to WCF-RESTful-POST

From SOAP to WCF-RESTful-POST

Simple step 2 :

http://pantestmb.blogspot.com/2011/02/personpassport4asmx.html

SOAP

[WebMethod(Description = "Method to Add User")]
public bool AddUser(string username, string password, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "INSERT INTO users(username,password,name,email)
values('" + username + "', '" + password + "', '" + name + "', '" + email + "');";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
returnBool=true;
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}





WCF REST POST :





    [DataContract(Namespace = "")]
    public class RequestData
    {
        [DataMember]
        public string details { get; set; }
    }


    [DataContract]
    public class PersonData
    {
        [DataMember]
        public string Name { get; set; }


        [DataMember]
        public string User { get; set; }


        [DataMember]
        public string Email { get; set; }


        [DataMember]
        public string Password { get; set; }
    }







        public PersonData AddUser(RequestData rData)
        {
            bool returnBool = false;


            var data = rData.details.Split('|');
            var response = new PersonData
            {
                Name = data[0],
                User = data[1],
                Email = data[2],
                Password = data[3]
            };


            SqlConnection dbConn = new SqlConnection(connStr);
            string sqlStr = "INSERT INTO users(username,name,email,password)
                                values('" + data[0] + "', '" + data[1] + "', '" + data[2] + "', '" + data[3] + "');";

            SqlCommand dbCommand = new SqlCommand(sqlStr, dbConn);
            try
            {
                dbConn.Open();
                if (dbCommand.ExecuteNonQuery() != 0)
                {
                    returnBool = true;
                }
                returnBool = true;
            }
            catch
            {
                returnBool = false;
            }
            dbConn.Close();
            return response;
        }



the result on fiddler





the result on SQL Server DataBase



Full Code on Google.Docs :
https://docs.google.com/document/d/1H0d2gq22-SsTElxI_mBEdAiagEOQL4HPXLInDHLDorg/edit?hl=en_GB

~ a 7z file ~ Visual Web Developer Express 2010 ~ full project :
https://docs.google.com/leaf?id=0BzKVfKe--t_cYTc4MWZkZjMtM2VmYi00OWIyLWJkMDgtN2FmOWE0ZGM4YTY5&hl=en_GB

Dumped Database can be downloaded at :
https://docs.google.com/leaf?id=0BzKVfKe--t_cYjAzOTk5YmEtNjk1ZS00ZTcxLWIzMDgtYTMwMTVlMTQwZDVi&hl=en_GB


1 comment:

  1. Certain news blogs other than attract perusers to have their very own unique exchanges. The space attracts you to make a gander at the aftereffects of different events and separate current issues. mediosindependientes

    ReplyDelete