[quoted text, click to view] Dave H wrote:
> Hello all,
>
> Novice to ASP.NET and am trying to access web service via xml. I declared a
> request and DOC object one one using MSXML the other .net framework:
>
> Dim objRequest As New MSXML2.XMLHTTP40()
> Dim objXMLDoc As New XmlDocument()
>
> What is the .net equivalent to the MSXML2.XMLHTTP40()?
>
> Thanks,
> Dave
[quoted text, click to view] What you need to use is the WebRequest object. Here's a funciton that I wrote
to POST a request (watch for wrapping in this message). This function will
return the resposne content as a string which you can load into an XMLDocument
object and parse, query via XPath, or transform using XSLT. If the web service
uses SOAP and has a WSDL there is nice capability in VS.NET (or even the free
Webmatrix tool) that will create a class for accessing the web service. BTW,
the params argument need to be in the format of that of a normal form POST
request (i.e. &field1=somevalue&field2=someothervalue&field3=...)
Public Function webFormPost(ByVal myUri As String, ByVal params As
String, ByRef errors As String) As String
Dim retString As String
Dim request As HttpWebRequest = CType(WebRequest.Create(myUri),
HttpWebRequest)
request.Method = "POST"
request.ContentLength = len(params)
request.ContentType = "application/x-www-form-urlencoded"
Dim writer As New StreamWriter(request.GetRequestStream())
Try
writer.write(params)
Catch e As Exception
errors = e.message
Finally
writer.Close()
End Try
Dim response As HttpWebResponse = request.GetResponse()
Dim strmReader As New StreamReader(response.getResponseStream())
retString = strmReader.ReadToEnd()
strmReader.close()
Return retString