Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic VB SOAP question VB6 to ASP and back

Status
Not open for further replies.

bennynye

Programmer
Feb 8, 2002
10
0
0
US
I am running a simple SOAP example that I see everywhere on the web. The example should pass a parameter to an ASP page which in turn responds. There are only parts to the example. The VB part is as follows:

Code:
Sub Main()
  Dim objHTTP 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
  
  'Create the SOAP Envelope
  strEnvelope = _
    &quot;<soap:envelope xmlns:soap=&quot;&quot;urn:schemas-xmlsoap-org:soap.v1&quot;&quot;>&quot; & _
    &quot;<soap:header></soap:header>&quot; & _
    &quot;<soap:body>&quot; & _
    &quot;<m:getsalestax xmlns:m=&quot;&quot;urn:myserver/soap:TaxCalculator&quot;&quot;>&quot; & _
    &quot;<salestotal>100</salestotal>&quot; & _
    &quot;</m:getsalestax>&quot; & _
    &quot;</soap:body>&quot; & _
    &quot;</soap:envelope>&quot;
  
  'Set up to post to our local server
  objHTTP.open &quot;post&quot;, &quot;[URL unfurl="true"]http://www.assetmarketingsystems.net/bnye/UpdateApplication.asp&quot;,[/URL] False
  
  'Set a standard SOAP/ XML header for the content-type
  objHTTP.setRequestHeader &quot;Content-Type&quot;, &quot;text/xml&quot;
  
  'Set a header for the method to be called
  objHTTP.setRequestHeader &quot;SOAPMethodName&quot;, _
    &quot;urn:myserver/soap:TaxCalculator#GetSalesTax&quot;
  
  'Make the SOAP call
  objHTTP.send strEnvelope
  
  'Get the return envelope
  strReturn = objHTTP.responseText
  
  'Load the return envelope into a DOM
  objReturn.loadXML strReturn
  
  'Query the return envelope
  strQuery = _
    &quot;SOAP:Envelope/SOAP:Body/m:GetSalesTaxResponse/SalesTax&quot;
  dblTax = objReturn.selectSingleNode(strQuery).Text
  
  Debug.Print dblTax
End Sub

The ASP page is as follows:

Code:
<%

Set objReq = Server.CreateObject(&quot;MSXML2.DOMDocument&quot;)

'Load the request into XML DOM
objReq.Load Request

'Query the DOM for the input parameter
strQuery = &quot;SOAP:Envelope/SOAP:Body/m:GetSalesTax/SalesTotal&quot;
varSalesTotal = objReq.SelectSingleNode(strQuery).Text

'Calculate the sales tax
varSalesTax = varSalesTotal * 0.04

'Prepare the return envelope
strTmp = _
&quot;<SOAP:Envelope xmlns:SOAP=&quot;&quot;urn:schemas-xmlsoap-org:soap.v1&quot;&quot;>&quot; & _
&quot;<SOAP:Header></SOAP:Header>&quot; & _
&quot;<SOAP:Body>&quot; & _
&quot;<m:GetSalesTaxResponse xmlns:m=&quot;&quot;urn:myserver/soap:TaxCalc&quot;&quot;>&quot; & _
&quot;<SalesTax>&quot; & varSalesTax & &quot;</SalesTax>&quot; & _
&quot;</m:GetSalesTaxResponse>&quot; & _
&quot;</SOAP:Body>&quot; & _
&quot;</SOAP:Envelope>&quot;

'Write the return envelope
Response.Write strTmp

%>

If someone could give me a hint at why I am getting the a &quot;Object Variable or with block not set.&quot; at the following line of code I would appreciate it:

Code:
dblTax = objReturn.selectSingleNode(strQuery).Text

It does not appear to be a firewall. The response string is as follows:

Code:
 <font face=&quot;Arial&quot; size=2>
<p>Microsoft VBScript runtime </font> <font face=&quot;Arial&quot; size=2>error '800a01a8'</font>
<p>
<font face=&quot;Arial&quot; size=2>Object required: 'objReq.SelectSingleNode(...)'</font>
<p>
<font face=&quot;Arial&quot; size=2>/bnye/UpdateApplication.asp</font><font face=&quot;Arial&quot; size=2>, line 10</font>

Thanks for your help,

Ben
 
Hey it works. Apparently just changing the dll to the msxml4.dll through me off. The working VB code is as follows:

Code:
Sub Main()

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

   'Create the SOAP Envelope
   strEnvelope = _
      &quot;<SOAP:Envelope xmlns:SOAP=&quot;&quot;urn:schemas-xmlsoap-org:soap.v1&quot;&quot;>&quot; & _
      &quot;<SOAP:Header></SOAP:Header>&quot; & _
      &quot;<SOAP:Body>&quot; & _
      &quot;<m:GetSalesTax xmlns:m=&quot;&quot;urn:myserver/soap:TaxCalculator&quot;&quot;>&quot; & _
      &quot;<SalesTotal>100</SalesTotal>&quot; & _
      &quot;</m:GetSalesTax>&quot; & _
      &quot;</SOAP:Body>&quot; & _
      &quot;</SOAP:Envelope>&quot;

   'Set up to post to our local server
   objHTTP.open &quot;post&quot;, &quot;[URL unfurl="true"]http://www.assetmarketingsystems.net/bnye/soap.asp&quot;,[/URL] False

   'Set a standard SOAP/ XML header for the content-type
   objHTTP.setRequestHeader &quot;Content-Type&quot;, &quot;text/xml&quot;

   'Set a header for the method to be called
   objHTTP.setRequestHeader &quot;SOAPMethodName&quot;, _
      &quot;urn:myserver/soap:TaxCalculator#GetSalesTax&quot;

   'Make the SOAP call
   objHTTP.send strEnvelope

   'Get the return envelope
   strReturn = objHTTP.responseText

   'Load the return envelope into a DOM
   objReturn.loadXML strReturn
   MsgBox strReturn

   'Query the return envelope
   strQuery = _
      &quot;SOAP:Envelope/SOAP:Body/m:GetSalesTaxResponse/SalesTax&quot;
   dblTax = objReturn.selectSingleNode(strQuery).Text

   Debug.Print dblTax

End Sub

The working ASP page is as follows:

Code:
<%
Dim strQuery
Dim varSalesTax
Dim varSalesTotal
Dim strTemp
Dim objReq

Set objReq = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)


'Load the request into XML DOM
objReq.Load Request

'Query the DOM for the input parameter
strQuery = &quot;SOAP:Envelope/SOAP:Body/m:GetSalesTax/SalesTotal&quot;
varSalesTotal = objReq.SelectSingleNode(strQuery).Text

'Calculate the sales tax
varSalesTax = varSalesTotal * 0.04

'Prepare the return envelope
strTmp = _
&quot;<SOAP:Envelope xmlns:SOAP=&quot;&quot;urn:schemas-xmlsoap-org:soap.v1&quot;&quot;>&quot; & _
&quot;<SOAP:Header></SOAP:Header>&quot; & _
&quot;<SOAP:Body>&quot; & _
&quot;<m:GetSalesTaxResponse xmlns:m=&quot;&quot;urn:myserver/soap:TaxCalc&quot;&quot;>&quot; & _
&quot;<SalesTax>&quot; & varSalesTax & &quot;</SalesTax>&quot; & _
&quot;</m:GetSalesTaxResponse>&quot; & _
&quot;</SOAP:Body>&quot; & _
&quot;</SOAP:Envelope>&quot;

'Write the return envelope
Response.Write strTmp

%>

I kept the ASP page name as Soap.asp and the app works swimmingly.

Thanks,

Bennynye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top