Session 6
Module 2
Calling a Web Service from
an [Link] Web Page
Tasks for this Module
• How we’d ideally call a Web service from an
[Link] Web page
• Creating a Proxy class with [Link]
– Using the Proxy class
– Examining the Proxy class
– Examining [Link]
Time allotment for this module and questions: 75 minutes
Calling a Web Service from an
[Link] Web Page
• Ideally the developer calling a Web service from
an [Link] Web page should be able to work
with the Web service using the same syntax as if
she was working with a component local to the
Web server.
• Since calling a Web service involves marshalling
the ingoing parameters properly and being able to
marshal the return parameters properly, obviously
performing such actions in an [Link] Web
page would make the syntax differ wildly from
using a local component, where such explicit
marshalling was not needed.
Enter the Proxy Class
• In order to achieve the end goal of treating a Web
service call just like a call to a local component,
the .NET framework contains a command-line
program called [Link] (Web Service
Description Language), which creates a proxy
class for a specific Web service.
• This proxy class serves as an intermediate
between the [Link] Web page and the Web
service. (The diagram on the next slide should
help clarify this…)
The Role of the Proxy Class
STEP
STEP
STEP3: The Web serviceunmarshals
unmarshalsthethe
STEP4:
1:
2:The
The
Theproxy
[Link]
proxyclass
classWeb page the
marshals
incoming
return parameters,
[Link]
parameters runs the
instantiates
and passes method, and
parameter list and makes an back
an instance
HTTP therequest
result
of to
tomarshals
the
the Web
the
theProxy
[Link] output
class:
service Web parameters.
page.
sitting
These are
Transaction
on Web Server #2
sent back in an HTTP response.
complete!
Dim objClass = New ProxyClassName
WEB SERVER #1 And calls one of the Web service methods:
[Link](paramList)
[Link]
an [Link] Web page
WEB
SERVER #2
PROXY CLASS Web service
Creating a Proxy Class
• Creating a Proxy class involves three steps:
– Create the source code for the class, which depends
upon the WSDL of the Web service.
– Compile the class into a DLL
– Copy the DLL to the \bin directory
• Once these three steps are complete we can use
our Proxy class to access Web service methods as
if they were methods of a local component!
Visual [Link] can perform all of these tasks with the
click of a button. We will examine how to do it via the
command-line for those who don’t have [Link] installed.
Creating a Proxy Class
(Continued…)
• When creating a proxy class, you must specify the
WSDL for the Web service. This XML-formatted file
contains information on the incoming and outgoing
parameters. See
[Link]
• Create the proxy class by simply calling [Link]
with the full URL of the WSDL as the parameter:
Wsdl [Link]
Creating a Proxy Class
(Continued…)
• Once we have the source code we need to compile
this code into a DLL.
• Finally, once we have the Proxy class compiled
into a DLL, we need to move it to the \bin
directory, since that is the location where our
DLLs need to reside to be picked up automatically
by [Link].
Run [Link] demo
Using the Proxy Class
• Once we have the Proxy class compiled and
the DLL in the \bin directory, we can use
it through an [Link] Web page.
Show [Link] Demo
• Note how, when examining the syntax, it is
impossible to tell if the instantiation of the
[Link] class is referring to a local or
remote component. Mission accomplished!
Examining the Proxy Class
• Let’s take a moment and examine [Link], the
source code for the Proxy class created by
[Link]
Examine [Link]
• Note that the Proxy class is in C# - [Link]
provides a command-line switch to specify what
language to use.
• Note that a class is created with the same name as
the Web service class (Math, in this example).
Also, for each public Web method there is a public
method in the Proxy class with the correct input
and output parameters.
Examining the Proxy Class
(Continued…)
• Note that in this Proxy class the Web
service is being called using the SOAP
request/response payloads.
• All of the complex behavior in hidden in
macros or through methods defined in base
classes from which our custom Math class
inherits from.
Examining [Link]
• [Link] contains only one required parameter,
a URL or path to the WSDL for the Web service.
The following optional parameters can be
specified:
– /language:language – specifies what language the
Proxy class should be created in (vb/cs/js).
– /protocol:protocol – specifies the payload protocol
to be used (SOAP, HttpGet, HttpPost)
– /namespace:namespace – the namespace of the
generated Proxy class.
– /out:filename – the filename of the Proxy class.
Module 2 in Conclusion
• Ideally, we’d like to be able to call Web services
from an [Link] Web page in an identical fashion
to which we call local components.
• Creating a Proxy class allows us to call a Web
service’s methods as if the Web service resided
locally. The Proxy class handles the actual HTTP
request as well as the marshalling of the input and
output parameters.
• The command-line program [Link] can create
the source code of the Proxy class for us based upon
a Web service’s WSDL. Once this class is compiled
and placed in the \bin directory, it can be used
through an [Link] Web page.
Questions???
Now would be a great time
to ask questions! Don’t you
think? So ask away!