c20b93edf86fe28d0bbee6d9c7d1da4e.ppt
- Количество слайдов: 23
Web Services 6. 916 Lecture Tuesday, October 17, 2000 Jim Miller (Microsoft) 1
Videos: Visions of the Future 2
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 3
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 4
What’s the Structure? Browser Shopping HTTP / HTML Supplier 1 Service ? Customer Data and Credentials Supplier 2 Supplier 3 Merchandise, Prices, and Discounts 5
Distributed Systems • 1970 s: FTP, RFC 780 (email) – Manually move data – No embedded links – No graphics (to speak of) • 1980 s: 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 • 1990 s: CORBA / DCOM – IDL-based (extended) – Location-independent – Object-based access – Problem: no inter-op 6
What’s the Structure? Browser Shopping HTTP / HTML Idea: A Web Service is a Web site that provides a programmatic interface. Supplier 1 Service ? Customer Data and Credentials Supplier 2 Supplier 3 Merchandise, Prices, and Discounts 7
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 8
Sample • The E-Commerce example is too big… • There are three Web services to play with – Terra. Service has images (photos and maps) – Census. Service has population and demographic data – Landmark. Service 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 9
What’s the Structure? Browser HTTP / HTML Geography Site Terra ? Census Landmark 10
Web Service Implementation (I) namespace Terra. Server { using System; . . . public class Terra. Service : Web. Service { [Web. Method] public Place. Facts[] Get. Place. List(string place. Name, int Max. Items, Boolean image. Presence) { Place. Facts[] place. Facts = new Place. Facts[Max. Items]; int i = 0, i. Row. Type = 0; SQLData. Reader reader = null; // Create a new Connection and Data. Set. COmmand Terra. Server. Connection ts. Con = new Terra. Server. Connection(); SQLCommand ts. Cmd = new SQLCommand("sp. TSNFind. Place. First", ts. Con); ts. Cmd. Command. Type = Command. Type. Stored. Procedure; //. . . Continued on next slide 11
Service Implementation (II) SQLParameter work. Param = null; work. Param = ts. Cmd. Parameters. Add (new SQLParameter("@Place. Name", SQLData. Type. Var. Char, 100)); work. Param. Direction = Parameter. Direction. Input; //. . . ts. Cmd. Parameters["@Place. Name"]. Value = place. Name; //. . . try { ts. Con. Open(0); ts. Cmd. Execute(out reader); while (reader. Read()) { i. Row. Type = reader. Get. Int 32(1); place. Facts[i]. Place. City = reader. Get. String(5); //. . . i++; if ((i == Max. Items)||(!reader. Next. Result())) break; } } finally { if (reader != null) reader. Close(); ts. Con. Close(); } return(place. Facts); } } } 12
How Is a Service Described? • WSDL (“Web Service Description Language”) – XML-based – Submitted to W 3 C for standardization • Look at http: //terranet. research. microsoft. com/ – terraservice. asmx? sdl – censusservice. asmx? sdl – landmarkservice. asmx? sdl • Take a look at Get. Theme in terraservice 13
How Is a Service Used? • Run Web. Service. Util 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 14
Service Description (WSDL) <? xml version="1. 0"? > <service. Description xmlns: s 0="http: //tempuri. org/" name="Terra. Service" target. Namespace="http: //tempuri. org/" xmlns="urn: schemas-xmlsoap-org: sdl. 2000 -01 -25"> <httpget xmlns="urn: schemas-xmlsoap-org: get-sdl-2000 -01 -25"> <service> <request. Response name="Get. Place. List" href="http: //207. 46. 235. 37/terranet/terraservice. asmx/Get. Place. List"> <request> <param name="place. Name"/> <param name="Max. Items"/> <param name="image. Presence"/> </request> <response> <mime. Xml ref="s 0: Array. Of. Place. Facts"/> </response> </request. Response> </service> </httpget> </service. Description> 15
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. w 3. org/1999/XMLSchema-instance" xmlns: xsd= "http: //www. w 3. org/1999/XMLSchema"> <soap: Body> <Get. Place. List xmlns="http: //tempuri. org/"> <place. Name>redmond</place. Name> <Max. Items xmlns="">10</Max. Items> <image. Presence>false</image. Presence> </Get. Place. List> </soap: Body> </soap: Envelope> 16
Proxy Code namespace Terra. Server { using System. Xml. Serialization; . . . public class Terra. Service: System. Web. Services. Protocols. Soap. Client. Protocol { public Terra. Service() { this. Url = "http: //terraweb/Terra. Net/Terra. Service. asmx"; } [System. Web. Services. Protocols. Soap. Method. Attribute ("http: //tempuri. org/Get. Place. List"), System. Xml. Serialization. Xml. Array. Item. Attribute ("Place. Facts", Form=System. Xml. Serialization. Xml. Form. Unqualified, Is. Nullable=false)] public Place. Facts[] Get. Place. List (string place. Name, [System. Xml. Serialization. Xml. Element. Attribute ("Max. Items", Form=System. Xml. Serialization. Xml. Form. Unqualified, Is. Nullable=false)] int max. Items, bool image. Presence) { object[] results = this. Invoke("Get. Place. List", new object[] {place. Name, max. Items, image. Presence}); return (Place. Facts[])(results[0]); } } } 17
Web Page Source Code <html> <script language="C#" runat=server> void Submit. Btn_Click(Object sender, Event. Args e) { Terra. Server. Terra. Service ts = new Terra. Server. Terra. Service(); Census. Server. Census. Service cs = new Census. Server. Census. Service(); Landmark. Server. Landmark. Service ls = new Landmark. Server. Landmark. Service(); Terra. Server. Place. Facts[] pf = ts. Get. Place. List(Place. Text, 10, false); Chosen. Place. Text = String. Format("Chosen place: <b> {0}, {1}, {2}</b>", pf[0]. Place. City, pf[0]. Place. State, pf[0]. Place. Country); Chosen. Lon. Lat. Text = String. Format("(<b>Longitude = {0}, Latitude = {1}</b>)", pf[0]. Center. Lon, pf[0]. Center. Lat); // Continued next slide. . . 18
Source Code (II) Census. Server. Census. Facts cf = cs. Get. Political. Unit. Facts. By. Name (Census. Server. Political. Unit. City, pf[0]. Place. State, 1990); Census. Info. Text = String. Format("Population = {0} ({1} males & {2} females)", cf. Population 1990, cf. Males, cf. Females); //. . . Landmark code here. . . } </script> 19
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" On. Click="Submit. Btn_Click" runat="server"/> <BR> <asp: label id="Chosen. Place" runat="server"/> <BR> <asp: label id="Chosen. Lon. Lat" runat="server"/> <p> <asp: label id="Census. Info" runat="server"/> <BR> <asp: label id="Landmark. Info" runat="server"/> </form> </center> </body> </html> 20
Video Revisited 21
Discussion of Videos • Discussion: What services are here • Discussion: What’s needed beyond just Web Services? 22
How Do I Find Web. Services? • Take a look at http: //uddi. org 23
c20b93edf86fe28d0bbee6d9c7d1da4e.ppt