Part 3
Part 3
Part 3
NET
ASP.NET
Framework Overview
VB C++ C# JScript …
Web Forms
Win Forms
(ASP.NET)
ASP.NET
• Visual Studio .NET is a developer application used to
create ASP.NET Web applications
• There are two main types of Web resources created
with ASP.NET applications
– WebForms are ASP.NET pages within an ASP.NET
application.
– Web Services are ASP.NET Web pages that contain
publicly exposed code so that other applications can
interact with them.
– Web Services are identified with the file extension .asmx
WebForms
• The ASP.NET WebForm is separated into two
logical areas:
– The HTML template
– A collection of code behind the WebForm
• The HTML template
– Contains the design layout, content, and the controls
– Creates the user interface, or presentation layer
– Instructs the browser how to format the Web page
– Is created using a combination of HTML controls,
HTML Server controls, Mobile Controls, and ASP.NET
controls
Server Controls
• HTML Server controls are similar to the HTML
controls, except they are processed by the server
• Add runat = "server" to the HTML control to
transform it into an HTML Server control
• HTML control: <input type="text">
• HTML Server control:
<input type="text" runat="server"/>
<input type=”radio” runat=”server” value=”Yes”/> Yes
• Server-side programs can interact with the control
before it is rendered as a plain HTML control and
sent to the browser
ASP.NET Controls
• ASP.NET form controls will create the HTML code
• ASP.NET Server controls are organized as:
– ASP.NET Form Controls
– Data Validation Controls
– User Controls
– Mobile Controls
• ASP.NET controls are usually identified with the
prefix asp: followed by the name of the control
• ASP.NET button:
<asp:Button id="ShowBtn" runat="server"
Text="Show the message." />
HTML Server Vs
ASP.NET Server, Controls
• ASP.NET form controls can interact with client-
side events such as when the user clicks on a
button
– When the event occurs, ASP.NET can trigger a script to
run on the server
• ASP.NET form controls also have different
properties than their HTML server control
counterparts
– HTML Server label control
• Message1.InnerHTML = "Product 1"
– ASP server label control
• Message2.Text = "Product 2"
User Controls
• User controls are external files that can be
included within another WebForm
• User controls allow you to reuse code across
multiple files
• For example, you can create a user control that
displays the a navigation bar
• You can use this control on the home page; they
are often used for creating self-contained code,
headers, menus, and footers
• User controls replace the functionality of ASP
server-side include pages
• Mobile controls
– A series of controls that provide form functionality within
wireless and mobile devices
• Literal controls
– Page content that is not assigned to a specific HTML control
such as a combination of HTML tags and text to the browser
Server Controls within
Visual Studio .NET
• In Visual Studio
.NET most of the
ASP.NET Server
controls are located
on the Web Forms
tab in the toolbox
Web Services
• Web Services also provide a means to
expose .NET functionality on the web but
Web Services expose functionality via XML
and SOAP (cf: function calls over the web)
INTRODUCTION TO WEB
SERVICES
Lecture 6
What is a Web Service ?
• Web services are implemented in ASMX files. ASMX is a special file name
extension registered to ASP.NET (specifically, to an ASP.NET HTTP handler) in
Machine.config.
• Web service classes can be attributed with optional WebService attributes. The
one in the previous example assigns the Web service a name and a description
that show up in the HTML page generated when a user calls up Calc.asmx in his
or her browser.
• Web methods are declared by tagging public methods in the Web service class
with WebMethod attributes. You can build helper methods into a Web service—
methods that are used internally by Web methods but that are not exposed as Web
methods themselves—by omitting the Webmethod attribute.
Testing a Web Service :
How do you test an ASMX Web service?
Simple: just call it up in your browser.
ASP.NET responds to the HTTP request for Calc.asmx by generating an HTML page
that describes the Web service.
• The name and description in the ASMX file’s WebService attribute appear at the top of the
page.
• Underneath is a list of Web methods that the service exposes, complete with the
descriptions spelled out in the WebMethod attributes.
Click “Add” near the top of the page, and ASP.NET displays a page that you can use to
test the Add method .
• ASP.NET knows the method name and signature because it reads them from the metadata
in the DLL it compiled from Calc.asmx. It even generates an HTML form that you can use
to call the Add method with your choice of inputs.
• The XML returned by the Web method appears in a separate browser window
The forms that ASP.NET generates on the fly from ASMX files enable you to
test the Web services that you write without writing special clients to test them
with.
Suppose you write a Web service that publishes Web methods named Add and Subtract that
callers can use to add and subtract simple integers. If the service’s URL is
www.wintellect.com/calc.asmx, here’s how a client would invoke the Add method by transmitting
a SOAP envelope in an HTTP request. This example adds 2 and 2:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 353
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 80
a=2&b=2
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 80
The hard part of writing a Web service is parsing HTTP requests and generating HTTP
responses. The .NET Framework insulates developers from the low-level details of HTTP, SOAP,
and XML and provides a high-level framework for writing Web services and Web service clients
alike.
Web Services Description Language - WSDL
If other developers are to consume (that is, write clients for) a Web service that
you author, they need to know :
All this information and more can be expressed in a language called the Web
Services Description Language, or WSDL for short.
WSDL is an XML vocabulary http://www.w3.org/TR/wsdl.
Once a client has a WSDL contract describing a Web service, it has all the
information it needs to make calls to that Web service.
But when you publish a Web service by making it available on a Web server,
how do clients find out where to get a WSDL contract? For that matter, how do
clients know that your Web service exists in the first place?
• DISCO is a file-based mechanism for local Web service discovery—that is, for
getting a list of available Web services from DISCO files deployed on Web
servers.
• UDDI is a global Web service directory that is itself implemented as a Web
service.