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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call a web service from vb6

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
US
Is it possible to call a web service from visual basic 6.0? I've seen lot's of examples using the .net framework, but is .net the only way to do this?
 
Of course you can. The real question is "What do you mean by web service?" That'll determine how easily it can be done.

Some people will call a simple HTTP GET request with a text response a "web service" while others are talking about interacting with significantly more infrastructure.

But even VBScript can invoke web services.
 
I have an xml request file that conforms to the web service's wsdl file. I've tested the request file with the product SoapUI, and received an appropriate xml response file. Now I would like to do the same thing using vb 6.0 code. I would like to pass an xml request file to the web service and then receive an xml response. How would I do this with VB?
 
I figured it out:
Code:
Option Explicit

Const sRequestFileName = "I:\Development\WesternSurplus\AutomatedFeed\CallGWSISTest\request.xml"
Const sResponseFileName = "I:\Development\WesternSurplus\AutomatedFeed\CallGWSISTest\response.xml"

Sub Main()
   Dim objHTTP As MSXML.XMLHTTPRequest
   Dim sRequest As String
   Dim sResponse As String
   Dim lFileHandle As Long
   
   'Create the SOAP Envelope
   
   lFileHandle = FreeFile
   Open sRequestFileName For Input Access Read As lFileHandle
   sRequest = Input(FileLen(sRequestFileName), lFileHandle)
   Close lFileHandle
   
   'Set up to post to our local server
   Set objHTTP = New MSXML.XMLHTTPRequest
   objHTTP.open "post", _
     "[URL unfurl="true"]http://admw2k3-gws1/gwsis/integrationservice.asmx",[/URL] False

   '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 "SOAPAction", _
      "[URL unfurl="true"]http://rebusis.com/webservices/gcs/IntegrationService/ProcessNA"[/URL]

   'Make the SOAP call
   objHTTP.send sRequest

   'Get the return envelope
   
   sResponse = objHTTP.responseText

   Debug.Print sResponse

   lFileHandle = FreeFile
   Open sResponseFileName For Output Access Write As lFileHandle
   Print #lFileHandle, sResponse
   Close lFileHandle
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top