VB calls WebService

Source: Internet
Author: User

VB calls WebService

Use the SOAP protocol

First, you must reference Microsoft XML 6.0

When the client calls

'Define the SOAP message. This message can be obtained during WebService calling. Mainly in soap12: Body
Dim strtest as string

'Strtest = "<? XML version = "" 1.0 "" encoding = "" UTF-8 ""?> "
'Strtest = strtest + "<soap12: envelope xmlns: xsi =" "http://www.w3.org/2001/XMLSchema-instance" "xmlns: XSD =" "http://www.w3.org/2001/XMLSchema" "xmlns: soap12 =" "http://www.w3.org/2003/05/soap-envelope">"
'Strtest = strtest + "<soap12: Body>"
'Strtest = strtest + "'Strtest = strtest + "<STR>" + STR + "</STR>"
'Strtest = strtest + "'Strtest = strtest + "</soap12: Body>"
'Strtest = strtest + "</soap12: envelope>"
Strtest = "<? XML version = "" 1.0 "" encoding = "" UTF-8 ""?> "
Strtest = strtest + "<soap12: envelope xmlns: xsi =" "http://www.w3.org/2001/XMLSchema-instance" "xmlns: XSD =" "http://www.w3.org/2001/XMLSchema" "xmlns: soap12 =" "http://www.w3.org/2003/05/soap-envelope">"
Strtest = strtest + "<soap12: Body>"
Strtest = strtest + "<returnclasstest xmlns =" "http://tempuri.org/"/>"
Strtest = strtest + "</soap12: Body>"
Strtest = strtest + "</soap12: envelope>"
Strxml = strtest

'Define an HTTP object and send a post message to the server.
Dim h as msxml2.serverxmlhttp40
'Define an XML Document Object and convert the handwritten or accepted XML content into an XML Object
Dim X as msxml2.domdocument40
'Initialize the XML Object
Set x = new msxml2.domdocument40
'Convert a handwritten soap string to an XML Object
X. loadxml strxml
'Initialize the HTTP object
Set H = new msxml2.serverxmlhttp40
'Send a post message to the specified URL. Here, the WebService address is the address to be referenced.
H. Open "Post", "http: // localhost/webserice/service. asmx", false
H. setRequestHeader "Content-Type", "text/XML"
H. Send (strxml)
While H. readystate <> 4
Wend
'Display returned XML Information
Text1.text = H. responsetext

At this point, the WebService return message is successful. The WebService return value can be a custom class.
Debugging is successful under VB6.0 vs2005.

 

WebService source code is provided below:

Using system;
Using system. Web;
Using system. Web. Services;
Using system. Web. Services. Protocols;

[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
Public class service: system. Web. Services. WebService
{
Public Service (){

// If you use the designed component, uncomment the following line
// Initializecomponent ();
}

[Webmethod]
Public String helloworld (string Str ){
Return "Hello world:" + STR;
}
[Webmethod]
Public int add (int I, Int J)
{
Return I + J;
}
[Webmethod]
Public returnclass returnclasstest ()
{
Returnclass r = new returnclass ();
R. ID = "idtest ";
R. Name = "nametest ";
Return R;
}
}
Public class returnclass
{
Public returnclass ()
{}
Private string ID;
Private string name;
Public String ID
{
Get {return ID ;}
Set {id = value ;}
}
Public string name
{
Get {return name ;}
Set {name = value ;}
}
}

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.