0

I am accessing webservices through following .aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Params.aspx.cs" Inherits="JQueryAjax.Params" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<style type="text/css">
.loading {  background-image: url('ajax-loader.gif');  background-repeat: no-repeat; } 



</style>
    <title></title>
    <script src="jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
    function CallService() {     
    $("#lblResult").addClass("loading");  
    $.ajax({    
    type: "POST",
    url: "MyService.asmx/HelloWorld",
    data: "{}",  
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: Success, 
    error: Error     
    });     }   
      function Success(data, status) {      
       $("#lblResult").removeClass("loading"); 
       $("#lblResult").html(data.d);   
         }     
           function Error(request, status, error) 
           {        
            $("#lblResult").removeClass("loading");
            $("#lblResult").html(request.statusText); 
            }

     function CallService1() {

     $.ajax({   
     type: "POST",
     url: "MyService.asmx/Add",  
     data: "{ 'value1': " + $("#txtValue1").val() + ", 'value2': " + $("#txtValue2").val() + "}",
      contentType: "application/json; charset=utf-8",  
      dataType: "json",     
      success: OnSuccess,
      error: OnError   
      });     } 

      function OnSuccess(data, status) {   
      $("#lblResult").html(data.d); 
       } 
       function OnError(request, status, error) { 
       $("#lblResult").html(request.statusText);     
       } 


         function CallService2() {
              $("#lblResult").addClass("loading");
     $.ajax({   
     type: "POST",
     url: "MyService.asmx/Records",  
     data: "{ 'value1': " + $("#txt_login").val() + ", 'value2': " + $("#txt_pass").val() + "}",
      contentType: "application/json; charset=utf-8",  
      dataType: "json",     
      success: OnSuccess,
      error: OnError   
      });     } 

      function OnSuccess(data, status) {   
       $("#lblResult").removeClass("loading"); 
       $("#lblResult").html(data.d); 
       } 
       function Error(request, status, error) 
           {        
            $("#lblResult").removeClass("loading");
            $("#lblResult").html(request.statusText); 
            }


    </script> 



</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tbody>
                    <tr>
                        <th>
                            Value 1: 
                        </th>
                        <td>
                            <asp:TextBox ID="txtValue1" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Value 2: 
                        </th>
                        <td>
                            <asp:TextBox ID="txtValue2" runat="server" />
                        </td>
                    </tr>
                </tbody>
            </table>

            <asp:Button ID="btnGo" Text="Hello World" OnClientClick="CallService(); return false;" runat="server" />
            <asp:Button ID="Button1" Text="Add" OnClientClick="CallService1(); return false;" runat="server" />


            <asp:Label ID="lblResult" Text="&nbsp;" Width="100%" runat="server" />
            <asp:Label ID="lblRecords" Text="&nbsp;" Width="100%" runat="server" />



        </div>
        <table class="style1">
            <tr>
                <td>
                    Login ID</td>
                <td>
                    <asp:TextBox ID="txt_login" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Password</td>
                <td>
                    <asp:TextBox ID="txt_pass" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                   <asp:Button ID="Button3" Text="Login check" OnClientClick="CallService2(); return false;" runat="server" />
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

and webservice code is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;

namespace JQueryAjax
{
    /// <summary>
    /// Summary description for MyService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [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 MyService : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            System.Threading.Thread.Sleep(1000);
            return "Hello World";
        }

        [WebMethod]
        public int Add(int value1, int value2)
        {
            return value1 + value2;
        }

        [WebMethod]
      //  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string  Records(string loginid,string pass)
        {

            //if (loginid == "Admin")
            //{
            //    return "Exist";
            //}

            return "";

            //else
            //{
            //    return "Not Exist";
            //}
            //DataTable dt = new DataTable("MyDataTable");
            //dt.Columns.Add("column1", typeof(System.String));
            //dt.Columns.Add("column2", typeof(System.String));

            //DataRow dr = dt.NewRow();
            //dr["column1"] = "Your Data";
            //dr["column2"] = "Your Data";
            //dt.Rows.Add(dr);

            //dr = dt.NewRow();
            //dr["column1"] = "Your Data";
            //dr["column2"] = "Your Data";
            //dt.Rows.Add(dr);

            //return dt;

        }
    }
}

when i access Records web methods it gives me an error "internal server Error"

can any one help me!!

3
Contributors
8
Replies
14
Views
4 Years
Discussion Span
Last Post by erum
0

thanks pritaeas for ur reply webservice is workingfine ichecked on browse :(

0

Set default browser to Google Chrome and launch the application. Click F12 . Go to Network tab after getting the error and click “Refresh Button. Debugger would show detailed description of the problem. The same debugger exists in latest Mozilla Firefox or Internet Explorer version.

0

thanks pritaeas ..how to check error log ??firebug in firefox ???

0

well gediminas i execute code in fire fox and it shows 2 things in error console

Could not read chrome manifest 'file:///C:/Program%20Files/Mozilla%20Firefox/extensions/%7B972ce4c6-7e08-4474-a285-3208198ce6fd%7D/chrome.manifest'.

Timestamp: 12/30/2012 8:50:43 AM
Warning: XUL box for _moz_generated_content_after element contained an inline #text child, forcing all its children to be wrapped in a block.
Source File: chrome://browser/content/browser.xul
Line: 0

0

the issue has been solved ..there was no problem with webservice code ..the problem exist only in calling time of webmethod

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.