1 / 44

Công nghệ NET Web Service

Công nghệ NET Web Service. Lương Trần Hy Hiến, Khoa CNTT, ĐH Sư phạm TpHCM. Nội dung. Giới thiệu XML Giới thiệu Web Services Xây dựng Web Services Sử dụng Web Services. CƠ BẢN VỀ XML. XML(e X tensible M arkup L anguage):

lihua
Download Presentation

Công nghệ NET Web Service

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. Công nghệ NETWeb Service Lương Trần Hy Hiến, Khoa CNTT, ĐH Sư phạm TpHCM

  2. Nội dung • Giới thiệu XML • Giới thiệu Web Services • Xây dựng Web Services • Sử dụng Web Services

  3. CƠ BẢN VỀ XML • XML(eXtensible Markup Language): • Là một bộ qui luật về cách chia một tài liệu ra làm nhiều phần, rồi đánh dấu và ráp các phần khác nhau lại để dễ nhận diện chúng

  4. Khái niệm cơ bản start -tag <name> <first>John</first> <middle>Fitzgerald Johansen</middle> <last>Doe</last> </name> root element element element content, Parsed Character DATA (PCDATA), text content, text node end -tag

  5. Khái niệm cơ bản • Tất cả start-tag đều có end-tag. • self-closing tag: <middle/> • Những tag không thể chồng chéo nhau • Sai : <P>Some <STRONG>formatted <EM>text</STRONG>, but</EM> no grammar no good!</P> • Đúng : <P>Some <STRONG>formatted <EM>text</EM></STRONG><EM>, but</EM> no grammar no good!</P> • Mỗi tài liệu XML chỉ có duy nhất 1 root element. • Sai : <name>John</name><name>Jane</name> • Đúng : <names> <name>John</name> <name>Jane</name> </names>

  6. Cấu trúc của tài liệu XML

  7. SỬ DỤNG XML READER • AttributeCount: Số thuộc tính của node • EOF: đi đến cuối stream • Depth: Độ sâu của node hiện hành • IsEmptyElement: chỉ ra node hiện hành có rỗng không • Name: tên node hiện hành • Value: lấy giá trị của node hiện hành • ValueType: lấy kiểu giá trị của node hiện hành

  8. Các phương thức của XMLReader Closed(): Đóng XMLReader GetAttribute() IsStartElement() MovetoAttribute() MovetoNextElement() ReadtartElement() ReadContent()

  9. SỬ DỤNG XML READER • Khai báo không gian tên: • Using System.Xml • Mở tài liệu XML: • Tạo đối tượng: sử dụng phương thức Create()

  10. SỬ DỤNG XML READER • Đọc tài liệu: • Đọc thuộc tính: • Có thể truy cập qua tên hoặc chỉ số:

  11. SỬ DỤNG XML READER

  12. Ghi dữ liệu XML với XmlWriter • Các thuộc tính: • Settings: tạo đối tượng XmlWriterSettings • writeState: trạng thái của bộ ghi • Phương thức: • Close(): đóng dòng dữ liệu hiện hành • Create(): tạo đối tượng XmlWriter • WriteAttributes: ghi tất cả các thuộc tính tại vị trí hiện hành trong đối tượng XmlReader

  13. Ghi dữ liệu XML với XmlWriter • WriteAttributeString: ghi thuộc tính với giá trị chỉ định • WriteChars: ghi khối lượng lớn dữ liệu trong bộ đệm tại một thời điểm • WriteElementString: ghi một phần tử chứa chuỗi giá trị chỉ định • WriteStartAttribute: ghi mở đầu thuộc tính • WriteStartDocument: ghi khai báo XML • WriteStartElement: ghi tag mở • WriteString: ghi nội dung văn bản

  14. Sử dụng XmlWriter • Bắt đầu và kết thúc tài liệu • WriteStartDocument() • Ghi chỉ thị: <?xml version=“1.0”> • WriteEndDocument() • Đóng các thuộc tính và phần tử

  15. Ghi dữ phần tử • Ví dụ: <name> <firstName>Laura</firstName> </name> Writer.WriteStartElement(“name”) Writer.WriteElementString(“firstName”, “Laura”)

  16. Using (XmlWriter writer=XmlWriter.Create(xmlFilePath)) • { Writer.WriteStartDocument(false); • Writer.WriteComment(“This XML file represents thi details of a table Employees”) • Writer.WriteStartElement(“Employees”); • Writer.WriteStartElement(“Employee”); • Writer.WriteAttributeString (“id”, “1”); • Writer.WriteStartElement(“name”); • Writer.WriteElementString(“firstName”,” Laura”); • Writer.WriteElementString(“lastName”,” Callahan”); • Writer.WriteEndElement(); • Writer.WriteElementString(“City”,” Seattle”); • Writer.WriteElementString(“state”,” WA”); • Writer.WriteElementString(“zipcode”,” 98122”); • Writer.WriteEndElement(); • Writer.WriteEndElement(); • Writer.WriteEndDocument(); • Writer.Flush(); • lblResult.Text=”File is written successfully”; • }

  17. Giới thiệu Web Services

  18. Giới thiệu Web Services • Các nhược điểm của DCOM (Distributed Component Object Model): • Gửi các thông tin dưới dạng nhị phân • Bị chặn bởi Firewall và Proxy Server • Truy cập thông qua giao thức Web TCP/IP. • Webservices xây dựng trên SOAP (Simple Object Access Protocol) =>gọi thực hiện và trả về kết quả là dạng TEXT (XML) =>có khả năng hoạt động xuyên qua Firewall: • Khả năng làm việc trên mọi hệ điều hành • Mở rộng khả năng phối hợp giữa các ứng dụng • Tăng cường giao tiếp giữa Client/Server • Ví dụ web services: • Đường sắt Việt Nam cung cấp các web services cho phép đặt mua vé tàu • Các nhà hàng, khách sạn cung cấp các web services cho phép đặt tiệc, đặt phòng • …

  19. Web Services • Web Services: Internet-based modular applications Network Web Service Network may be LAN, WAN, MAN, or the Internet

  20. Web Services Solutions Two of the most popular Web Services Solutions: SUNTM OPEN NET ENVIRONMENT (SUN ONE)

  21. Web Services Characteristics of Web Services Should be registered Accessed over the Web Supported by loosely coupled applications Have a service interface Integrated Just In Time Use standard Web protocols Uses XML

  22. Important Components Service Provider Publish Bind Service Registry Service Broker Service Requestor Find

  23. Life Cycle 6. Unpublish the Web service when not needed 5. Invoke the Web service 4. Search for the Web service 3. Publish the Web service on the Internet or intranet 2. Define service interface and invocation methods for the Web service 1. Create a Web service

  24. Working of a Web Service Service Description Get Type info (XML Schema) Parameters Soap Protocol XML over HTTP Return Value Client Application Web Server (With Web Service)

  25. Application Model Web Services WinForm Users Web Services Web Browser WebForm Internet Java Databases Web Service Consumer

  26. Communication WSDL download Web Service Consumer Web Service SOAP Message Proxy Call Web Method through Proxy

  27. Xây dựng 1 Web Services

  28. Tạo Web Service

  29. Tạo Web Services (tt)

  30. Kiểm tra Web Service

  31. Sử dụng Web Services do mình tạo ra

  32. Sử dụng Web Services do mình tạo ra

  33. Sử dụng Web Service miễn phí trên mạng www.webservicex.net

  34. Các webservices thông dụng http://www.webservicex.net/currencyconvertor.asmx?wsdl http://www.webservicex.net/globalweather.asmx?wsdl http://www.webservicex.net/country.asmx?wsdl

  35. Các bước sử dụng webservice

  36. Các bước sử dụng webservice (tt)

  37. Các bước sử dụng webservice (tt)

  38. Các bước sử dụng webservice (tt)

  39. Các bước sử dụng webservice (tt) Sau khi thêm các dịch vụ:

  40. Thể hiện các thông tin của webservice

  41. Thể hiện các thông tin của webservice

  42. Virtual Bank Web Browser Online Shopping Cart V-Bank Web Service Client Server

  43. Bank Account Web Service • Account(Id, PinCode, Name, Balance) • Withdraw(Id, PinCode, Money) • Deposit(Id, PinCode, Money) • Transfer(Id, PinCode, Money, Id2)

  44. ATM User Interface

More Related