Library tutorials & articles
XML SOAP
The Client
In traditional VB terms, our request to the GetSalesTax function described above, would be something such as:
dblSalesTax = GetSalesTax(100)
Returning a value of $4.
If the GetSalesTax function was contained within an external object, such as an MTS server, then the call would need to reference the server DLL:
Dim objTax As New CTaxCalc
dblSalesTax = objTax.GetSalesTax(100)
In a SOAP system the call is little different, only the request is formatted as an XML document, which is passed up to the server. The appropriate document contains the same details as the MTS call –a method to call, and the parameter name and value.
<GetSalesTax>
<SalesTotal>100</SalesTotal>
<GetSalesTax>
In order to ensure that the server can correctly identify and decrypt this method call, it is wrapped up in a larger document, called a SOAP envelope, which references the universal name-space of the SOAP envelope standard.
<SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1">
<SOAP:Header></SOAP:Header>
<SOAP:Body>
<GetSalesTax>
<SalesTotal>100</SalesTotal>
<GetSalesTax>
</SOAP:Body>
</SOAP:Envelope>
Finally, to complete our SOAP request document, we will add a name-space reference to our method call, which points to the object which contains the method – the equivalent of the object declaration (Dim objTax As New CTaxCalc) in our MTS method call.
<SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1">
<SOAP:Header></SOAP:Header>
<SOAP:Body>
<m:GetSalesTax xmlns:m="urn:myserver/soap:TaxCalc">
<SalesTotal>100</SalesTotal>
</m:GetSalesTax>
</SOAP:Body>
</SOAP:Envelope>
Now that we have built our SOAP request document, we are ready to send it to the server. The request is a simple HTTP post - just like posting a web form in your internet browser. Of course, your internet browser masks all the complexity of sending a form to a server; and in the longer-term .NET will mask this process from your VB code too. But for now, we need to do the job ourselves; and I have been using Microsoft's XML HTTP Request object to give me a helping hand. (The XMLHTTPRequest is an object within the MSXML class library (MSXML.DLL), and it comes with IE5.) Assuming that strEnvelope contains the XML document described above, the request is formatted thus:
Dim objHTTP As New MSXML.XMLHTTPRequest
Dim strEnvelope As String
'Set up to post to our localhost server
objHTTP.open "post", "http://localhost/soap/soap.asp"
'Set a standard SOAP/ XML header for the content-type
objHTTP.setRequestHeader "Content-Type", "text/xml"
'Set a header for the method to be called
objHTTP.setRequestHeader "SOAPMethodName", _
"urn:myserver/soap:TaxCalc#GetSalesTax"
'Make the SOAP call
objHTTP.send strEnvelope
'Get the return value
strReturn = objHTTP.responseBody
Now that we have sent our request, we move to the server, to see how we set up a SOAP service to listen and respond to our calls.
Related articles
Related discussion
-
How to import Xml file into a table in MS-ACCESS database using Visual Basic 6.0?
by sutanu_halder (0 replies)
-
XML transformation: how to save it into a hmtl file.
by srinathnrk (1 replies)
-
Read eMails from Outlook express using ASP
by kumaravelu (1 replies)
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
Related podcasts
-
LINQ to XML
Scott's been poking around with LINQ to XML and reports his findings to Carl about life with XDocuments and XElements. They also talk about the bridge classes that link (no pun intended) System.Xml and System.Xml.Linq.
I tried to copy the the code and add references to VB project and run the VB app. but get runtime error at the DOMDocument object accesing a single node.
Run time error 91.
MSXML2 and MTS Admin are the references I have added.
HELP!
Thanks ....
OK looks like it was the problem where the objReturn.selectSingleNode(strQuery).Text did not have anything returned that we get Object or with block variable not set.
More details at http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q283803&
Now I need to get back to look at why it was not returning anything ....
I tried to copy the the code and add references to VB project and run the VB app. but get runtime error at the DOMDocument object accesing a single node.
Run time error 91.
MSXML2 and MTS Admin are the references I have added.
HELP!
Thanks ....
In .NET web services; How to monitor from where (mostly his/her web site URL but not his/her machine IP) requester is consuming the web service? Techies, 'HTTP_REFERER' and 'URLReferrer' shows null please, suggest any other possibilities.
Great work by ComponentSource and they have very well explained VB 6.0 client and access to web service. I have a question here. How to monitor from where (mostly his/her web site URL not his/her machine IP) requester is consuming the web service? Techies, 'HTTP_REFERER' shows null please, suggest any other possibilities.
Thanks
if anyone knows the meaning of this, i could use the feedback. my hunch is, that the SOAP server is not configured to handle the request properly. but i dunno... =)
Can any one help me to identify the references and dlls required to run this code.
I want to register the dlls required and then run this code in VB4.0.
I know i need msxml.dll and the other one is it mssoap1.dll ?
if thats the one where do i get it from?
thanks in advance.
I copied all the code and followed all the instructions (including making sure the xml tags were all in the same case) and all I could get back from the soap request was ?????????????????????? etc etc with the odd † or - or = character thrown in. 2216 characters in all. I'm using vb 6 and msxml4.
Any suggestions? Did anyone get this to work?
Hi all
to use this example with msxml 2.0 or higher
change
"msxml.xmlhttprequest"
to:
"msxml2.xmlhttp"
or
"msxml2.xmlhttp26"
or
"msxml2.xmlhttp30"
...
hth
bye
Hi.
can u tell me how to fix the "dblTax = objReturn.selectSingleNode(strQuery).Text" error..pliz e.mail me
I noticed that your code appears to have been written in VB6, if this is so then a possible cause of your issues is the declarations as new. Try changing your as new statements to be just as classname and then before you use it say set myobject = new ServerXMLHTTPClass or whatever class you are creating. VB6 handled the as new statement in a way which was not always reliable and this has caused me issues before.
Hi,
I Am New To SOAP Through VB. I am getting following error
" Method 'Send' Of 'IXMLHTTPRequest' Failed".
Error Number := -2146697211
.
I am sending you the code for consideration.
Option Explicit
Dim objHTP As New MSXML.XMLHTTPRequest
Dim strEnvelope As String
Dim strreturn As String
Dim objReturn As New MSXML.DOMDocument
Dim dblTax As Double
Dim strQuery As String
''Declaration Ends Here
Private Sub taxcal()
'Create SOAP Envelope
strEnvelope = ""
strEnvelope = "<soap : envelope xmlns:soap=""urn:schemas-xmlsoap-org:soap.v1"">" & _
"<soap : header> </soap : header>" & _
"<soap : Body>" & _
"<m:getsalestax xmlns: m=""urn:myserver/soap:TaxCalculator"">" & _
"<salestotal>" & Val(txtSale.Text) & "<salestotal>" & _
"</m:getsalestax>" & _
"</Soap: Body>" & _
"</Soap: Envelope>"
'Setup To Post To Our Local Server
objHTP.open "post", "http://localhost/soap.asp", False
'Set A Standard SOAP / XML Header For The Content-Type
objHTP.setRequestHeader "Content-Type", "text/xml"
'Set A Header For The Method To Be Called
objHTP.setRequestHeader "SOAPMethodName", "urn:myserver/soap:Taxcalcultor#GetSalesTax"
'Make The SOAP Call
objHTP.send strEnvelope
'Get The Return Envelope
strreturn = objHTP.responseText
'Load The Return Envelope Into A DOM
objReturn.loadXML strreturn
'Query The Return Envelope
strQuery = "SOAP:Envelope/SOAP:Body/m:GetSalesTaxResponse/SalesTax"
dblTax = objReturn.selectSingleNode(strQuery).Text
txt_Tax.Text = dblTax
End Sub
I was wondering if someone could help me with my problem. I am using code very similar to the XML Soap in my application and it communicates succesfully when used as a windows application and as an ASP.NET project but when I try and use the same method from my Windows Service I get the exception message QueryInterface for interface 'XMLHTTPRequest' has failed when I try to execute myobject.Open ... The type of exception is an invalid cast exception even though the object was declared as new XMLHttpRequest.
Following suggestions from some web sites I put the line :
Threading.Thread.CurrentThread.ApartmentState = Threading.ApartmentState.STA
Apparently activex applications can't handle multi-threaded communication properly but this didn't stop my error from occurring. The above line I placed in my Onstart event and even tried in my New event with no success. The time at which the XMLHttpRequest is fired off is after onstart in my timer_tick event.
I am a beginner of SOAP & XML
I copy and save Soap.asp to Win2000 Server wwwroot ,
then Copy Souce code of VB Client to run , but occure some error?
dblTax = objReturn.selectSingleNode(strQuery).Text
the strQuery is not correct format,what error?
Return nothing becuase strQuery Xpath expression is case sensitive an its case doen not match whats been generated by ASP page . Eg return XML is "<soap.......
where as whats been checked in VB is <"SOAP............ A mismatch in Case
creates the object but for some reason objReq.SelectSingleNode says "Object Required"
changed above line to
Set objReq = Server.CreateObject("MSXML2.DOMDocument")
and everything worked
This thread is for discussions of XML SOAP.