all groups > dotnet xml > february 2006 >
You're in the

dotnet xml

group:

XML Trouble Moving to .Net


XML Trouble Moving to .Net DouglasABaker NO[at]SPAM gmail.com
2/1/2006 8:42:02 AM
dotnet xml: 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...
Re: XML Trouble Moving to .Net DouglasABaker NO[at]SPAM gmail.com
2/1/2006 11:26:02 AM
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.GetResponseStream())
Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument
doc.Load(myReader)
Re: XML Trouble Moving to .Net DouglasABaker NO[at]SPAM gmail.com
2/1/2006 1:03:43 PM
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)
Re: XML Trouble Moving to .Net Martin Honnen
2/1/2006 6:11:58 PM


[quoted text, click to view]

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
Re: XML Trouble Moving to .Net Martin Honnen
2/2/2006 1:18:42 PM


[quoted text, click to view]


[quoted text, click to view]

The above looks fine but why the next two lines?
[quoted text, click to view]

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

[quoted text, click to view]



--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button