1

I created a WebService in C#. In it I have a method:
I created a AndroidWebservices.asmx and a Default.aspx with the same method on each page

[System.Web.Services.WebMethod]
public bool CheckLogin(string email, string password)
{
 //Get the User Information
 DB.User cur_user = DB.User.ByEmail(email.Trim());
 if (cur_user.CheckPassword(password)) {
 return true;
 } else {
 return false;
 }
}

for the Default.asxp page I put in
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" EnablePartialRendering="true" runat="server"></asp:ScriptManager>

and for the AndroidWebService.asmx I uncommented
[System.Web.Script.Services.ScriptService]


This service is being run off of http://localhost:49524/ and also my companys .com domain as well

I created a new directory on a tomcat server:

http:// localhost:8080/

the code for this is a simple table

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <meta name="viewport" content="user-scalable=no, width=device-width" />
 <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
 <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
 <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
 <script src="js/iphone.js"></script>
 <title></title>
</head>
<body>
 <div id="container">
 <div id="header">
 <h1><a></a></h1>
 <div class="loginContainer">
 <table cellpadding="0" cellspacing="0" width="100%">
 <tr>
 <td valign="top" style="width:100px">
 <div class="rounded-end">email</div>
 </td>
 <td valign="top">
 <input type="text" id="email" class="login" />
 </td>
 </tr>
 <tr>
 <td valign="top" style="width:100px">
 <div class="rounded-end">password</div>
 </td>
 <td valign="top">
 <input type="password" id="password" 
 class="login" />
 </td>
 </tr>
 </table>
 <input type="button" class="loginButton" value="login" 
 onclick="loginCheck(); return false;"/>
 </div> 
 </div>
 </div>
</body>
</html>

And the Javascript:

function loginCheck() {
 var u = $('#email').val();
 var p = $('#password').val();
 $.ajax({
 type: "POST",
 url: "http://localhost:49524/mobile/Android/Default.aspx/CheckLogin",
 data: JSON.stringify({email: u, password: p}),
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: function (msg) {
 alert(msg);
 }
 });
}

The things I've tried:

dataType: "json"

Returns nothing.

dataType: "jsonp"

Returns the page.. i.e.

"<!doctype><html> ...... "

Whenever i run the Default.aspx as my url the function returns the html/text of the page, i can put the code plus the + querystring in the URL and i get the page back.. but no data It doesn't seem to be calling the method but rather just returning the page.. as stated above.. What I am after is returning a true or a false to ensure the login of the user to proceed to the next page.

I do appreciate people commenting and I had to go back to the office before working on it again. I will mark a accepted answer as soon as I get one that works.

Jaak Kütt
2,6764 gold badges35 silver badges41 bronze badges
asked Feb 25, 2013 at 21:43
8
  • also i run with the console on, so i know when i get a same-origin-error Commented Feb 25, 2013 at 21:44
  • 1
    It doesn't look like you are returning anything in your if block. Commented Feb 25, 2013 at 21:46
  • thats a typo, i am returning true or false Commented Feb 25, 2013 at 21:47
  • Title and typo fixed with edit and i also posted my full html file Commented Feb 25, 2013 at 21:51
  • 1
    Please tell me you aren't checking login status on the client side?! Commented Feb 25, 2013 at 22:06

2 Answers 2

2

I think that's because you marked your Method as protected. Mark it as public, then try again.

So

protected bool CheckLogin(string email, string password)

becomes

public bool CheckLogin(string email, string password)
answered Feb 25, 2013 at 22:05
Sign up to request clarification or add additional context in comments.

1 Comment

this didn't fix the error, but i did make the change because you are right it needs to be public not protected.. but i am still getting the html as a response rather then the boolean.
0

I used a $.jsonp plugin that saved the day It made the ajax call easier..
I also had to put this in my webconfig:

<webServices>
 <protocols>
 <add name="HttpGet"/>
 <add name="HttpPost"/>
 </protocols>
</webServices>
answered Feb 26, 2013 at 16:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.