can any one tell me how to call webservice through json query here is my code.
i want pass two variable and i want to get the result of that methos say Add methos of following service.

for webservice

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

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://localhost:54727/WebSite1/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components 

    public string HelloWorld() {
        return "Hello World";

    public int Add(int x, int y)
        return x + y;

and my code for script is as follows

<script type="text/javascript">
        function getread() {
                type: "Post",
                url: "http://localhost:54727/WebSite1/WebService.asmx/HelloWorld",
                data: "{}",
                contentType: "json",
                success: funcation(msg)

which is not working and i'm call this service through

<asp:TextBox ID="text1" runat="server" ></asp:TextBox>
<asp:TextBox ID="text2" runat="server" ></asp:TextBox>
<span id="text" runat="server"></span>
<input id="in" type="button" onclick="getRead" value="Check" />

please tell me where is my misstack in the code.

You should be able to call the webservice using a relative url

url: "WebService.asmx/HelloWorld"

the content type should look like this

contentType: "application/json; charset=utf-8"

and you may need to specify the dataType

dataType: "json"

also, your success function needs fixed

success: function(msg){
    alert(msg); // this may need to be msg.d instead of just msg
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.