PDA

View Full Version : [SOLVED]C# Web Service and grid



Deleter
6 Jul 2007, 4:08 AM
I need to have an oppportunity to delete rows from grid. So, I put checkbox column. It works fine

But when I try to call Web Service method I got error from C# about Invalid Expression

So I do it in this way:

function deleteHandler(btn)
{
rowsForDelete = grid.getSelections();
deleteRow = '[';
for(var i =0; i < rowsForDelete.length; i++)
{
deleteRow= deleteRow + String.format('{{id: {0}}},', rowsForDelete[i].get('id'));

}
deleteRow = deleteRow + ']';
if(rowsForDelete.length != 0)
{
var c = new Ext.data.Connection();
c.request({
url: "ClassManagement.asmx/DeleteClass",
params: deleteRow,
method: 'POST',
scope: this,
callback: function (options, success, response)
{
if(!success)
return;
for(var i=0;i<rows.length;i++)
{
ds.remove(rows[i]);
}
grid.load();
}
})
}
}

and my Web method from service

[WebMethod()]
public bool DeleteClass(string str)
{
try{}catch(Exception ex)
{
}

return false;
}
any ideas?

liggett78
6 Jul 2007, 4:22 AM
Your C# Webservice expects a SOAP formatted message, not a line with name/value pairs or JSON.

Deleter
6 Jul 2007, 4:54 AM
And how i need to make my web service expecting string or something else?

liggett78
6 Jul 2007, 5:06 AM
Well I'm not quite sure whether it's possible at all. Webservices are all about operability, and SOAP is a way to achieve it.

Deleter
6 Jul 2007, 5:10 AM
Ok, if it's not possible to remove SOAP how can I sent array of parameters to web service?

liggett78
6 Jul 2007, 5:23 AM
You could manually construct a SOAP envelope for your message. This would probably be easy for simple data types: strings, ints etc. But gets messy for complex types.
Otherwise why don't use the existing ASP.NET page (if your pages come from ASP.NET) and post there?

Brendan Carroll
6 Jul 2007, 5:54 AM
I believe if you use microsauce's :)) asp.net ajax (ATLAS) extensions you should be able to route your web service call through thier clent-side libraries and then do a desrialize on the arg string in the webservice. At least that's what I'm hoping because that's my plan on a project I'm doing now. All preliminary testing indicates this should work. I think you'll need a home-grown adapter which extends the proxy ms injects into your page, like the one's described in the Jayrock and AspPro threads.

aconran
6 Jul 2007, 6:37 AM
Although I don't have any working experience with JayRock, I've seen that you can utilize it in C# to expose classical SOAP web services as JSON-RPC Web Services consumable by JavaScript. I'd suggest looking on the forums or google "JayRock"

Aaron

Deleter
6 Jul 2007, 11:00 PM
No man... You all are wrong!!!

I'm so stupid... Look at my JS code. On params of Ext.data.Connection i missed {}
So i need to write

params: {str: "here is parameter string"}
and it works fine!

Gunmen
18 Jul 2007, 9:19 AM
@Deleter,

I'm interested in C# webservices in combination with Ext.
Can you make a working version public?

What do you think are the advantages of Ext in relation to asp.net ajax?
Also, what can asp.net do what ext 2.0 cannot?

Thanks!

Deleter
23 Jul 2007, 12:12 AM
@Deleter,

I'm interested in C# webservices in combination with Ext.
Can you make a working version public?

What do you think are the advantages of Ext in relation to asp.net ajax?
Also, what can asp.net do what ext 2.0 cannot?

Thanks!

First of all, ASP.NET AJAX controls are very easy to use! You don't need to write massy of JavaScript code that works fine in FF but doesn't work in IE, for example. It's a big trouble - stupid Microsoft has own vision to W3C standarts, I think! It's dissapointing!(:|

About working version... What exactly do you want? I can post an example with working grid!

Gunmen
24 Jul 2007, 2:39 AM
First of all, ASP.NET AJAX controls are very easy to use! You don't need to write massy of JavaScript code that works fine in FF but doesn't work in IE, for example. It's a big trouble - stupid Microsoft has own vision to W3C standarts, I think! It's dissapointing!(:|

About working version... What exactly do you want? I can post an example with working grid!

Hi!

Yeah, I understand your standards problem. Good point.

What do you mean with FF?

Hmm, at this moment I'm catching up the literature. Ext JS is new for me, I try to understand it with usefull samples. Also, in relation with things I already understand for example C#, ASP.NET and XML webservices.

Having a working ext js grid with c# webservice as back-end would be nice for me and also for others I believe.

Thank you!

rodiniz
24 Jul 2007, 8:16 AM
Have a look here http://www.codeplex.com/GridExtender/
Its a project I am developing that transforms the grid into a server-side control.
One of the samples avaiable to download its showing a grid populated from a webservice.

magunes117
6 Aug 2007, 4:34 AM
Hi all,

@rodiniz & @Deleter

Can you please post some examples about howto populate a grid using web services?

rodiniz, I have looked at your project but failed to find a sample, sorry.

Thanks and best regards.

Deleter
12 Sep 2007, 4:22 AM
Ext.onReady(function(){
ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
method: 'POST',
url: 'WebService.asmx/MethodName'
}),
//I used XML as returning format, but you can easily use JSON - you only need to mark your WebService with ScriptService attribute, method with ScriptMethod attribute
reader: new Ext.data.XmlReader({
record: 'item',
totalRecords: 'total',
id: 'id'
}, [{name: 'id', mapping: 'id'},
{name: 'school_name', mapping: 'school_name'}
]),
remoteSort: true,
//I was to check filter, so i need to send some params everytime to web service
baseParams: { city: getCitySearchTextBox().value,
school: getSchoolNameSearchTextBox().value
}
});
This is datastore main feature that communicate with web service



//Let's send a request to service
ds.load({params:{start:0,
limit: 15,
city: getCitySearchTextBox().value,
school: getSchoolNameSearchTextBox().value
}
});

Nw let's look at our web service


[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml, UseHttpGet = true)]
public XmlDocument MethodName(int start, int limit, string sort, string dir, string city, string school)
{
do what you need to do!
return someXmldoc;
}

Send your questions to GTalk: sgorchichko[at]gmail.com or ICQ: 151570164 or MSN: s.gorchichko[at]itranisition.com