473,473 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help streaming XML instead of dataset

JJA
I am confused about all the various methods of handling XML in ASP.Net
2.0. I want to be able to stream XML to some clientside Javascript code
(snippet below):

var urlRequest = "../GetLendersAsXML.aspx"
var request = GXmlHttp.create();
request.open("GET", urlRequest, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;

I have all the Javascript code I need but I need to have the page above
return XML.

Using SQL 2005 I have created an HTTP endpoint and exposed a stored
procedure as a webservice. I want to add a FOR XML AUTO clause in the
stored procedure to return XML as a big string (that part is easy). The
sproc currently returns a dataset and I've got this code below that
binds it to a GridView (this works but is not what I need):

Partial Class GetLendersAsDataset
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
Dim ws As yukon.ITMO_Lenders = New yukon.ITMO_Lenders
Dim ds As System.Data.DataSet
ws.Credentials = New System.Net.NetworkCredential("myID",
"myPass", "myDomain")
Dim oa As Object()
oa = ws.GetLenderLocations("GOLDEN EMPIRE MORTGAGE")
'hardcode example for testing
If oa(1).ToString() = "System.Data.DataSet" Then
ds = DirectCast(oa(1), System.Data.DataSet)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
End If
Catch ex As ApplicationException
Response.Write(ex.ToString)
End Try
End Sub
End Class

So, if I change my stored procedure by adding FOR XML clause, then
ws.GetLenderLocations webmethod above will return XML. Can anybody
suggest code for my ASPX page to stream this XML so that my Javascript
at the top of the post can read it?

Dec 1 '06 #1
3 3362
Have you tried doing a this.Response.Write(...) in GetLendersAsXML.aspx's
OnLoad(...) override?
Dec 1 '06 #2
JJA
Thank you so much for responding. I've been researching all day on this
and the problem has morphed a bit now. First, I am trying something
close to what you suggest (i.e. I'm trying Response.OutputStream.Write
- see below).

In summary, how to convert System.Xml.XmlElement to an output stream or
byte array?

See: http://www.developer.com/db/article.php/10920_3390241_3
for a pretty good explanation of what is returned and what I am dealing
with. By adding FOR XML to my stored proc, the type returned in
oa(1).ToString is ""System.Xml.XmlElement". Removing it causes
oa(1).ToString to be equal to "System.Data.DataSet".

But I am still confused as to how to pump that data out directly. Here
is my latest attempt (but only the 2nd case for dataset works). In
short, how to convert a big chunk of type system.xml.xmlelement to byte
array or something that can be streamed out?
Here's my code:

Partial Class GetLendersAsDataset
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
Dim ws As yukon.ITMO_Lenders = New yukon.ITMO_Lenders
ws.Credentials = New System.Net.NetworkCredential("myID",
"myPass", "myDomain")
Dim oa As Object()
oa = ws.GetLenderLocations("GOLDEN EMPIRE MORTGAGE")
If oa(1).ToString() = "System.Xml.XmlElement" Then
Dim i As Integer
Dim xd As System.Xml.XmlElement
Response.ContentType = "text/xml"
xd = DirectCast(oa(1), System.Xml.XmlElement)
Dim encoding As New System.Text.ASCIIEncoding()
Dim oaCopy As Object
oaCopy = oa(1)
i = encoding.GetBytes(oaCopy)
'<---------------------blows up on this
stmt (see Server Error below)
Response.OutputStream.Write(encoding.Get
Bytes(oaCopy), 0, i)
Response.Flush()
Response.End()
End If
If oa(1).ToString() = "System.Data.DataSet" Then 'This
case works fine:
Dim ds As System.Data.DataSet
ds = DirectCast(oa(1), System.Data.DataSet)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
End If
Catch ex As ApplicationException
Response.Write(ex.ToString)
End Try
End Sub
End Class

Server Error in '/LenderLocations' Application.
--------------------------------------------------------------------------------

Overload resolution failed because no Public 'GetBytes' can be called
with these arguments:
'Public Overrides Function GetBytes(s As String) As Byte()':
Argument matching parameter 's' cannot convert from 'XmlElement'
to 'String'.
'Public Overrides Function GetBytes(chars As Char()) As Byte()':
Argument matching parameter 'chars' cannot convert from
'XmlElement' to 'Char()'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Reflection.AmbiguousMatchException: Overload
resolution failed because no Public 'GetBytes' can be called with these
arguments:
'Public Overrides Function GetBytes(s As String) As Byte()':
Argument matching parameter 's' cannot convert from 'XmlElement'
to 'String'.
'Public Overrides Function GetBytes(chars As Char()) As Byte()':
Argument matching parameter 'chars' cannot convert from
'XmlElement' to 'Char()'.

Source Error:
Line 15: Dim oaCopy As Object
Line 16: oaCopy = oa(1)
Line 17: i = encoding.GetBytes(oaCopy)
Line 18:
Response.OutputStream.Write(encoding.GetBytes(oaCo py), 0, i)
Line 19: Response.Flush()

Dec 1 '06 #3
If you want to stream it out, I'd recommend serializing it, but in reality,
your XML is basically a serialized object anyway (once it's correctly
"serialized" all the encoding is based on the runtime's settings so you can
leave them alone), so you'd be taking a serialized object (the element),
deserializing it (into an object) and then reserializing it (to send it over
the response). If the XML you get from the DB is a complete & correct XML
document, you can just stream the XML directly without doing any encoding

The particular error you are getting is caused by you passing in an
XmlElement to GetBytes rather than the expected string. That can be
resolved by replacing:
encoding.GetBytes(oa)

with:
encoding.GetBytes(oa.OuterXml)

Dec 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Markus Ernst | last post by:
Hi I know this question is rather HTTP related than PHP, but I did not find an HTTP group on my news server. I deliver some files with the following PHP syntax: header('Content-Description:...
3
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and...
2
by: Changhao | last post by:
Hi, friends, I am implementing a protocol on top of 'asyncore.dispatcher' to send streaming multimedia data over TCP socket. However, I found that the throughput of my current implementation is...
2
by: Cerebral Believer | last post by:
Hi All, I plan to use streaming audio on my site. I had uploaded some .mp3's as part of a trial, and these streamed very badly so I tried .ram (RealAudio) files instead. The RealAudio files...
8
by: Amjad | last post by:
Hi i am writing a application where i want to browse video file and copy data into stream and send that stream over network...I have develop P2P windows application where i successfully transfer...
5
by: pmakoi | last post by:
dear all this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic I am...
30
by: Alf P. Steinbach | last post by:
I once suggested in that SomeOne Else(TM) should propose a string value class that accepted literals and char pointers and so on, with possible custom deleter, and in case of literal strings just...
3
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years...
1
by: Faisal Shafiq | last post by:
I want to upload a file direct to the Silverlight Streaming Service from a Web Client such as silverlight application. As per our product requirement we want to upload a .WMV file directly from...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.