B118 Web Programming - PowerPoint PPT Presentation

b118 web programming l.
Skip this Video
Loading SlideShow in 5 Seconds..
B118 Web Programming PowerPoint Presentation
B118 Web Programming

play fullscreen
1 / 37
Download
Download Presentation

B118 Web Programming

Presentation Transcript

  1. B118 Web Programming Session #13 Forms, XML & Web Services May 3, 2004

  2. Tonight’s Agenda • Administrative • Order form validation homework • bEssentials • Final exam • Introduction to ASP.NET Web Server Controls • XML • Web Services

  3. Administrative – Order Form Validation • Grading criteria • Solution discussion

  4. Administrative – bEssentials • Peer evaluations: based on contribution effort towards the team, showing up for meetings, meeting commitments for deliverables, etc. • 5 percentage points out of the 30 percentage points for the project, proportional to the overall group score • Allocate points from the pot to your team members: • Don’t exceed the # of points you have to allocate! If you do, they come out of your points! • Don’t give yourself any points! • Due on the day of the final – if you forget, you get ZERO for peer evaluation

  5. Administrative – bEssentials • Deliverables on the Final Exam day: • Peer evaluation scores • All files uploaded to Cypress • On a single sheet of paper: • Names of your team members • URL of your company’s home page • URL of any web pages that your team is especially proud of and would like to bring to my attention • Anything else about your web site that you’d like to point out for grade evaluation • Be prepared to do a 5 minute demo of your web site in front of the class before we begin the final exam

  6. Administrative – Final Exam • Bring Blue Book • Review next class session

  7. Introduction to ASP.NET Web Server Controls • Basic controls (text box, radio button, check box) are similar to HTML controls • Radio Button List & Check Box List ASP.NET controls do the grouping for you • Retrieve list contents from a data source or list collection • Dropdown List ASP.NET control uses same implementation model • AutoPostBack attribute for immediate or deferred form processing • Additional information: • Chapter 4 of the text • http://www.asp.net/Tutorials/quickstart.aspx, ASP.NET Web Forms topic

  8. ASP.NET Validation Controls • Does form validation in response to a button click event • Required field (asp:RequiredFieldValidator) • Range checking of input data (asp:RangeValidator) • Verify the input data against a format such as email address, Social Security Number or minimum character length (asp:RegularExpressionValidator) • Compare two data from two form controls (asp.CompareValidator)

  9. Example: form-demo.aspx • Web Matrix Technique highlights • Page properties: Events (lightening bolt): Load (double-click) to create Page_Load subroutine template • Create ListItems for a list control by clicking on (…) icon in collections • Programming techniques • RadioButtonList1.SelectedIndex=-1 to deselect all items in the list • See what happens when you: • Set AutoPostBack = "False" • Set CausesValidation = "True"

  10. XML - Introduction • Core technology for one of the hottest areas in IT today • An essential, "must know" topic if you want to stay current in web programming • An excellent format for packaging and communicating data between humans, machines or both • Firewalls may block binary data, XML is text only so it doesn’t have any problems getting through

  11. XML – Overview • XML = eXtensible Markup Language • But it’s really not a language • It’s a standard format for writing your own language in a way that other people (and applications) can easily learn • Resembles HTML, similar to XHTML in terms of grammar rules (nesting, end tags, attribute values in quotes, comments, etc.) • Tag names are case sensitive!

  12. XML’s Hidden Role in .NET • XML’s most useful place isn’t in a web application you might create, rather it’s in the infrastructure supporting your web application • Places where .NET makes use of XML: • ADO.NET Data Access • Configuration files like web.config • Web Services • Anywhere that .NET needs to store miscellaneous data such as the list of files to display in the AdRotator control

  13. XML Basic • Compare these two product catalog data files Traditional text file format: 1 Chair 49.33 113 2 Car 43399.55 97 3 Fruit Basket 49.99 83 XML file format: <?xml version = "1.0"?> <ProductList> <Product> <id>1</id> <name>Chair</name> <price>49.33</price> <StockQty>113</StockQty> </Product> <Product> <id>2</id> <name>Car</name> <price>43399.55</price> <StockQty>97</StockQty> </Product> <Product> <id>3</id> <name>Fruit Basket</name> <price>49.99</price> <StockQty>83</StockQty> </Product> </ProductList>

  14. XML • XML isn’t a replacement for a real database • XML doesn’t have all of the mechanisms that a database package has (to enforce table relations or manage concurrency issues, for example) • In addition to the XML document itself, there are two other components: • Document Type Definition (DTD) or XML Schema (XSD) • eXtensible Style Sheets (XSL) – optional for displaying the XML document

  15. DTD Example book-instance.xml <?xml version="1.0"?> <BOOK InStock="true"> <TITLE>The Marble Faun</TITLE> <AUTHOR>Nathaniel Hawthorne</AUTHOR> <BINDING>trade paperback</BINDING> <PAGES>473</PAGES> <PRICE>10.95</PRICE> </BOOK> book-dtd.dtd <!ELEMENT INVENTORY (BOOK) *> <!ELEMENT BOOK (TITLE, AUTHOR, BINDING, PAGES, PRICE) > <!ATTLIST BOOK InStock (true|false) #REQUIRED > <!ELEMENT TITLE (#PCDATA) > <!ELEMENT AUTHOR (#PCDATA) > <!ELEMENT BINDING (#PCDATA) > <!ELEMENT PAGES (#PCDATA) > <!ELEMENT PRICE (#PCDATA) >

  16. XML Schema Example book-schema.xsd <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="BOOK"> <xsd:complexType> <xsd:sequence> <xsd:element name="TITLE" type="xsd:string"/> <xsd:element name="AUTHOR" type="xsd:string"/> <xsd:element name="BINDING" type="xsd:string"/> <xsd:element name="PAGES" type="xsd:positiveInteger"/> <xsd:element name="PRICE" type="xsd:decimal"/> </xsd:sequence> <xsd:attribute name="InStock" type="xsd:boolean" use="required"/> </xsd:complexType> </xsd:element> </xsd:schema>

  17. XML Facilities in .NET • Handle XML as a special type of text file • XmlTextWriter, XmlTextReader • Text stream I/O (you need to construct tags by specifying element names) • Good for storing simple blocks of data • You need to keep track of the structure and the order of the element tags (<name> then <price> then <StockQty>, for example) • Maintains connection to the actual data

  18. XML Facilities in .NET: XmlTextWriter Dim fs As New FileStream ("c:\myFile.xml", FileMode.Create) Dim w As New XmlTextWriter(fs, Nothing) w.WriteStartDocument() w.WriteStartElement("SuperProProductList")0 ‘ Write the first product w.WriteStartElement("Product") w.WriteAttributeString("ID", "", "1") w.WriteAttributeString("Name", "", "Chair") w.WriteStartElement("Price") w.WriteString("49.33") w.WriteEndElement() w.WriteEndElement() ‘ Close the root element w.WriteEndElement() w.WriteEndDocument() w.Close()

  19. XML Facilities: XmlTextWriter (cont’d) • Produces this XML file: <?xml version="1.0"> <SuperProProductList> <Product ID="1" Name="Chair"> <Price>49.33</Price> </Product> </SuperProProductList>

  20. XML Facilities in .NET • Handle XML as a collection of in-memory objects • XmlDocument, XmlNode • Makes the entire XML document structure available as an in-memory object • You set values to node properties, order of the element tags is maintained for you • Tag pairs (<name> </name>) handled for you • Offers ability to search for content by element ID or element tag name • A copy of the original data • Similar in concept to ADO.NET DataSet

  21. XML Facilities in .NET • Handle XML as a special interface to relational data • XmlDataDocument • Lets you read an XML document and then bind it to ADO.NET data controls such as DataGrid

  22. XML Facilities in .NET • Process an XML document through XSL (to create an HTML document, for example) • XmlTransform to generate the output stream • Xml takes XmlTransform output to generate an HTML page

  23. XML Demo Programs • All of these programs use the rental.mdb from B188

  24. Web Services - Introduction • Why? The architecture for Internet applications is very similar to the client/server architecture of about five years ago: monolithic, a full-featured application containing a variety of services behind a single proprietary user interface

  25. The Era of Monolithic Applications • Single web application offering a comprehensive set of services such as a financial services site (with access to individual savings, credit card, insurance information and services)

  26. Limitations of Monolithic Applications • Take a lot of time and resources to create • Often tied to specific platforms or technologies, can’t be easily extended or enhanced • Difficult to get multiple applications to work together beyond just a hyperlink • Units of application logic can’t easily be reused between applications (this is the next level above just sharing source code or object classes) • You have to go through the complete, monolithic application even if all you want is a simple piece of information (such as your savings balance or the current loan rate for a specific program)

  27. Components and the COM Revolution • On the standalone desktop application level, Microsoft addressed these problems through their COM (component object model) technology which produced ActiveX controls • A lot of the individual functional services inside of Word and Excel are available as ActiveX controls, for example • Web Services offers the same re-usable and more easily accessible functionality over a networked environment

  28. Web Services and the Programmable Web • Web Services are individual units of programming logic that exist on a web server • Built on open standards, not a platform-specific binary standard • Think of it as being able to call classes/subroutines/functions over a network

  29. eWeek – September 23, 2002 page 26H

  30. Web Services Standards

  31. WSDL • XML-based • Contains only the information for communication between a Web Service and client, nothing on the inner workings of the service • Designed for reading by applications • To see the WSDL for an ASP.NET Web Service, add ?WSDL to the query string: http://localhost/WebService/myWebService.asmx?WSDL

  32. SOAP • One of the three supported standards for the transmission of Web Service information (the other two being HTTP GET & HTTP PUT) • HTTP GET/PUT sends information as simple name/value pairs, SOAP uses a well-formatted XML document

  33. DISCO • Web Services are available at a specific URL address. How do you let the world know about this address? What if you need to change the address? • DISCO is a machine-readable "HTML page with links to Web Services" • As long as your application knows how to find the site’s .disco file, it can then find all of the Web Services available at that site

  34. UDDI • Proposed by Microsoft, very new and not yet widely adopted • Conceptually equivalent to a Yahoo! for web services • Sits at the level above DISCO files. It’s a means for businesses to advertise all the Web Services they have • The UDDI registry itself is a Web Service • Details at http://uddi.microsoft.com

  35. Standalone Web Application Web Service Client Service Class ProxyClass Web Application Web Application Methods Methods Web Service Web Service Class Communicating with a Web Service Internet

  36. Creating a Web Service • Code a .asmx file <WebService (Description:="Bus118W Web Service demo", _ Namespace:="http://cob.sjsu.edu")> _ Public Class GetTransactions Inherits WebService • Put it through the WSDL compiler to generate a Visual Basic source file: wsdl.exe /language:vb http://localhost/rental-XMLWebSvc.asmx?WSDL • Compile VB source file to generate proxy DLL vbc.exe /t:library /out:GetTransactions.dll /r:system.dll /r:system.web.dll /r:system.web.services.dll /r:system.xml.dll /r:system.data.dll GetTransactions.vb

  37. XML & Web Services Demo Programs • All of these programs use the rental.mdb from B188 • Commercial web services • WeatherByZipClient.aspx • Calls a web service that returns current weather conditions for a given ZIP code • GoogleAPIClient.aspx • Calls a web service operated by Google