Saturday, September 27, 2008

ASP.NET: How to call webservice with parameters through extJs HttpProxy class.

In this post I am going to explain how we can call a C# asp.net webservice with parameters through extJs HttpProxy class.

You have to do this:

var storeName = new Ext.data.Store

({

proxy: new Ext.data.HttpProxy

({

url: 'webserviceName/methodName,

method: 'POST'

}),

baseParams: {parameter1: p1,parameter2 p2},

reader: readerName,

});

In webservice you have to write:

[WebMethod]

[ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]

public void GetData(int p1, int p2)

{

// outString is a JSON formated string

Context.Response.Write(outString);

}

Labels: , ,

Post a Comment(3 comments)

Nice and simple :D We love to see our community members helping others.

Looking forward to more blog posts!

Aaron Conran
Ext JS Core Developer
That's very nice. Exactly what I was looking for too! Needed that Json part. tyvm
The JSON formated string could be like this:

string outString = "{\"Status\":[";

foreach(DataRow dr in dt.Rows)
{
if(dt.Rows.Count>i+1)
outString = outString + "{" + "\"Status\":\"" + dr["name"] + "\"," + "\"status_id\":\"" + dr["status_id"] + "\"},";
else
outString = outString + "{" + "\"Status\":\"" + dr["name"] + "\"," + "\"status_id\":\"" + dr["status_id"] + "\"}]}";
i++;
}
if (dt.Rows.Count <= 0)
outString = "";