Link to home
Start Free TrialLog in
Avatar of Amien90
Amien90

asked on

webservice, getting empty response

see code. i get this back "           " .. few empty spaces. Seems like i need to wait longer for the response from server for the full content .. is that possible? how can i do this? or is there anything else wrong?

StatusDescription = OK

Specs of webservice:

called using HTTPS-POST.
The contents  format: application/x-www-form-urlencoded.
The XML structure : the form field REQUEST.
' Create a request using a URL that can receive a post. '
        Dim request As WebRequest = WebRequest.Create(url)
        ' Set the Method property of the request to POST.'
        request.Method = "POST"
        request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
        ' Create POST data and convert it to a byte array.'
        Dim postData As String = ioLines
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(ioLines)


        ' Set the ContentType property of the WebRequest.'
        request.ContentType = "application/x-www-form-urlencoded"
        ' Set the ContentLength property of the WebRequest.'
        request.ContentLength = byteArray.Length
        ' Get the request stream.'
        Dim dataStream As Stream = request.GetRequestStream()
        ' Write the data to the request stream.'
        dataStream.Write(byteArray, 0, byteArray.Length)
        ' Close the Stream object.'
        dataStream.Close()
        ' Get the response.'
        Dim response As WebResponse = request.GetResponse()
        ' Display the status.'
        Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)


        ' Get the stream containing content returned by the server.'
        dataStream = response.GetResponseStream()
        ' Open the stream using a StreamReader for easy access.'
        Dim reader As New StreamReader(dataStream)
        ' Read the content.'
        Dim responseFromServer As String = reader.ReadToEnd
        ' Display the content.'
        Console.WriteLine(responseFromServer)

        ' Clean up the streams.'
        reader.Close()
        dataStream.Close()
        response.Close()

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

What result are you expecting?
Avatar of Amien90
Amien90

ASKER

a xml file/string
What happens when you test the page through IE? Does it work as expected?
Avatar of Amien90

ASKER

Yes..

i think it is this:

The XML structure : the form field REQUEST

i think i didnt do this .. i need to put the xml content in a HTML field named REQUEST ..
how can i do this?


>i need to put the xml content in a HTML field named REQUEST ..
how can i do this?

Did not understand.
Avatar of Amien90

ASKER

i'm not sure too . manual is not that specific

but i think i need to put a <FORM NAME="REQUEST"> and </FORM> before and after the XML?
Avatar of Amien90

ASKER

its about the same that i have in my code.
the xml itself is correct. i'v checked that one.

again "html input field named 'request'" .. what does this mean?
seems like i need to embed the xml data into a input field?
help appreciated
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amien90

ASKER

Thanks for your reply .. ok .. now i got a response from the webservice in xml back . .but its an error
"An error occured while Parsing an XML document"

myremotepost.Add("REQUEST", doc.InnerText)

perhaps it has something to do with xml encoding? UTF-8/application/x-www-form-urlencoded

i have a confirmation that the content of the xml itself is valid
Try converting the encoding.
Avatar of Amien90

ASKER

is that encoding done in myremotepost.Add("REQUEST", doc.InnerText) or in the myremotepost class itself?

myremotepost.Add("REQUEST", Server.HtmlEncode(doc.OuterXml))

gives me: 500 Internal Server Error

Dim bytesUTF8 As Byte() = System.Text.Encoding.UTF8.GetBytes(TextBox1.Text)
Dim fromUTF8 As String = System.Text.Encoding.UTF8.GetString(bytesUTF8)
myremotepost.Add("REQUEST", fromUTF8)

gives me: An error occured while Parsing an XML document
Avatar of Amien90

ASKER

nevermind

myremotepost.Add("REQUEST", Server.HtmlEncode(doc.OuterXml))

is working .. the 500 internal server error is a webservice issue.
Thanks all!
Avatar of Amien90

ASKER

how do i fetch the xml reponse that i now see in my browser back in asp.net?

If Not Request.Form("field1") Is Nothing Then
Response.Write("field1 : " & Request.Form("field1") & "</br>")
End If
If Not Request.Form("field2") Is Nothing Then
Response.Write("field2 : " & Request.Form("field2") & "</br>")
End If


dont understand this. Request.Form??
Request.Form is being used to read the posted input. It is writing the input back to the output! Is the above code from the webservice?
Avatar of Amien90

ASKER

no .. its from your url. this should be used to Receiving Page (Point C) .. i guess

what i have now, is that i see the xml result in the browser. what i want to do is that i only want to output a certain node of the xml.

BTW i though that it should be possible to use the code of my first post to consume xml webservice.. Why do i need to send also html code? i know the webservice is using coldfusion.

You need to use the WebResponse class to receive the result and then use XMLDocument to parse it.

This shows the WebResponse example

http://www.c-sharpcorner.com/UploadFile/mahesh/WebRequestNResponseMDB12012005232323PM/WebRequestNResponseMDB.aspx
Avatar of Amien90

ASKER

and i put that after  myremotepost.Post()?



Dim HttpWebRequest As HttpWebRequest = WebRequest.Create(url)
Dim dataStream As HttpWebResponse = HttpWebRequest.GetResponse
Dim receiveStream As Stream = dataStream.GetResponseStream()
Dim readStream As New StreamReader(receiveStream, Encoding.UTF8)
Dim responseFromServer As String = readStream.ReadToEnd()
MsgBox(responseFromServer)

is not working
Avatar of Amien90

ASKER

i will post a new question for this