Conduct WebService in VB6 or ASP
Web Services technology enables the heterogeneous computing environment to share data and communication to achieve the consistency of information. We can use
The http post/get protocol, SOAP protocol to call Web Services.
1. Use the SOAP protocol to call Web Services in VB6
; First use .NET to release a simple web service
<webmethod ()> _
Public function getstring (byval str as string)
Return Hello World, & Str &!
end function
The Web Services contains only one getstring method to return a string. When we call this web services, the SOAP message sent to the .smx page was::
<? xml version = 1.0 encoding = UTF-8?>
<Soap: ENVELOPE XMLNS: XSI = http://www.w3.org/2001/xmlschema-instance
xmlns: xsd = http://www.w3.org/2001/xmlschema xmlns: soap = http: //
schemas.xmlsoap.org/soap/envelope/>
<Soap: Body>
<GETSTRING XMLNS = http://tempuri.org/testwebservice/service1>
<str> String </strong
</getstring>
</soap: Body>
</soap: ENVELOPE>
The returned SOAP message is:
<? xml version = 1.0 encoding = UTF-8?>
<Soap: ENVELOPE XMLNS: XSI = http://www.w3.org/2001/xmlschema-instance
xmlns: xsd = http://www.w3.org/2001/xmlschema xmlns: soap =
http://schemas.xmlsoap.org/soap/envelope/>
<Soap: Body>
<GetstringResponse xmlns = http://tempuri.org/testwebservice/service1>
<GETSTRINGRSULT> String </getstringResult>
</GetstringResponse>
</soap: Body>
</soap: ENVELOPE>
This simple web service in VB6 can use the XMLHTTP protocol to send it to the .asmx page
Send SOAP to implement.
In VB6, build a simple project, the interface is shown in the figure. We call this simple by clicking Button
Single web services
DIM Strxml as String
dim str as string
str = text2.text
'Define soap messages
Strxml = <? xml Version = '1.0' Encoding = 'UTF-8'?> <Soap: ENVELOPE
xmlns: xsi = 'http://www.w3.org/2001/xmlschema-instance'
xmlns: xsd = 'http://www.w3.org/2001/xmlschema'
xmlns: soap = 'http://schemas.xmlsoap.org/soap/envelope/'> <sap: Body> <GetString xmlns = 'http: //tempuri.org/testwebservice/service1 '> <STR> & Str &
</strong </getstring> </soap: body> </soap: envelope>
'Define a HTTP object, send post message to the server
dim h as MSXML2.serverxmlhttp40
'Define a document object of XML, convert the handwriting or accepted xml content into XML objects
dim x as msxml2.Document40
'Initialize XML object
set x = new msxml2.Document40
'Convert the handwritten SOAP string to XML object
x.loadxml strxml
'Initialize HTTP object
set h = new msxml2.serverxmlhttp40
'Send post message to the specified URL
h.open post, http://localhost/testwebservice/service1.asmx, false
h.setRequestHeader Content-Type, Text/XML
h.send (Strxml)
While h.readyState <> 4
wend
'Show the returned XML information
text1.text = h.Responsetext
'Analyze the returned XML information and display the return value
set x = new msxml2.Document40
x.loadxml text1.text
text1.text = x.ChildNodes (1) .text
We enter "China" in TextBox and click Button, so we can display "Hello World, China" in TextBox below. Show as shown in the figure: