Hello everyone,
I'm trying to make a small application that checks on submission if a user is human or not by just copying what's shown on a page and submitting it for validation. OK, I have a few errors with this piece of code and am unsure how to fix it as I'm very very new to c# community.
// HumanCheckerApp.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication3
{
public partial class _Default : System.Web.UI.Page
{
string genRanNum;
HumanCheckerService.HumanCheckerApplication humanCheck = new HumanCheckerService.HumanCheckerApplication();
protected void Page_Load(object sender, EventArgs e)
{
genRanNum = humanCheck.RandomNumberGenerator();
//Display generated numbers
Label1.Text = genRanNum;
}
protected void Button1_Click(object sender, EventArgs e)
{
//Send input to webservice for validation
Label2.Text = humanCheck.HumanChecker(txtBox.Text);
}
}
}
// service1.asmx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService2
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/", Name = "Human Checker Service", Description= "This checks whether a user is human or not.")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string RandomNumberGenerator()
{
Random random = new Random();
string num = "";
for (int i = 0; i <= 9; i++)
{
num += random.Next(0, 9);
}
return num;
}
[WebMethod]
public string HumanChecker(string str)
{
if (str == this.RandomNumberGenerator())
{
return "You are a human.";
}else{
return "You aren't a human!";
}
}
}
}
Thanks in advance, folks.