How... How To Use A Web XML Service From VB6
How... How To Use A Web XML Service From VB6
How... in .NET
Use an XML Web service from
VB6
Published on June 20, 2003
Updated on Jun 29, 2003 (Dec 14, 2003)
Modification to NOT use the Internet Transfer Control to access the service
Web (29/Jun/03)
Virtual Tree .NET Control Advanced data binding Fast virtual loading of data [Link]
Visual [Link] Course Learn comfortably and quickly from your home. Get informed here! [Link]
Introduction
Yes, I know that if we are going to create a client in Visual Basic 6.0, it should not be in the .NET section.
but... what it's about is using a Web Service created with a .NET language
Framework (particularly with C#), as I believe that 'also' should be in this section...
De lo que setrata es de saber qué es lo que tenemos que hacer para podercrear uncliente (una
classic Visual Basic application to be able to use a Web service created with .NET.
The good thing about using Web services is that by accessing them via the internet, you do not have to
we should worry if it's made in .NET or not... the important thing is that we can use it and that's what matters here
let's see:
The first thing is Visual Basic 6.0 (it is supposed to work with VB5, but I haven't checked it)
2- The project will use the Microsoft Internet Transfer Control (INET) to access the
site where the Web service is hosted (even if it is on the same machine)
3- A reference to Microsoft XML version 2 (any later version is also acceptable) will also be used.
4- If you are going to have the Web services on your own machine, you will need Windows XP Professional (or the
Windows 2000) with IIS installed (to be able to use it from, for example, localhost), in addition to
having the .NET Framework SDK installed, as the .NET web services require the infrastructure
from .NET (elemental), but this last one only if you are not going to use the Web service that is published in
Costasol pages.
Once the issue of the requirements is clarified, let's go to the explanation of how to create the client in VB6.
to access a Web service, in particular it will be the Web service that converts degrees
Celsius to Fahrenheit ([Link], whose code you can see by following this link).
Note:
If you want to try the Web service from the internet, you will have to use this address:
[Link]
from her you can try it.
Part of the code used to send to the Web service is obtained from the description shown in the
explorer, for example, the way to call each of the functions. Therefore, this example
que te voy a mostrar sólo es válido para este servicio Web, en otra ocasión veremos cómocrear
a generic client for any web service, in this example we will see how to know what functions
exporta el servicio Web y los parámetros que necesita recibir, para ello necesitaremos examinar y
understand the content of a file of the type WSDL (Web Service Description Language, language of
Web service description), but that will be on another occasion.
When we send the information to the web service, we have to do it using the protocols that the
.NET understands, the one used in this example is SOAP, I am not going to go into details, just to tell you
that the format used for communication between a Web service and the client will always be using
XML (hence the name of these Web services), therefore the SOAP code that I am going to show you (the
which is taken, as I mentioned before of the page shown by the explorer) is in that
format, that is the reason we have a reference to Microsoft XML version 2, since we will use
some of the classes included in it to be able to handle the XML code, well, okay, I won't go on
Here you have the code for one of the functions, in particular the function that converts degrees.
Celsius to Fahrenheit:
The provided text appears to be a fragment of an XML or SOAP message and does not contain translatable content.
<soap:Body>
<CaF xmlns="[Link]
<valor> double </valor>
</CaF>
</soap:Body>
</soap:Envelope>
When we send this code to the Web service, we will have to include it in the site that is marked.
in bold (the word double) the value of the parameter that we want to pass to that function.
We will do this using the DOMDocument class from the msxml library. The code would be something like this:
[Link]/…/[Link] 2/11
17/01/2011 How... How to use a Web XM service...
With this last line, what we are doing is assigning the parameter that we want to pass to the function CaF,
which expects a double type value in a parameter called value.
Once we have the XML code with the data to send to the Web service, we will use the Internet
Transfer to make that shipment, the following line is responsible for that:
Use the Inet control to make the call to the Web service
[Link] [Link], "POST", [Link], "Content-Type: text/xml; charset=u"
Once this command has been executed, the Web service will return the response to us, (even if...
An error occurs.
To receive (and interpret) the response that the Web service sends us, we will continue using the control.
Inet, in particular the eventStateChanged, let's take a look at the code:
[Link]/…/[Link] 3/11
17/01/2011 How... How to use a Web Service XM...
[Link] = [Link]("/soap:Envelope/soap:Body/CaFResponse")
End If
End Sub
Note:
It is important to detect the errors, since if the string sent to the Web service does not
It is correct, an error will occur when reading the value, especially if the received string is not
in XML format, what will happen if, for example, if the indicated address is not
web service, in this case it will return a "normal" HTML page indicating that it does not
has found (the typical error 440).
And so, broadly speaking, this is what we need to create the VB6 client, not much, right?
The problem is knowing which code to use for calling the different functions, luckily,
if we access a Web service from the explorer, it will show us a page with what is necessary
to create the code we need. In the following figure, you will see who I am referring to:
[Link]/…/[Link] 4/11
17/01/2011 How... How to use a Web XM service...
Figure 1, the SOAP code to call the function of the Web service
Yes, I know that's not very clear, but... once you know how to 'understand it',
the thing turns out easier... I, the truth is that when I saw that code, well... like nothing... but,
Fortunately, I came across a book in which, although it does not thoroughly explain how to do this, in the
Web of the same yes, it included an example, which has helped me to create this one that I show you.
Today... don't think that I know everything... I also read other authors..., in this case it is
David S. Platty in his book Introducing .NET (which was sent to me by the people from MSDN Latin America)
achieve the first 5-star developer star, which must be said.
Well, I’ll leave you the complete code, as well as a screenshot of the form in addition to, of course,
I will leave the example code in a zip file.
[Link]/…/[Link] 5/11
17/01/2011 How... How to use a Web XM service...
The link to the complete code (the Web service file and the WSDL file are included) [Link]
10.20 KB
See you.
Guillermo
P.S.
Remember that soon I will publish the generic code to access any Web service.
In that example, I will show the way to create a series of collections with the different functions that I
they include in the Web service as well as each of the parameters received each of the
functions.
But that will be in a few days... or perhaps tomorrow... who knows?
'------------------------------------------------------------------------------
VB6 client of the Web service converter from °C to °F (Jun 18, 03)
'
Based on an example from the book: Introducing .NET by David S. Platt
'
©Guillermo 'guille' Som, 2003
'------------------------------------------------------------------------------
Option Explicit
using [Link];
namespace CelsiusFahrenheit
{
///
Brief description of Converter.
///
[WebService(Namespace="http:"//elGuille/WebServices",
Description="Conversor de grados Fahrenheit a grados centígrados
public class Converter
{
//
const double fc = (5.0 / 9.0);
//
Converts from Fahrenheit to Celsius, returns a value
public double FaC(double value)
{
return ((value - 32) * fc);
}
[WebMethod(Description="Convierte de Celsius a Fahrenheit, devuelve un va
public double CaF(double value)
{
return (value / fc + 32);
}
//
}
}
Modification to NOT use the Internet Transfer Control to access the Web service
(29/Jun/03)
In the example I showed above, the INET control (Internet Transfer Control) is used to access.
to the web service, both to send the data and to receive it, but if you don't want to, it's not necessary anymore.
[Link]/…/[Link] 8/11
17/01/2011 How... How to use a Web XM service...
that Microsoft XML version 2.0 includes an object to perform this task, it is about
XMLHTTPRequest.
This object contains a series of methods that allow us to send a command to the Web service to
to send the information and it will also allow us to receive the data that the Web service sends us.
We will see the code that needs to be changed for the project to access the service.
Web temperature converter.
The first thing we need is the controlInet, so you can remove it from the form, as well as
the reference we have (in Project/Components...)
You can also remove the Intet1_Statechanged event as we will not need it.
Here (within a few lines) I will show you the new code. The first thing you will have to do is
replace the click event code of the two conversion buttons, in addition to adding a couple of
new procedures for sending and receiving information from the Web service.
Although I'm going to explain a little bit how the XMLHTTPRequest object works and how to use it.
When we send a POST command (we will see how shortly), the command is sent to the Web service.
(just like we did with the controlInet) and the Web service will return a response to us, that
the response will also have to be processed by the objectXMLHTTPRequest. How can it be that the
response is slow to arrive, could we be notified when that response arrives (way
asynchronous) or we can also wait until the response arrives and then continue (form
synchronous). This last one will be the form we are going to use, since the other one (the asynchronous) needs something
other code and even the creation of a class, which would be the one to receive the notification that it
It has finished receiving data from the server.
Note:
If you want to see how this is done, I recommend that you download Microsoft XML.
4.0 Parser SDK in the documentation is how to do it, (this other link will take you to the
MSXML 4.0 SDK documentation online and in English.
If you have the documentation of the mentioned SDK, you can search for these topics:
Use the onReadyStateChange Property (Visual Basic)
Make XML Requests Over HTTP (Visual Basic)
Program with DOM in Visual Basic
The code for the two Click events (you will need to replace this code with the code shown)
previously
[Link]/…/[Link] 9/11
17/01/2011 How... How to use a Web XM service...
The new code to send the command to the Web service and the one that processes the received code from the
web service.
[Link]/…/[Link] 10/11
January 17, 2011 How... How to use a Web Service XM...
If you observe the changes, you will realize that using the XMLHttpRequest object we have to
The headers sent to the Web service are indicated using the setRequestHeader method.
XML code is sent with the send method.
Well... I hope you now know another way to communicate with a Web XML service created with
.NET
See you.
William
[Link]/…/[Link] 11/11