PDA

View Full Version : Read XML from Webservice .NET



polo
6 Nov 2009, 4:45 AM
Hi, i try to read xml data from a .NET (VB) web service and put my result in a grid.
I've also seen a lot of post in this forum about that, but I reach 90% of solution every time, without the complete solution...
when my extjs start, i enter in debug in webservice, but the result in my page is just the grid, without data!

so, this is my code:

Web service Code:

<WebMethod(True)> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Xml, UseHttpGet:=False)> _
Public Function InsRich_GetData() As XmlDocument


Dim xmldoc As XmlDocument
Dim xmlnode As XmlNode
Dim xmlelem As XmlElement
Dim xmlelem2 As XmlElement
Dim xmltext As XmlText
xmldoc = New XmlDocument()
'let's add the XML declaration section
xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "")
xmldoc.AppendChild(xmlnode)
xmlelem = xmldoc.CreateElement("rootnode")
xmldoc.AppendChild(xmlelem)
'let's add another element (child of the root)
xmlelem2 = xmldoc.CreateElement("myresult")
Dim Res As String = "OK"
xmltext = xmldoc.CreateTextNode(Res)
xmlelem2.AppendChild(xmltext)
xmldoc.ChildNodes.Item(1).AppendChild(xmlelem2)
Return xmldoc

End Function

ExtJS Code:

var UrlWS = 'Ws.asmx/InsRich_GetData';

Ext.onReady(test3);

function test3() {

var xmlread = new Ext.data.XmlReader({ record: 'rootnode' },
// set up the fields mapping into the xml doc
['myresult'] );
var ds = new Ext.data.Store({


proxy: new Ext.data.HttpProxy({method:'POST',url: UrlWS }),
reader:xmlread});
var cm = new Ext.grid.ColumnModel([

{ header: "myresult", width: 120, dataIndex: 'myresult' }
]);
cm.defaultSortable = true;
// create the grid
var grid = new Ext.grid.GridPanel({

store: ds,
cm: cm,
renderTo: 'example-grid',
width: 422,
height: 300
});
grid.render();
// pass params in ds.load call
ds.load(); //({a:1, b:2});
}

Thanks.
Polo