How to pass objects across applications

I am having one windows application which calls an asp.net webpage.

i want to return a file stream object form asp.net page & want to access that filestream object in windows application.

can any body tell me how to do that.

i am calling the webpage like this.

Dim url as string

url = "Http:\\localhost\Sample\WebForm1.aspx"

Dim WebRequest As HttpWebRequest = HttpWebRequest.Create(url)

when i try to get response stream like this

Dim stream As Stream = response.GetResponseStream()

it returns nothing

how can i get filestream object returned by asp.net page in windows app.

Thanks



Answer this question

How to pass objects across applications

  • WilsonNg

    Can you provide a bit more detail Are you seeing an exception

    You read the stream and there is no data If this is the case, you can use netmon or System.Net tracing to determine if data is being sent accross the wire: http://blogs.msdn.com/dgorti



  • ulu

    I think you are misundestanding how the data generated in your retStream() function is sent over the wire. Just because you return an object from that function doesn't mean that it was written to the network as the response to the HttpWebRequest. You need to serialize the data and write it to the HttpResponse (not HttpWebResponse). In other words, in your ASPX code, you need write the data using "Response.Write()".



  • eddie d

    Hi Mike,

    when i try to iterate through the stream then i get this exception

    Dim response As HttpWebResponse = CType(iRequest.GetResponse(), HttpWebResponse)

    Dim stream As Stream = response.GetResponseStream()

    An unhandled exception of type 'System.NotSupportedException' occurred in system.dll

    Additional information: This stream does not support seek operations.

    Thanks


  • anfortas

    Hi Mike,

    I have changed my code a bit in this aspx page i am sending you that, this returns some xml code that i want to receive in my windows app but i am getting full response that an aspx page generates, can you tell me how can i get only xml code that aspx page generates.

    here is the code of aspx file.

    Protected iXmlDocument As New XmlDocument

    Protected iRoot As XmlElement

    Protected iSoapEnvelope As XmlDocument = New XmlDocument

    Protected iSoapHeader As XmlElement

    Protected iSoapBody As XmlElement

    Protected iAction As String

    Private iURL As String

    Private iCompressThreshold As Integer

    Private iSoapSchema As String = "http://schemas.xmlsoap.org/soap/envelope/"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    retStream()

    End Sub

    Public Function retStream() As XmlDocument

    iSoapEnvelope.AppendChild(iSoapEnvelope.CreateXmlDeclaration("1.0", "UTF-8", "yes"))

    'Write SOAP Envelope

    iSoapEnvelope.AppendChild(iSoapEnvelope.CreateElement("soapenv", "Envelope", iSoapSchema))

    iSoapHeader = iSoapEnvelope.CreateElement("soapenv", "Header", iSoapSchema)

    iSoapEnvelope.FirstChild.NextSibling.AppendChild(iSoapHeader)

    AddHeaderElement("action", "workloadlist")

    AddHeaderElement("sessionid", "MySession")

    CreateHeaderElements(iSoapHeader)

    iSoapBody = iSoapEnvelope.CreateElement("soapenv", "Body", iSoapSchema)

    iSoapEnvelope.FirstChild.NextSibling.AppendChild(iSoapBody)

    iXmlDocument.AppendChild(iXmlDocument.CreateElement("processX"))

    iRoot = iSoapEnvelope.CreateElement("process")

    If Not iXmlDocument Is Nothing Then

    iRoot.InnerXml = iXmlDocument.OuterXml

    End If

    iSoapBody.AppendChild(iRoot)

    CreateBodyElements(iRoot)

    Return iSoapEnvelope

    when i try to get this iSoapEnvelop in my windows code through these lines

    Dim response As HttpWebResponse = CType(iRequest.GetResponse(), HttpWebResponse)

    Dim stream As Stream = response.GetResponseStream()

    Dim sr As StreamReader

    sr = New StreamReader(stream, Encoding.UTF8)

    MsgBox(sr.ReadToEnd())

    this sr gives me compelete response that an aspx page generates whereas i just want the code in iSoapEnvelop.

    please help me in achieving that.

    Thanks for your support


  • Leoang

    Can you post your full snippet and stack trace What URL are you hitting Is it public facing so we can try to repro

  • Sharvie

    You will have to do some processing on contents of the stream to extract the pieces you are interested in.

  • How to pass objects across applications