PDA

View Full Version : Post Param data to ASP.Net Web service



kvbhaskar.net@gmail.com
12 Sep 2013, 8:48 AM
Hi, I would like to know how to pass parameters to asp.net web services. I am new to EXTJs so appreciate if you provide with sample code.

my requirement is much simple and standard, take search values and on button click fill data into grid. please advice if I am making any mistake seeing below code.

On button click how to make call to service with parameters?

Click event:
buttons: [{ text: 'Search', id: 'Search', listeners: {
click: function () {
var st = Ext.data.StoreManager.lookup('mystore');
st.proxy.extraParams = { 'param1': 'test', 'param2': 'test2' };
st.load();
}}}]

Store:
var store = new Ext.data.JsonStore({
autoLoad: true,
storeId: 'mystore',
model: 'Book',
proxy: new Ext.data.HttpProxy({
type: 'ajax',
method: 'POST',
url: "Service2.asmx/GetPeople",
headers: {'Content-type': 'application/json'},
writer: {type: 'json'},
reader: {type: 'json',root: 'd',idProperty: 'SEQ_NO'}
})
});

Grid:
var grid = Ext.create('Ext.grid.Panel', {
frame: true,
store: store,
columns: [
{ text: "SEQ_NO", width: 100, dataIndex: 'SEQ_NO' },
{ text: "column2", width: 180, dataIndex: 'column2' },
{ text: "column3", width: 115, dataIndex: 'column3' },
{ text: "column4", width: 100, dataIndex: 'column4' }
],
renderTo: 'example-grid',
width: 1230,
height: 200

});

Web Service:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
public List<Person> GetPeople(string param1, string param2)
{
string SProc = "PROC_NAME";
return Factory.GetPeopleController().GetPeople(SProc);
}
}

existdissolve
12 Sep 2013, 10:08 AM
To help others help you, I would suggest a few things:

Cleanup and properly format your code. With all of the commented out bits, plus the lack of formatting, it's incredibly difficult to read
Share the data (again, properly formatted) that is being returned from the server

kvbhaskar.net@gmail.com
12 Sep 2013, 11:22 AM
thank you for your response, sure definetly will help others, today is my first day so I can't answer other questions.

as per your suggestion, I seperate it out my code and see it below:

Hi, I would like to know how to pass parameters to asp.net web services. I am new to EXTJs so appreciate if you provide with sample code.

my requirement is much simple and standard, take search values and on button click fill data into grid. please advice if I am making any mistake seeing below code.

Issue: unable to make call to service on button click.

Click event:
buttons: [{ text: 'Search', id: 'Search', listeners: {
click: function () {
var st = Ext.data.StoreManager.lookup('mystore');
st.proxy.extraParams = { 'param1': 'test', 'param2': 'test2' };
st.load();
}}}]

Store:
var store = new Ext.data.JsonStore({
autoLoad: true,
storeId: 'mystore',
model: 'Book',
proxy: new Ext.data.HttpProxy({
type: 'ajax',
method: 'POST',
url: "Service2.asmx/GetPeople",
headers: {'Content-type': 'application/json'},
writer: {type: 'json'},
reader: {type: 'json',root: 'd',idProperty: 'SEQ_NO'}
})
});

Grid:
var grid = Ext.create('Ext.grid.Panel', {
frame: true,
store: store,
columns: [
{ text: "SEQ_NO", width: 100, dataIndex: 'SEQ_NO' },
{ text: "column2", width: 180, dataIndex: 'column2' },
{ text: "column3", width: 115, dataIndex: 'column3' },
{ text: "column4", width: 100, dataIndex: 'column4' }
],
renderTo: 'example-grid',
width: 1230,
height: 200

});

Web Service:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
public List<Person> GetPeople(string param1, string param2)
{
string SProc = "PROC_NAME";
return Factory.GetPeopleController().GetPeople(SProc);
}
}

kvbhaskar.net@gmail.com
12 Sep 2013, 1:11 PM
I figure it out and working as expected.
below code has been adjusted:
buttons: [{ text: 'Search', id: 'Search', listeners: {
click: function () {
var st = Ext.data.StoreManager.lookup('mystore');
st.proxy.extraParams = { 'param1': 'test22', 'param2': 'test22' };
st.load();
}}}]

Ext.Ajax.request({
url: "Service2.asmx/GetPeople",
method: 'GET'
})

read param value in webservice:
System.Web.HttpContext.Current.Request.Params["param1"].ToString();

Gary Schlosberg
12 Sep 2013, 7:59 PM
Glad you figured it out, and thanks for sharing the solution with the community.

kvbhaskar.net@gmail.com
18 Sep 2013, 8:19 PM
Hi,
I have some issue with pagination, basically my database has 30,000+ rows so trying to load data using remote pagination features and my page size is 25. I can't return all rows from my database because response data going to be huge and nothing will display on grid so retrieving 25 rows per page and implimented row number logic in sql that working as expected but on GUI total page count shows 1 and display message shows 1-25 of 25.

I assume, my data the totalRecords may be wrong. can anyone suggest me?, appreciate if you post some example.

In my store:
reader: new Ext.data.JsonReader({ root: 'd', totalProperty: 'totalRecords', idProperty: 'SEQ_NO' })

In Grid Panel:
remotePage: true,
bbar: Ext.create('Ext.PagingToolbar', {
store: store,
displayInfo: true,
displayMsg: 'Number of records {0} - {1} of {2}',
emptyMsg: "No data available"

}),

Response from webservice:
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfModel_Summary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
- <Model_Summary>
<SEQ_NO>121076</SEQ_NO>
<c1>37419590</c1>
<c2>JP3690400001</c2>
<c3>5302.T</c3>
<totalRecords>30000</totalRecords>
</Model_Summary>


webservice is serialized as:
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]

can anyone suggest me what I am doing wrong here?.