By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

XML Trouble Moving to .Net

P: n/a
I'm having problems getting this to return a response in .Net, any
ideas? I've been playing around with WebRequest/WebResponse, is that
what I should use? Thanks

sXMLMessage = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" &
vbCrLf
sXMLMessage = sXMLMessage & "<transaction>"
sXMLMessage = sXMLMessage & "<userid>" & sUserId & "</userid>"
sXMLMessage = sXMLMessage & "<password>" & sPassword & "</password>"
sXMLMessage = sXMLMessage & "</transaction>"

'Send HTTP request
set objHTTP = CreateObject("MICROSOFT.XMLHTTP")
Set objXml =CreateObject("Microsoft.XMLDOM")

Call objHTTP.open("POST", kXMLhostURL & ".asp", False)
Call objHTTP.send(sXMLMessage)
If Ucase(objHTTP.statusText) = "OK" Then
If InStr(Lcase(objHTTP.responseText), "xml") Then
objXml.loadXml(objHTTP.responsetext)
If objXml.parseError.errorCode = 0 Then

Set objNode =
objXml.selectSingleNode("//transaction_result//status_code")
if not objNode is nothing then
sStatusCode = objNode.text
end if
set objNode = nothing
etc...

Feb 1 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Do***********@gmail.com wrote:
I'm having problems getting this to return a response in .Net, any
ideas? I've been playing around with WebRequest/WebResponse, is that
what I should use?


Yes, and use XmlTextWriter to create the XML, don't use string
concatenation.
If you need to manipulate the returned XML then use an XmlDocument, if
you only want to read out values you can use XPathDocument.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 1 '06 #2

P: n/a
How do I load the XMLTextWriter into the WebRequest?

Dim myXmlTextWriter As XmlTextWriter

myXmlTextWriter.Formatting = System.Xml.Formatting.Indented
myXmlTextWriter.WriteStartDocument(False)
myXmlTextWriter.WriteStartElement("transaction")
myXmlTextWriter.WriteElementString("userid", sUserId)
myXmlTextWriter.WriteElementString("password", sPassword)
myXmlTextWriter.WriteEndElement()
Dim myRequest As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create("http://***.*****.com/******.asp")
Dim myResponse As System.Net.HttpWebResponse =
myRequest.GetResponse()
Dim myReader As System.Xml.XmlTextReader = New
System.Xml.XmlTextReader(myResponse.GetResponseStr eam())
Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument
doc.Load(myReader)

Feb 1 '06 #3

P: n/a
I figured it out in VB if anybody else needs it. Feels good when it
works.

Dim myReq As HttpWebRequest =
CType(WebRequest.Create("http://***.******.com/********.asp"),
HttpWebRequest)
myReq.Method = "POST"

Dim myXmlTextWriter As XmlTextWriter = New
XmlTextWriter(myReq.GetRequestStream(), System.Text.Encoding.UTF8)

myXmlTextWriter.Formatting = System.Xml.Formatting.Indented
myXmlTextWriter.WriteStartDocument(False)
myXmlTextWriter.WriteStartElement("transaction")
myXmlTextWriter.WriteElementString("userid", sUserId)
myXmlTextWriter.WriteElementString("password", sPassword)
myXmlTextWriter.WriteEndElement()

Dim doc As XmlDocument = New XmlDocument
doc.WriteTo(myXmlTextWriter)
myXmlTextWriter.Close()

Dim myResp As HttpWebResponse
myResp = CType(myReq.GetResponse, HttpWebResponse)
Dim MyReader As StreamReader = New
StreamReader(myResp.GetResponseStream)
Dim strResult
strResult = MyReader.ReadToEnd
MyReader.Close()
Response.Write(strResult)

Feb 1 '06 #4

P: n/a


Do***********@gmail.com wrote:

Dim myReq As HttpWebRequest =
CType(WebRequest.Create("http://***.******.com/********.asp"),
HttpWebRequest)
myReq.Method = "POST"

Dim myXmlTextWriter As XmlTextWriter = New
XmlTextWriter(myReq.GetRequestStream(), System.Text.Encoding.UTF8)

myXmlTextWriter.Formatting = System.Xml.Formatting.Indented
myXmlTextWriter.WriteStartDocument(False)
myXmlTextWriter.WriteStartElement("transaction")
myXmlTextWriter.WriteElementString("userid", sUserId)
myXmlTextWriter.WriteElementString("password", sPassword)
myXmlTextWriter.WriteEndElement()
The above looks fine but why the next two lines? Dim doc As XmlDocument = New XmlDocument
doc.WriteTo(myXmlTextWriter)
You create a new empty XmlDocument and write that to the XmlTextWriter?
Why do think you need that?
I would simply expect you to call e.g.
myXmlTextWriter.WriteEndDocument()
and then close the writer as you do
myXmlTextWriter.Close()


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.