PDA

View Full Version : Params format for HttpProxy and WebServices



pl
27 Nov 2007, 6:04 AM
Hi all,

I've been browsing the forums and I cant seem to find an answer that works for me so far.

Let me start by saying that I'm new to both Extjs and ASP.NET so please keep that in mind ;)

I keep on getting "Missing Parameter strWhere" for the following code:

JS:


Ext.onReady(function() {
var RecordDef = Ext.data.Record.create([
{name: 'id'},
{name: 'requesttype'}
]);
var xmlread = new Ext.data.XmlReader({ record: 'row' }, RecordDef);
var dsgrid= new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'RequestListService.asmx/listRequests', baseParams:{strWhere: 'WHERE id < 100'}}),
reader:xmlread
});
var grid = new Ext.grid.GridPanel({
store: dsgrid,
columns: [
{header: "ID", width: 20, sortable: true, dataIndex: 'id'},
{header: "Type", width: 20, sortable: true, dataIndex: 'requesttype'}
],
viewConfig: {
forceFit: true
},
renderTo: 'content',
title: 'My First Grid',
width: 1000,
height: 500,
frame: true
});
dsgrid.load()

});


Webservice:


[WebMethod]
public XmlDocument listRequests(string strWhere)
{
SqlConnection conn = ConnectToDb();
conn.Open();
SqlCommand custCMD = new SqlCommand("SELECT top 100 id, requesttype FROM VIEW_REQUEST_LOOKUP " + strWhere + " FOR XML AUTO, ELEMENTS", conn);
System.Xml.XmlReader myXR = custCMD.ExecuteXmlReader();

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.AppendChild(xmlDoc.CreateElement("root"));
myXR.Read();
while (!myXR.EOF)
{
XmlElement node = xmlDoc.CreateElement("row");
node.InnerXml = myXR.ReadInnerXml();
xmlDoc.FirstChild.AppendChild(node);
}
conn.Close();
conn.Dispose();
return xmlDoc;
}


Any help will be appreciated.

PL

pl
27 Nov 2007, 8:58 AM
Still cant get it to work.

if it helps here's my request and response headers:


Response Headers
Server Microsoft-IIS/5.0
Date Tue, 27 Nov 2007 16:49:34 GMT
X-Powered-By ASP.NET
X-AspNet-Version 1.1.4322
Cache-Control private
Content-Type text/plain; charset=utf-8
Content-Length 30
Request Headers
Host pars00751597
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://... .../RequestLists/RequestList.aspx
Cookie ys-ext-comp-1005=o%3Acollapsed%3Db%253A0; ys-ext-comp-1006=o%3Awidth%3Dn%253A600%5Eheight%3Dn%253A352%5Ex%3Dn%253A285%5Ey%3Dn%253A223; ASP.NET_SessionId=cepovpmmcmfyvb553p5jwrva

devnull
27 Nov 2007, 11:02 AM
are you using firebug? does it show that strWhere is in fact being sent in the post vars?
we will also trust that using raw sql code in a post var is just for debugging purposes and will be handled in a more secure manner in the final version of your app ;)

hendricd
27 Nov 2007, 11:15 AM
Given that baseParams were intended for use as static parameters for every proxy request, have you tried this instead:



dsgrid.load({params:{strWhere: 'WHERE id < 100'}})

pl
28 Nov 2007, 12:24 AM
are you using firebug? does it show that strWhere is in fact being sent in the post vars?
we will also trust that using raw sql code in a post var is just for debugging purposes and will be handled in a more secure manner in the final version of your app ;)

I am using firebug :)

The Params tab shows:
_dc 1196237971176

Is there any other ways to find my post vars in Firebug?

(Oh and yeah this is just a proof of concept application to show my manager what we can do with Extjs in our webapp :) )


Given that baseParams were intended for use as static parameters for every proxy request, have you tried this instead:

dsgrid.load({params:{strWhere: 'WHERE id < 100'}})


I have tried so far "params", "baseParams" and "extraParams"

hendricd
28 Nov 2007, 10:50 AM
Params for a POST are located in the body of the request. What do you see there in FireBug:Net?

CreamyWhiteThighs
28 Nov 2007, 2:34 PM
@pl - check out my post here (http://extjs.com/forum/showthread.php?t=19396).

shibubh
28 Nov 2007, 5:35 PM
hi pl
you have to defined webservice like this



[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Xml,UseHttpGet=true)]
public XmlDocument listRequests(string strWhere)
{
SqlConnection conn = ConnectToDb();
conn.Open();
SqlCommand custCMD = new SqlCommand("SELECT top 100 id, requesttype FROM VIEW_REQUEST_LOOKUP " + strWhere + " FOR XML AUTO, ELEMENTS", conn);
System.Xml.XmlReader myXR = custCMD.ExecuteXmlReader();

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.AppendChild(xmlDoc.CreateElement("root"));
myXR.Read();
while (!myXR.EOF)
{
XmlElement node = xmlDoc.CreateElement("row");
node.InnerXml = myXR.ReadInnerXml();
xmlDoc.FirstChild.AppendChild(node);
}
conn.Close();
conn.Dispose();
return xmlDoc;
}


try this and dont forget to install asp.net atlas

pl
29 Nov 2007, 1:04 AM
Params for a POST are located in the body of the request. What do you see there in FireBug:Net?
Forgive my noobishness but is this what you're looking for:

Response Headers
Server Microsoft-IIS/5.0
Date Thu, 29 Nov 2007 08:49:39 GMT
X-Powered-By ASP.NET
X-AspNet-Version 1.1.4322
Cache-Control private
Content-Type text/plain; charset=utf-8
Content-Length 30
Request Headers
Host pars00751597
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://.../RequestLists/RequestList.aspx
Cookie ASP.NET_SessionId=4rhlbqm2t03vj455keioa555


@pl - check out my post here.

Hmm... I hope if it is actually a bug it gets fixed soon.


hi pl
you have to defined webservice like this
...
try this and dont forget to install asp.net atlas

Actually my webservice works well as long as I don't use parameters... it even works if I pass my parameters manually in my address string (RequestListService.asmx/listRequests?paramname=param)

As for AJAX for ASP.NET I am stuck at the moment with using .Net 1.1... and I haven't seen a version of Atlas for my version of .Net.

hendricd
29 Nov 2007, 7:22 AM
Does your webservice respond to POSTs or GETs ?

pl
29 Nov 2007, 8:06 AM
Does your webservice respond to POSTs or GETs ?

In my web.config I have set up for both GET and POST. Do I need to make a modification directly in my webservice as well?

hendricd
29 Nov 2007, 8:23 AM
If you type the entire URL (with ?params) into a browser, what do ya get ?

pl
29 Nov 2007, 8:41 AM
So far even this has been working:

url: 'RequestListService.asmx/listRequests?strWhere=' + escape('WHERE id < 100'),

But it really seems like a bad/limited workaround.

pl
3 Dec 2007, 1:29 AM
Anyone else has any idea on how to do this properly?