Click here to Skip to main content
14,298,693 members
Rate this:
Please Sign up or sign in to vote.
Dear All,

i have WebService that get 2 string and return if they equals

WebService that in http://127.0.0.1/HTML_SIMPLE_TEST/


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    
    [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
         [WebMethod(Description = "Validate the login credentials")]
         public bool Validate(string UserName, string Password)
         {
              if (Password == "test" && UserName == "test")
                  return true;
              else
                  return false;
         }
    }


and i have html page that call this WebService and need to return the Result

<html  lang="en-US">
     <head>
         <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
         <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
         <script type="text/javascript" language="javascript">

         var Surl = "http://localhost:3031/WS_HTML/Service1.asmx/Validate";

         $(document).ready(function () {
             $("input#submit").click(function (event) {
                 //var uid = document.getElementById("UserName").value;
                 //var pwd = document.getElementById("Password").value;

                 var uid = "test";
                 var pwd = "test";

                 var dataString = "{ 'UserName' : '" + uid + "', 'Password' : '" + pwd + "'}";

                 $.ajax({
                     ServiceCallID: 1,
                     url: Surl,
                     type: 'POST',
                     data: dataString,
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",

                     success: function (result) {
                         returnVal = result.d;
                         alert(returnVal);
                     },

                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         returnVal = '';
                     }
                 });
             });
         });

 </script>

 </head>
     <body >
         <form method=post runat="server">
             <input  type="submit" />Connet to my WS
         </form>
     </body>
 </html>



I swear to God that for several days I break my head and can not figure out why it does not work

):

thanks,
Posted
Updated 6-Sep-19 10:27am
v2
Comments
   
Do you see any errors logged in console tab of Developer Tool? Have you debugged the code?
Kornfeld Eliyahu Peter 13-Jul-14 9:10am
   
Are you sure that the connection made over port 3031? Maybe it's a dynamic port assigned by VS?
goldsoft 13-Jul-14 10:07am
   
i see that Nothing happens
Ranjeet Patel 14-Jul-14 3:27am
   
http://localhost:3031/WS_HTML/Service1.asmx/Validate/UserName=test&Password=test
http://localhost:3031/WS_HTML/Service1.asmx/Validate/UserName=test/Password=test

Try to run both the upper links and verify if one of those works, It works then
$.ajax({
ServiceCallID: 1,
from this line try to remove the ServiceCallID:1, and see if any luck..
goldsoft 14-Jul-14 6:59am
   
same.......
Ranjeet Patel 14-Jul-14 8:31am
   
See that means your service is not working... so any client can not use your service.
make sure that your service is accessible and running always.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You said the url is at http://127.0.0.1/HTML_SIMPLE_TEST/[^] and in your code you have a different url, http://localhost:3031/WS_HTML/Service1.asmx/Validate[^]

All you need to do; however, is debug it. Put a breakpoint on your error function and see what the values are.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Ypu have specified in jquery that output from web method is in JSON foormat
(dataType: "json",)


Add this before web method if you are about to return output as JSON
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

banner
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100