1 / 23

Web Services

Web Services. 6.916 Lecture Tuesday, October 17, 2000 Jim Miller (Microsoft). Videos: Visions of the Future. The Web Today. Independent Web sites Web farms and data bases Reliability Round-the-clock operation Graceful upgrade Great for browsing OK for indexing and searching.

spannc
Download Presentation

Web Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Services 6.916 Lecture Tuesday, October 17, 2000 Jim Miller (Microsoft)

  2. Videos: Visions of the Future

  3. The Web Today • Independent Web sites • Web farms and data bases • Reliability • Round-the-clock operation • Graceful upgrade • Great for browsing • OK for indexing and searching

  4. A Hard Problem Today:A Shopping Service • Clients describe themselves • Credentials indicate purchasing groups they participate in (AAA, MIT, United Airlines) • Pay for access to additional groups run by us • Service contracts with suppliers • Suppliers trust us to test credentials • Suppliers offer discounts for our groups • Suppliers compete with each other • Price lists with discounts aren’t public • Product offerings change often

  5. ? What’s the Structure? Browser Shopping Service Supplier 1 HTTP / HTML Supplier 2 Customer Data and Credentials Supplier 3 Merchandise, Prices, and Discounts

  6. Distributed Systems • 1970s: FTP, RFC780 (email) • Manually move data • No embedded links • No graphics (to speak of) • 1980s: RPC / DCE • Describe a method in a special language (IDL) • Generate a client-side proxy and server-side stub • Marshalls data, etc. • Link client and server code against the proxy/stub • “Feels like” a procedure call • Problem: IDL maintenance • 1990s: CORBA / DCOM • IDL-based (extended) • Location-independent • Object-based access • Problem: no inter-op

  7. ? What’s the Structure? Browser Shopping Service Supplier 1 HTTP / HTML Supplier 2 Idea:A Web Service is a Web site that provides a programmatic interface. Customer Data and Credentials Supplier 3 Merchandise, Prices, and Discounts

  8. Web Services A Web site that provides a programmatic interface • Operations are called using HTTP and XML (SOAP) • Results are returned using HTTP and XML (SOAP) • The operations are described using XML (WSDL) What’s changed? • Timing: TCP/HTTP/XML is ubiquitous • Common client: browsers everywhere • Rich content standard: HTML, XML, style sheets, and client-side objects

  9. Sample • The E-Commerce example is too big… • There are three Web services to play with • TerraService has images (photos and maps) • CensusService has population and demographic data • LandmarkService has latitude and longitude of “interesting” places (rivers, train stations, …) • Let’s build a Web page that uses the three services to provide a rich user experience

  10. ? What’s the Structure? Browser Geography Site Terra HTTP / HTML Census Landmark

  11. Web Service Implementation (I) namespace TerraServer { using System; ... public class TerraService : WebService { [WebMethod] public PlaceFacts[] GetPlaceList(string placeName, int MaxItems, Boolean imagePresence) { PlaceFacts[] placeFacts = new PlaceFacts[MaxItems]; int i = 0, iRowType = 0; SQLDataReader reader = null; // Create a new Connection and DataSetCOmmand TerraServerConnection tsCon = new TerraServerConnection(); SQLCommand tsCmd = new SQLCommand("spTSNFindPlaceFirst", tsCon); tsCmd.CommandType = CommandType.StoredProcedure; // . . . Continued on next slide

  12. Service Implementation (II) SQLParameter workParam = null; workParam = tsCmd.Parameters.Add (new SQLParameter("@PlaceName", SQLDataType.VarChar, 100)); workParam.Direction = ParameterDirection.Input; // . . . tsCmd.Parameters["@PlaceName"].Value = placeName;// . . . try { tsCon.Open(0); tsCmd.Execute(out reader); while (reader.Read()) { iRowType = reader.GetInt32(1); placeFacts[i].Place.City = reader.GetString(5); // . . . i++; if ((i == MaxItems)||(!reader.NextResult())) break; } } finally { if (reader != null) reader.Close(); tsCon.Close(); } return(placeFacts); } } }

  13. How Is a Service Described? • WSDL (“Web Service Description Language”) • XML-based • Submitted to W3C for standardization • Look at http://terranet.research.microsoft.com/ • terraservice.asmx?sdl • censusservice.asmx?sdl • landmarkservice.asmx?sdl • Take a look at GetTheme in terraservice

  14. How Is a Service Used? • Run WebServiceUtil to generate client proxy (for each service) • Compile together to form one program that has all three proxies available • Write code that calls the proxies as though they were the actual objects • Proxies • Generate SOAP • Send to the target service • Receive the SOAP response • Parse the SOAP • Generate an object • Return the object as a result

  15. Service Description (WSDL) <?xml version="1.0"?> <serviceDescription xmlns:s0="http://tempuri.org/" name="TerraService" targetNamespace="http://tempuri.org/" xmlns="urn:schemas-xmlsoap-org:sdl.2000-01-25"> <httpget xmlns="urn:schemas-xmlsoap-org:get-sdl-2000-01-25"> <service> <requestResponse name="GetPlaceList" href="http://207.46.235.37/terranet/terraservice.asmx/GetPlaceList"> <request> <param name="placeName"/> <param name="MaxItems"/> <param name="imagePresence"/> </request> <response> <mimeXml ref="s0:ArrayOfPlaceFacts"/> </response> </requestResponse> </service> </httpget> </serviceDescription>

  16. SOAP Request <?xml version="1.0"?> <soap:Envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc= "http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi= "http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/1999/XMLSchema"> <soap:Body> <GetPlaceList xmlns="http://tempuri.org/"> <placeName>redmond</placeName> <MaxItems xmlns="">10</MaxItems> <imagePresence>false</imagePresence> </GetPlaceList> </soap:Body> </soap:Envelope>

  17. Proxy Code namespace TerraServer { using System.Xml.Serialization; . . . public class TerraService: System.Web.Services.Protocols.SoapClientProtocol { public TerraService() { this.Url = "http://terraweb/TerraNet/TerraService.asmx"; } [System.Web.Services.Protocols.SoapMethodAttribute ("http://tempuri.org/GetPlaceList"), System.Xml.Serialization.XmlArrayItemAttribute ("PlaceFacts", Form=System.Xml.Serialization.XmlForm.Unqualified, IsNullable=false)] public PlaceFacts[] GetPlaceList (string placeName, [System.Xml.Serialization.XmlElementAttribute ("MaxItems", Form=System.Xml.Serialization.XmlForm.Unqualified, IsNullable=false)] int maxItems, bool imagePresence) { object[] results = this.Invoke("GetPlaceList", new object[] {placeName, maxItems, imagePresence}); return (PlaceFacts[])(results[0]); } } }

  18. Web Page Source Code <html> <script language="C#" runat=server> void SubmitBtn_Click(Object sender, EventArgs e) { TerraServer.TerraService ts = new TerraServer.TerraService(); CensusServer.CensusService cs = new CensusServer.CensusService(); LandmarkServer.LandmarkService ls = new LandmarkServer.LandmarkService(); TerraServer.PlaceFacts[] pf = ts.GetPlaceList(Place.Text, 10, false); ChosenPlace.Text = String.Format("Chosen place:<b> {0}, {1}, {2}</b>", pf[0].Place.City, pf[0].Place.State, pf[0].Place.Country); ChosenLonLat.Text = String.Format("(<b>Longitude = {0}, Latitude = {1}</b>)", pf[0].Center.Lon, pf[0].Center.Lat); // Continued next slide ...

  19. Source Code (II) CensusServer.CensusFacts cf = cs.GetPoliticalUnitFactsByName (CensusServer.PoliticalUnit.City, pf[0].Place.City, pf[0].Place.State, 1990); CensusInfo.Text = String.Format("Population = {0} ({1} males & {2} females)", cf.Population1990, cf.Males, cf.Females); // . . . Landmark code here . . . } </script>

  20. Source Code (III) <body> <center> <form method="post" runat="server"> Enter a place: <asp:textbox id="Place" runat="server"/> <asp:button type=submit text="Lookup" OnClick="SubmitBtn_Click" runat="server"/> <BR> <asp:label id="ChosenPlace" runat="server"/> <BR> <asp:label id="ChosenLonLat" runat="server"/> <p> <asp:label id="CensusInfo" runat="server"/> <BR><BR> <asp:label id="LandmarkInfo" runat="server"/> </form> </center> </body> </html>

  21. Video Revisited

  22. Discussion of Videos • Discussion: What services are here • Discussion: What’s needed beyond just Web Services?

  23. How Do I Find WebServices? • Take a look at http://uddi.org

More Related