Title: Session 7 : The Web
1Session 7 The Web
2Matters arising
- Have I mentioned CodeProject?
- www.codeproject.com
3Adding richer content to WinForms
- The .NET framework is an evolution, not a
revolution. - Before the advent of .NET and managed code, there
was a concept called COM objects. - These were higherlevel versioned objects packaged
such that the implementation was securely hidden. - Subsequently, a standard was defined for COM
objects with a visual representation (ActiveX). - There are A LOT of these out there.
- Fortunately, it is possible to use these on forms.
4Demo Controls
- Demo
- Agent
- Spreadsheet
- MSChart
5The Web in General
- The web has revolutionized our lives.
- It gives us possibilities to reach out into the
world that we have never had before. - It gives businesses a way of conducting business
electronically. - We're only just starting to utilize the potential.
6Web technologies
- We will concentrate on
- Web pages, using ASP.NET
- Web services.
- We will not look too much into the technology
that transports the data from one end to the
other. - (Except maybe for this).
7The Web Server
- The web server is the program that sends HTML to
the browser. - The browser requests a page through a URL.
- The browser uses the DNS (Domain Name Server) to
convert the domain name of the URL into an IP
Address. - Demo nslookup ltsitegt using IP address in
browser. - The site with that IP address is then hit (on
port 80). - The server examines the rest of the URL
(stripping the domain) and either just sends the
HTML back or executes code generating HTML. - This is a server, meaning a number of clients can
be served at once. - The MS Internet explorer is called IIS (Internet
Information Server).
8HTML. The history
- In 1989, Tim Berners-Lee worked at CERN in
Geneva. - Particle physics requires cooperation from teams
all over the world. A method for cross
referencing and accessing research papers was
needed. - While reading one paper, you could instantly
examine references to others, forming a web of
information. The hyperlink was invented. - Tim B-Lee based the format of the text on (the
already existing) SGML. He called it HTML,
HyperText Markup Language. To transfer the data
between machines, he invented HTTP, HyperText
Transfer Protocol.
9HTML
- HTML is now a standard. There are many browsers
available on any platform. - HTML is raw text, with tags defining the layout.
- Demo
- This servers perfectly for static contents, where
the information does not change much. - Active Server Pages emerged from MS (and other
technologies from other vendors), allowing code
to be mixed in. - The current incarnation is ASP.NET, allowing
managed code to be used to provide the code.
10Dynamic ASPX pages
- Demo. Make a simple html page and put it in a
suitable directory. - Demo. Take the html page from before and make it
dynamic, such that it uses code to achieve its
result. - Rename to .aspx
- Insert code with lt gt metatags.
- If you wanted to, you could still write code this
way, but now there are easier and better ways,
using VS. - Now, you can use the knowledge you have from
building windows forms to build web forms. - Works by adding Server controls that are
interpreted at the server. The generated HTML
code is sent back to the browser.
11Source code
- It is still perfectly possible to mix in code
with the page itself. - In this way, everything is collected in one
place. - BUT It causes a dangerous coupling between
content and logic. - Better to use code behind files (or partial
classes).
lthtmlgt ltscript language"C" runatservergt
void SubmitBtn_Click(Object sender,
EventArgs e) Message.Text "Hi "
Server.HtmlEncode(Name.Text) ", you selected "
Category.SelectedItem " on "
MyCal.Date.ToShortDateString()
lt/scriptgt ltbodygt ltcentergt
ltform action"intro7.aspx" method"post"
runat"server"gt ....
ltaspbutton text"Lookup" OnClick"SubmitBtn_Click
" runat"server"/gt lt/formgt
lt/centergt lt/bodygt lt/htmlgt
12Server controls
- The use of server controls allows user interfaces
to be written more easily.
lthtmlgt ltheadgt ltlink rel"stylesheet"href
"intro.css"gt lt/headgt ltbodygt
ltcentergt ltform action"intro5.aspx"
method"post" runat"server"gt
ltaspadrotator AdvertisementFile"ads.xml"
BorderColor"black" BorderWidth1
runat"server"/gt lth3gt Name
ltasptextbox id"Name" runat"server"/gt
Category ltaspdropdownlist id"Category"
runatservergt
ltasplistitem gtpsychologylt/asplistitemgt
ltasplistitem gtbusinesslt/asplisti
temgt ltasplistitem
gtpopular_complt/asplistitemgt
lt/aspdropdownlistgt lt/h3gt
ltaspbutton text"Lookup" runat"server"/gt
lt/formgt lt/centergt lt/bodygt lt/htmlgt
13Demo Writing a Web page
- Create a new project of type ASP.NET Web
Application. - Add some controls.
- Run from the browser.
- Check the application within the IIS.
14Web Services
- XML Web services provide a simple, flexible,
standards-based model for binding applications
together over the Internet. Middle-tier business
functionality exposed by way of standard Web
protocols is known as XML Web services. - All implementation details are encapsulated.
- Web services accept SOAP messages and send back
SOAP replies. - Their interface is described in a special XML
document with the extension WSDL. - This information may be read by interested
clients who then know how to interact with it.
15Web Services
- UDDI specifies a mechanism for Web service
providers to advertise the existence of their Web
services, and for Web service consumers to locate
Web services of interest. - It is extremely easy to create web services and
web services consumers using VS.NET.
16SOAP
- Simple Object Access Protocol is the format of
the messages that go over the wire to invoke web
services. - This is an XML schema.
- SOAP messages carry both an envelope and a
payload. - ltenvEnvelope xmlnsenv"http//www.w3.org/2003/05
/soap-envelope"gt - ltenvHeadergt
- lt/envHeadergt
- ltenvBodygt
- ltmalert xmlnsm"http//example.org/alert
"gt - ltmmsggtPick up Mary at school at
2pmlt/mmsggt - lt/malertgt
- lt/envBodygt
- lt/envEnvelopegt
17WSDL
- Web Service Description Language
- This is the document that describes the web
service. It contains the following sections - Types
- Messages
- Operations
- Port types
- Bindings
- Ports
- Services
18WSDL
- Types describe the types of the data contained in
the messages. - This is usually described in the XSD (schema
definition language). - Messages are composed of parts.
- Each part refers to a type in the Types section.
- A Port Type is a set of messages grouped into
operations. - Operations represent a single unit of work
performed by the service. Think of an operations
as a method with in, out parameters and exception
cases. - Bindings define how a given operation maps to a
specific protocol. - A Port associates a bindig with a protocol
specific address
19Demo
- Create a simple class and put it in a suitable
web server directory. - Add the stuff that is needed to make this a web
service. - Demonstrate that it works.
- Use the VS IDE to do the same
- Create a simple web service (call it
SimpleValidator) to validate a credit card
number. - View the .asmx file in the browser.
- Show the WSDL in the browser
- http//localhost/SimpleValidator/Service1.asmx?
WSDL.
20Web Services Clients
- Clients (consumers of web services) certainly do
not want to deal with the low-level plumbing
involved in constructing SOAP messages,
marshalling parameters etc. - An clean object model is presented instead.
- The bridge between the two worlds is the Proxy.
- The proxy is generated by the wsdl tool.
- (This is done by the VS environment for you).
21Demo
- Create the proxy file for the web service written
before. - Wsdl http//.../MyService.asmx?wsdl
22Proxy
- The generated proxy is what supplies the clean OO
abstraction of the web service.
23Client