Consuming a Web Service
In ASP.NET,
consuming a web service is nearly as easy as creating one. ASP.NET
provides a utility called
wsdl.exe
that can create a proxy class, which is a class that knows all of the
necessary details of communicating with the web service via
SOAP, as shown in Figure 4-1, and which can be called from a client
application the same way as any other managed class, In this way, the
proxy class abstracts away the complexities of communication with the
web service.
Consuming a web service in ASP.NET requires four steps:
Locate the WSDL contract for the desired web service.
Create a proxy class by using the
wsdl.execommand-line utility.Compile the proxy class.
Create a new instance of the proxy class in the client application (WinForms, Console, or ASP.NET) and call the desired methods.
In the case of our Qotd_cb web service, you would
execute the following command (again, conveniently saved as a DOS
batch file) to generate a proxy class based on the web service:
wsdl /l:vb /out:Qotd_cb_proxy.vb http://localhost/ASPdotNET_iaN/Chapter _4/Qotd_cb.asmx?WSDL pause
The /l parameter specifies that the proxy class
should be generated in Visual Basic .NET (the default is C#). The
/out parameter specifies the name and, optionally,
the path of the output file. This is important if you are compiling
your proxy class in the same directory as the code-behind class that
implements the web service. In this case, if you do not specify the
output filename, the file Qotd_cb.vb will ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access