473,410 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

XML Trouble Moving to .Net

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
4 825


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
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
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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: weston | last post by:
So, I'm attempting to code an expanding tree menu, based off of unordered lists containing unordered lists. I'm also trying to do it in such a way that none of the javascript has to go inline with...
0
by: Kenneth Myhra | last post by:
I am having some trouble debugging a project that is set up to be Registered as COM Interop. I will try to explain the problem here: If I add some code to the project, to for example the xxx.cs...
5
by: Ron Weldy | last post by:
In moving a ASP.NET site from a W2K IIS5 server to a new W2K3 IIS6 server, we are having trouble with what appears to be ASP.NET server side includes in the .shtml files. I did not set up the old...
2
by: RSH | last post by:
Hi, I am having a little trouble with a Visual Studio project. I moved and existing project to a Network share and now when I go to run the project in Debug mode I get an error saying "The...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
3
by: weston | last post by:
I'm making a foray into trying to create custom vertical scrollbars and sliders, and thought I had a basic idea how to do it, but seem to be having some trouble with the implementation. My...
2
by: Paul | last post by:
I am moving an existing app written years ago to a new server. It uses Sigma Template 1.3 and Quickform 1.1.1 and PEAR.php,v 1.1.1.1 2004/02/16 The directory structure is like this: /site...
0
by: linkswanted | last post by:
http://www.movingcompanies.co.il/supplies/boxes.html http://www.movingcompanies.co.il/residental/ http://www.movingcompanies.co.il/commercial/corporate-moves.html...
0
by: linkswanted | last post by:
We are your trusted source. World Moving & Storage is bonded and licensed by the U.S. Department of Transportation and is one of the largest residential moving and corporate relocation company in...
0
by: linkswanted | last post by:
We are your trusted source. World Moving & Storage is bonded and licensed by the U.S. Department of Transportation and is one of the largest residential moving and corporate relocation company in...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.