Call WebService in VB6 or ASP

Source: Internet
Author: User
Tags define http post soap web services xmlns
Called WebService in Web VB6 or ASP



WEB Services technology enables heterogeneous computing environments to share data and communication to achieve information consistency. We can use

HTTP Post/get Protocol, SOAP protocol to invoke Web Services.



First, using the SOAP protocol to invoke web Services in VB6



; First use. NET to publish a simple web Services

<webmethod () > _

Public Function getString (ByVal str As String) as String

Return to "Hello World," & STR &! "

End Function

The Web services contains only one GetString method that returns a string. When we call this Web services, the SOAP message that is sent to the. asmx page 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>
<getstring xmlns= "Http://tempuri.org/TestWebService/Service1" >
<str>string</str>
</getString>
</soap:Body>
</soap:Envelope>
The SOAP message returned 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" >
<getStringResult>string</getStringResult>
</getStringResponse>
</soap:Body>
</soap:Envelope>

; This simple Web services can be invoked in VB6 to use the XMLHTTP protocol to send to the. asmx page

Send soap to implement it.

In VB6, create a simple engineering, interface diagram, we click button to call this Jane

A 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/' ><soap:body><getstring xmlns= ' http:// Tempuri.org/testwebservice/service1 ' ><str> ' & str &

"</str></getString></soap:Body></soap:Envelope>"



' Define an HTTP object and send a post message to the server

Dim h as MSXML2. ServerXMLHTTP40

' Defines an XML document object that converts handwritten or accepted XML content into an XML object

Dim x as MSXML2. DOMDocument40

' Initialize XML objects

Set x = New MSXML2. DOMDocument40

' Converts a handwritten soap string to an XML object

X.loadxml strxml

' Initialize HTTP object

Set h = New MSXML2. ServerXMLHTTP40

' Send a 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

' Display the returned XML information

Text1.Text = H.responsetext

' resolves the returned XML information and displays the return value

Set x = New MSXML2. DOMDocument40

X.loadxml Text1.Text

Text1.Text = X.childnodes (1). Text



We enter "China" in the TextBox and click the button, so we can display "Hello World, China" in the textbox below. Display as shown in figure:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.