SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Giới thiệu

Windows Communication
Foundation
             Nguyễn Bá Quang
               [basquang@hotmail.com]
                   Microsoft Corporation
Nội dung


•   Windows Communication Foundation là gì?
•   Kiến trúc hướng dịch vụ (SOA) và WCF
•   Làm gì để xây dựng một ứng dụng WCF?
•   Một dịch vụ WCF hoạt động như thế nào?
•   Hosting một dịch vụ WCF
Vấn đề phát sinh
  Các phần mềm hiện nay yêu cầu khả năng tích
  hợp cao

  … Xây dựng các hệ thống có tính kết nối là rất khó!

  1. Có rất nhiều công nghệ giải quyết cho
      vấn đề truyền thông và tích hợp hiện nay
       Chọn cái nào?
  2. Nhu cầu thay đổi nền tảng ứng dụng
      xảy ra bất cứ lúc nào
       Làm sao để chuyển đổi mà tiết kiệm chi phí
Windows Communication Foundation




  Khung thống nhất cho việc
   phát triển nhanh các ứng
       dụng hướng dịch vụ.
Windows Communication Foundation

Mô hình thống nhất thay thế cho các công nghệ phân tán trước đó



           ASMX                                  Remoting

         Dịch vụ Web                           Mô hình từ xa
          ASP.NET


             ES/COM+           WSE          MSMQ

            Lập trình nền                 Lập trình nền
             thuộc tính     Dịch vụ Web
                             nâng cao      thông điệp
Mục tiêu thiết kế WCF
  “Mô hình lập trình thống nhất nhằm phát triển nhanh các ứng
              dụng hướng dịch vụ trên nền Windows”

     Thống nhất về công nghệ
     Giữ nguyên ưu điểm
     Thích hợp cho nhiều             Unification
     mục đích sử dụng                     Thống nhất




Là một mô hình lập                                                       Tương tác và tích hợp
trình hướng dịch vụ    Productive SO               Interoperability       với các ứng dụng trên
Đáp ứng 4 tiêu chí    Programming                  & Integration         các nền tảng khác
của lập trình hướng      Đẩy mạnh lập                                     Tương tác và nâng cấp
                                                       Khả năng tương
dịch vụ                trình hướng dịch                                   các ứng dụng phân tán
                                                        tác và tích hợp
                               vụ
                                                                          hiện có
SOA và WCF
 WCF đã được thiết kế với các nguyên lý sau của SOA

Rõ ràng về ranh     Các ứng dụng và dịch vụ liên lạc với nhau
                    thông qua các thông điệp mà không quan tâm
      giới          đến việc xử lý và tiếp nhận

                    Dịch vụ và sử dụng dịch vụ là độc lập với các
  Tự phát triển     quá trình nâng cấp phiên bản, triển khai, hoạt
                    động và bảo mật.

 Chia sẻ yêu cầu,
                    Các dịch vụ cung cấp các phép toánvà cấu trúc
không chia sẻ nội   thông tin. Không bao gồm nội dung thông tin
      dung
                    Các dịch vụ có thể thiết kế để độc lập với việc
Tương thích dựa
                    triển khai, thống nhất với các ứng dụng về
 trên chính sách    chuẩn giao tiếp
Các lợi ích của SOA
                   Dễ dàng thự thi

       Độc lập triển khai, phát triển và quản lý

      Nâng cao khả năng tái sử dụng công nghệ




     Giảm chi phí cho việc cập
     nhật và bảo trì phần mềm
Xây dựng một ứng dụng WCF




  Xây dựng một dịch vụ WCF
Xây dựng một ứng dụng client
       sử dụng dịch vụ WCF
Xây dựng dịch vụ WCF


• Định nghĩa các Contracts
  • Data Contract
  • Operation Contract
• Thi hành các dịch vụ
• Cấu hình, triển khai và kiểm thử các dịch vụ
  • Cấu hình services trong configuration file
  • Triển khai lên IIS 7
  • Kiểm thử
Data Contract


• [DataContract]: cho biết một class được khai
  báo có thể được serialized và deserialized như một
  XML stream bởi WCF
• [DataMember]: cho biết
  thuộc tính nào sẽ được
  serialized và deserialized
Service Contract


• [ServiceContract ]: cho biết một interface là một
  service contract. WCF dựa vào thuộc tính này
  để sinh ra metadata cho client khi sử dụng
• [OperationContract]: cho biết phương thức nào sẽ được
  đưa vào sử dụng
Thi hành các dịch vụ

• Một class được cung cấp bởi một dịch vụ WCF phải
  thực thi đầy đủ một service contract.
Cấu hình các dịch vụ WCF

• ProductService.svc

• Web.config
<serviceModel>: chứa thông tin cấu
hình cho một dịch vụ Web WCF
<services>: chứa thông tin chi tiết
của mỗi service được thực thi
<service>: chỉ ra namespace và
class mà thực thi service
<endpoint>: cung cấp thông tin chi
tiết của service mà các ứng dụng
client yêu cầu theo thứ tự để liên
lạc với service
<behavior >: cho phép metadata
được công bố tới client
Triển khai trên IIS 7 (Vista)
Kiểm thử
Xây dựng ứng dụng client
Nguyên lý ABCs của WCF
Kiến trúc ABCs của WCF
                                             Service Host



   Client                                                   Service
  Bv                                         A      B   C        Bv

  Bv        C   B     A       Message        A      B   C        Bv




                    Address   Binding    Contract
                    (Where)    (How)      (What)

                              Endpoint
Endpoints

• Address: Where?
   – Chỉ ra nơi nào để gửi và nhận thông điệp
   – Chỉ ra nơi nào để tìm ra Endpoints
• Binding: How?
   – Chỉ ra làm cách nào để gửi thông điệp
   – Chỉ ra làm sao để client liên lạc với Service endpoints
• Contract: What?
   – Chỉ ra nhưng cái gì được bao gồm trong thông điệp
   – Chỉ ra những dịch vụ nào client có thể sử dụng
• Behaviours:
   – Triển khai chi tiết
Address


• Nơi để truyền và nhận thông điệp
• Cung cấp thông tin:
  –   Đường dẫn
  –   Giao thức vận chuyển
  –   Tên Host
  –   Cổng truy cập     [transport]://[machine][:optional port]
                            http://localhost
                            http://localhost:8081
                            http://localhost:8081/Service
                            net.tcp://localhost:8082/Service
                            net.pipe://localhost/Pipe
Address URI                                                                      Peer to Peer

       Scheme                                                            net.p2p://localhost/MyService
                                                                                NetPeerTcpBinding

       Host
                                                      MSMQ
       Port                            net.msmq://localhost/private/MyService

       Path                                      NetMsmqBinding

      Named Pipes                                                                             TCP
net.pipe://localhost/MyService                                                  net.tcp://localhost:8088/MyService

    NetNamedPipeBinding                                                                   NetTcpBinding

                                                    HTTP
                                                                                       Chia sẻ Port thông qua
                                         http://localhost:80/MyService                TCP Port Sharing Service

              Chia sẻ Port thông qua          BasicHttpBinding
                     HTTP.SYS                  WSHttpBinding
                                             WSDualHttpBinding
                                           WSFederationHttpBinding
Bindings (Gắn kết)


• Mô tả cách Client kết nối với services
• Định dạng dữ liệu mong muốn
• Có thể bao gồm các thông tin
  –   Giao thức vận chuyển
  –   Định dạng mã hóa thông điệp
  –   Cơ chế bảo mật
  –   Cơ chế giao dịch
                                  Một số bindings phổ biến
                                  BasicHttpBinding
  –   Tính tin cậy trong liên lạc NetTcpBinding
                                  WSHttpBinding
                                  NetMsqmqBinding
Contracts (Hợp đồng)


• [Service Contract]: Là một Interface
• [OperationContract]: Mô tả các phép toán có thể
  thực thi bởi service
   – Toàn bộ data phải được serializable
• [Data Contract]: Mô tả cấu trúc dữ liệu và cách mà dữ
  liệu được serializable.
Hosting and Demo




   IIS 7 và WAS
Windows Service
 Ứng dụng User
Hosting: Ứng dụng người dùng
class HelloHost {
  static void Main(string[] args) {
    ServiceHost host =
      new ServiceHost(typeof(HelloService));
    host.Open();
    Console.ReadLine();
    host.Close();
  }
}



<service name="HelloService">
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost:8000"/>
    </baseAddresses>
  </host>
   …
</service>
Hosting: Ứng dụng người dùng
• Thuận lợi
  – Kiểm soát toàn vẹn
  – Không giới hạn trong việc binding/behavior
  – Sử dụng các ứng dụng có giao diện
• Khó khăn
  – Không có các chức năng quản lý Hosting
Hosting: Windows Service
public class WindowsService : ServiceBase {
  ServiceHost host;
  protected override void OnStart(string[] args) {
    host = new ServiceHost(typeof(HelloService));
    host.Open();
  }
  protected override void OnStop() {
    host.Close();
  }
}

[RunInstaller(true)]
public class WindowsServiceInstaller : Installer {
  public WindowsServiceInstaller() {
    ServiceProcessInstaller spi =
       new ServiceProcessInstaller();
    ServiceInstaller si = new ServiceInstaller();
    Installers.Add(spi);
    Installers.Add(si);
  }
}
Hosting: Windows Service
• Thuận lợi
   – Tự động Start/Stop/Restart
   – Có tool quản lý service
   – Có thể thực thi ở tài khoản máy cũng như người
     dùng
• Khó khăn
   – Sự kích hoạt không có thông báo
Hosting: IIS7/WAS

http://localhost/HelloService/HelloService.svc

<%@ Service language="C#" class="HelloService" %>
using System;
using System.ServiceModel;
public class HelloService : IHelloService {
 …
}
Hosting: IIS7/WAS
• Thuận lợi
  – Kích hoạt sẵn có trong IIS
  – Hỗ trợ Named Pipes, TCP, and MSMQ
  – Sử dụng công cụ quản lý IIS7 mới
• Khó khăn
  – Chỉ hoạt động trên VISTA
Tóm tắt về WCF

• WCF là công nghệ cho tính toán phân tán
• WCF tích hợp tất cả các công nghệ phân tán tốt nhất
• Sử dụng chuẩn Web Services để tương tác và tích hợp
  với các giải pháp đang tồn tại
• WCF sẵn có trong Windows Vista, Windows XP SP2,
  Windows Server 2008
Tham khảo thêm….
     Check out the WCF community site for a list of useful
     resources: http://windowscommunication.net

     Download and prototype on the WCF CTP Releases:
     http://msdn.microsoft.com/windowsvista/getthebeta/d
     efault.aspx

     Leverage the community forum to post comments and
     connect with the feature team:
     http://forums.microsoft.com/MSDN/ShowForum.aspx?
     ForumID=118&SiteID=1
Giới thiệu WCF

Weitere ähnliche Inhalte

Andere mochten auch

El neorrealisme italià
El neorrealisme italiàEl neorrealisme italià
El neorrealisme italiàssolanmo
 
コンバージョンを意識したCMS運用
コンバージョンを意識したCMS運用コンバージョンを意識したCMS運用
コンバージョンを意識したCMS運用takuo yamada
 
Brazilian Travel Industry
Brazilian Travel IndustryBrazilian Travel Industry
Brazilian Travel IndustryFelipe Perlino
 
The Value Propositions of Employer Branding
The Value Propositions of Employer BrandingThe Value Propositions of Employer Branding
The Value Propositions of Employer Brandingrajivnaithani
 
Smartshop: development and creation of an e-commerce app for smartphones
Smartshop: development and creation of an e-commerce app for smartphonesSmartshop: development and creation of an e-commerce app for smartphones
Smartshop: development and creation of an e-commerce app for smartphonessimom87
 
How to Write Funny For Work and Play
How to Write Funny For Work and PlayHow to Write Funny For Work and Play
How to Write Funny For Work and PlayLucia Novara
 
Jonge Democraten - Individueel pensioen zonder sociale partners.
Jonge Democraten - Individueel pensioen zonder sociale partners.Jonge Democraten - Individueel pensioen zonder sociale partners.
Jonge Democraten - Individueel pensioen zonder sociale partners.BeFrank
 
Emerce eFinancials
Emerce eFinancialsEmerce eFinancials
Emerce eFinancialsBeFrank
 
The Future of Content Marketing
The Future of Content MarketingThe Future of Content Marketing
The Future of Content MarketingLucia Novara
 
About Kaar Watch
About Kaar WatchAbout Kaar Watch
About Kaar WatchAndrew Asir
 
Transforming Theater Fundraising with BiddingForGood
Transforming Theater Fundraising with BiddingForGoodTransforming Theater Fundraising with BiddingForGood
Transforming Theater Fundraising with BiddingForGoodPerry Allison
 
Webデザイントレンドと a-blog cms に組み込みたい実装
Webデザイントレンドと a-blog cms に組み込みたい実装Webデザイントレンドと a-blog cms に組み込みたい実装
Webデザイントレンドと a-blog cms に組み込みたい実装takuo yamada
 
2012 User Experience in Canada - Work & Salary Survey
2012 User Experience in Canada - Work & Salary Survey2012 User Experience in Canada - Work & Salary Survey
2012 User Experience in Canada - Work & Salary SurveyLaura B
 
Digital media for marketing meeting 2011
Digital media for marketing meeting 2011Digital media for marketing meeting 2011
Digital media for marketing meeting 2011cmviasat
 
Open innoveren in tijden van schaarste
Open innoveren in tijden van schaarsteOpen innoveren in tijden van schaarste
Open innoveren in tijden van schaarsteVincent Van Malderen
 
Building a $100k and flexible design career
Building a $100k and flexible design careerBuilding a $100k and flexible design career
Building a $100k and flexible design careeradambcarney
 

Andere mochten auch (19)

El neorrealisme italià
El neorrealisme italiàEl neorrealisme italià
El neorrealisme italià
 
コンバージョンを意識したCMS運用
コンバージョンを意識したCMS運用コンバージョンを意識したCMS運用
コンバージョンを意識したCMS運用
 
Brazilian Travel Industry
Brazilian Travel IndustryBrazilian Travel Industry
Brazilian Travel Industry
 
The Value Propositions of Employer Branding
The Value Propositions of Employer BrandingThe Value Propositions of Employer Branding
The Value Propositions of Employer Branding
 
Smartshop: development and creation of an e-commerce app for smartphones
Smartshop: development and creation of an e-commerce app for smartphonesSmartshop: development and creation of an e-commerce app for smartphones
Smartshop: development and creation of an e-commerce app for smartphones
 
The compass
The compassThe compass
The compass
 
How to Write Funny For Work and Play
How to Write Funny For Work and PlayHow to Write Funny For Work and Play
How to Write Funny For Work and Play
 
Jonge Democraten - Individueel pensioen zonder sociale partners.
Jonge Democraten - Individueel pensioen zonder sociale partners.Jonge Democraten - Individueel pensioen zonder sociale partners.
Jonge Democraten - Individueel pensioen zonder sociale partners.
 
Emerce eFinancials
Emerce eFinancialsEmerce eFinancials
Emerce eFinancials
 
The Future of Content Marketing
The Future of Content MarketingThe Future of Content Marketing
The Future of Content Marketing
 
About Kaar Watch
About Kaar WatchAbout Kaar Watch
About Kaar Watch
 
Transforming Theater Fundraising with BiddingForGood
Transforming Theater Fundraising with BiddingForGoodTransforming Theater Fundraising with BiddingForGood
Transforming Theater Fundraising with BiddingForGood
 
Webデザイントレンドと a-blog cms に組み込みたい実装
Webデザイントレンドと a-blog cms に組み込みたい実装Webデザイントレンドと a-blog cms に組み込みたい実装
Webデザイントレンドと a-blog cms に組み込みたい実装
 
Shyamkrishna
ShyamkrishnaShyamkrishna
Shyamkrishna
 
C
CC
C
 
2012 User Experience in Canada - Work & Salary Survey
2012 User Experience in Canada - Work & Salary Survey2012 User Experience in Canada - Work & Salary Survey
2012 User Experience in Canada - Work & Salary Survey
 
Digital media for marketing meeting 2011
Digital media for marketing meeting 2011Digital media for marketing meeting 2011
Digital media for marketing meeting 2011
 
Open innoveren in tijden van schaarste
Open innoveren in tijden van schaarsteOpen innoveren in tijden van schaarste
Open innoveren in tijden van schaarste
 
Building a $100k and flexible design career
Building a $100k and flexible design careerBuilding a $100k and flexible design career
Building a $100k and flexible design career
 

Ähnlich wie Giới thiệu WCF

Slide Web Service
Slide Web ServiceSlide Web Service
Slide Web Serviceask bills
 
Business process excution language
Business process excution languageBusiness process excution language
Business process excution languageNguyen Tran
 
(HoaND) giao trinh webservice
(HoaND) giao trinh webservice (HoaND) giao trinh webservice
(HoaND) giao trinh webservice Duc Hoa
 
Bao cao do an ltm hoan chinh
Bao cao do an ltm hoan chinhBao cao do an ltm hoan chinh
Bao cao do an ltm hoan chinhNgok Ánk
 
Tìm hiểu web service
Tìm hiểu web serviceTìm hiểu web service
Tìm hiểu web serviceThieu Mao
 
Kiến trúc-hướng-dịch-vụ-webservice
Kiến trúc-hướng-dịch-vụ-webserviceKiến trúc-hướng-dịch-vụ-webservice
Kiến trúc-hướng-dịch-vụ-webserviceThuyet Nguyen
 
Kiến trúc hướng dịch vụ (webservice)
Kiến trúc hướng dịch vụ (webservice)Kiến trúc hướng dịch vụ (webservice)
Kiến trúc hướng dịch vụ (webservice)Nguyễn Thu Hằng
 
Web Architecture
Web ArchitectureWeb Architecture
Web ArchitectureHiep Luong
 
Windows comunication foundation
Windows comunication foundationWindows comunication foundation
Windows comunication foundationTiến Quang Phan
 
Ltw0 baimodau
Ltw0 baimodauLtw0 baimodau
Ltw0 baimodauHoa Dại
 
Bao cao web cake php
Bao cao web cake phpBao cao web cake php
Bao cao web cake phplaonap166
 
Videoconferencereport
VideoconferencereportVideoconferencereport
Videoconferencereporttuanle1984
 
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVER
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVERGIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVER
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVERPMC WEB
 
chuong 1 - Tong quan ve Lap trinh mang.ppt
chuong 1 - Tong quan ve Lap trinh mang.pptchuong 1 - Tong quan ve Lap trinh mang.ppt
chuong 1 - Tong quan ve Lap trinh mang.pptkhamgo1191
 
Cloud computing and OpenStack
Cloud computing and OpenStackCloud computing and OpenStack
Cloud computing and OpenStackMinh Le
 
Cloud computing and OpenStack
Cloud computing and OpenStackCloud computing and OpenStack
Cloud computing and OpenStackMinh Le
 
Chapter 1 introduction www
Chapter 1  introduction wwwChapter 1  introduction www
Chapter 1 introduction wwwxuandiencntt
 

Ähnlich wie Giới thiệu WCF (20)

Web service
Web serviceWeb service
Web service
 
Slide Web Service
Slide Web ServiceSlide Web Service
Slide Web Service
 
Business process excution language
Business process excution languageBusiness process excution language
Business process excution language
 
(HoaND) giao trinh webservice
(HoaND) giao trinh webservice (HoaND) giao trinh webservice
(HoaND) giao trinh webservice
 
Bao cao do an ltm hoan chinh
Bao cao do an ltm hoan chinhBao cao do an ltm hoan chinh
Bao cao do an ltm hoan chinh
 
Luận văn: Tích hợp dịch vụ nghiệp vụ ngân hàng theo mô hình soa
Luận văn: Tích hợp dịch vụ nghiệp vụ ngân hàng theo mô hình soaLuận văn: Tích hợp dịch vụ nghiệp vụ ngân hàng theo mô hình soa
Luận văn: Tích hợp dịch vụ nghiệp vụ ngân hàng theo mô hình soa
 
Tìm hiểu web service
Tìm hiểu web serviceTìm hiểu web service
Tìm hiểu web service
 
Kiến trúc-hướng-dịch-vụ-webservice
Kiến trúc-hướng-dịch-vụ-webserviceKiến trúc-hướng-dịch-vụ-webservice
Kiến trúc-hướng-dịch-vụ-webservice
 
Kiến trúc hướng dịch vụ (webservice)
Kiến trúc hướng dịch vụ (webservice)Kiến trúc hướng dịch vụ (webservice)
Kiến trúc hướng dịch vụ (webservice)
 
Web Architecture
Web ArchitectureWeb Architecture
Web Architecture
 
Windows comunication foundation
Windows comunication foundationWindows comunication foundation
Windows comunication foundation
 
Bản cuối
Bản cuốiBản cuối
Bản cuối
 
Ltw0 baimodau
Ltw0 baimodauLtw0 baimodau
Ltw0 baimodau
 
Bao cao web cake php
Bao cao web cake phpBao cao web cake php
Bao cao web cake php
 
Videoconferencereport
VideoconferencereportVideoconferencereport
Videoconferencereport
 
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVER
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVERGIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVER
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVER
 
chuong 1 - Tong quan ve Lap trinh mang.ppt
chuong 1 - Tong quan ve Lap trinh mang.pptchuong 1 - Tong quan ve Lap trinh mang.ppt
chuong 1 - Tong quan ve Lap trinh mang.ppt
 
Cloud computing and OpenStack
Cloud computing and OpenStackCloud computing and OpenStack
Cloud computing and OpenStack
 
Cloud computing and OpenStack
Cloud computing and OpenStackCloud computing and OpenStack
Cloud computing and OpenStack
 
Chapter 1 introduction www
Chapter 1  introduction wwwChapter 1  introduction www
Chapter 1 introduction www
 

Mehr von Quang Nguyễn Bá

Lesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPFLesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPFQuang Nguyễn Bá
 
Lesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPFLesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPFQuang Nguyễn Bá
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFQuang Nguyễn Bá
 
Lesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPFLesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPFQuang Nguyễn Bá
 
Lesson 02 Introduction to XAML
Lesson 02 Introduction to XAMLLesson 02 Introduction to XAML
Lesson 02 Introduction to XAMLQuang Nguyễn Bá
 
TDD - Test Driven Dvelopment | Test First Design
TDD -  Test Driven Dvelopment | Test First DesignTDD -  Test Driven Dvelopment | Test First Design
TDD - Test Driven Dvelopment | Test First DesignQuang Nguyễn Bá
 
Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012Quang Nguyễn Bá
 
Introduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration ServicesIntroduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration ServicesQuang Nguyễn Bá
 
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2Quang Nguyễn Bá
 
Introduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis ServiceIntroduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis ServiceQuang Nguyễn Bá
 
SharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceSharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceQuang Nguyễn Bá
 
Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010Quang Nguyễn Bá
 

Mehr von Quang Nguyễn Bá (20)

Lesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPFLesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPF
 
Lesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPFLesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPF
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
 
Lesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPFLesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPF
 
Lesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPFLesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPF
 
Lesson 04 WPF Controls
Lesson 04 WPF ControlsLesson 04 WPF Controls
Lesson 04 WPF Controls
 
Lesson 03 Layouts in WPF
Lesson 03 Layouts in WPFLesson 03 Layouts in WPF
Lesson 03 Layouts in WPF
 
Lesson 02 Introduction to XAML
Lesson 02 Introduction to XAMLLesson 02 Introduction to XAML
Lesson 02 Introduction to XAML
 
Lesson 01 Introduction to WPF
Lesson 01 Introduction to WPFLesson 01 Introduction to WPF
Lesson 01 Introduction to WPF
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
 
TDD - Test Driven Dvelopment | Test First Design
TDD -  Test Driven Dvelopment | Test First DesignTDD -  Test Driven Dvelopment | Test First Design
TDD - Test Driven Dvelopment | Test First Design
 
Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012
 
Introduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration ServicesIntroduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration Services
 
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
 
Introduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis ServiceIntroduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis Service
 
Office 2010 Programming
Office 2010 ProgrammingOffice 2010 Programming
Office 2010 Programming
 
MOSS 2007 Overview
MOSS 2007 OverviewMOSS 2007 Overview
MOSS 2007 Overview
 
SharePoint Programming Basic
SharePoint Programming BasicSharePoint Programming Basic
SharePoint Programming Basic
 
SharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceSharePoint 2010 Business Intelligence
SharePoint 2010 Business Intelligence
 
Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010
 

Giới thiệu WCF

  • 1. Giới thiệu Windows Communication Foundation Nguyễn Bá Quang [basquang@hotmail.com] Microsoft Corporation
  • 2. Nội dung • Windows Communication Foundation là gì? • Kiến trúc hướng dịch vụ (SOA) và WCF • Làm gì để xây dựng một ứng dụng WCF? • Một dịch vụ WCF hoạt động như thế nào? • Hosting một dịch vụ WCF
  • 3. Vấn đề phát sinh Các phần mềm hiện nay yêu cầu khả năng tích hợp cao … Xây dựng các hệ thống có tính kết nối là rất khó! 1. Có rất nhiều công nghệ giải quyết cho vấn đề truyền thông và tích hợp hiện nay  Chọn cái nào? 2. Nhu cầu thay đổi nền tảng ứng dụng xảy ra bất cứ lúc nào  Làm sao để chuyển đổi mà tiết kiệm chi phí
  • 4. Windows Communication Foundation Khung thống nhất cho việc phát triển nhanh các ứng dụng hướng dịch vụ.
  • 5. Windows Communication Foundation Mô hình thống nhất thay thế cho các công nghệ phân tán trước đó ASMX Remoting Dịch vụ Web Mô hình từ xa ASP.NET ES/COM+ WSE MSMQ Lập trình nền Lập trình nền thuộc tính Dịch vụ Web nâng cao thông điệp
  • 6. Mục tiêu thiết kế WCF “Mô hình lập trình thống nhất nhằm phát triển nhanh các ứng dụng hướng dịch vụ trên nền Windows” Thống nhất về công nghệ Giữ nguyên ưu điểm Thích hợp cho nhiều Unification mục đích sử dụng Thống nhất Là một mô hình lập Tương tác và tích hợp trình hướng dịch vụ Productive SO Interoperability với các ứng dụng trên Đáp ứng 4 tiêu chí Programming & Integration các nền tảng khác của lập trình hướng Đẩy mạnh lập Tương tác và nâng cấp Khả năng tương dịch vụ trình hướng dịch các ứng dụng phân tán tác và tích hợp vụ hiện có
  • 7. SOA và WCF WCF đã được thiết kế với các nguyên lý sau của SOA Rõ ràng về ranh Các ứng dụng và dịch vụ liên lạc với nhau thông qua các thông điệp mà không quan tâm giới đến việc xử lý và tiếp nhận Dịch vụ và sử dụng dịch vụ là độc lập với các Tự phát triển quá trình nâng cấp phiên bản, triển khai, hoạt động và bảo mật. Chia sẻ yêu cầu, Các dịch vụ cung cấp các phép toánvà cấu trúc không chia sẻ nội thông tin. Không bao gồm nội dung thông tin dung Các dịch vụ có thể thiết kế để độc lập với việc Tương thích dựa triển khai, thống nhất với các ứng dụng về trên chính sách chuẩn giao tiếp
  • 8. Các lợi ích của SOA Dễ dàng thự thi Độc lập triển khai, phát triển và quản lý Nâng cao khả năng tái sử dụng công nghệ Giảm chi phí cho việc cập nhật và bảo trì phần mềm
  • 9. Xây dựng một ứng dụng WCF Xây dựng một dịch vụ WCF Xây dựng một ứng dụng client sử dụng dịch vụ WCF
  • 10. Xây dựng dịch vụ WCF • Định nghĩa các Contracts • Data Contract • Operation Contract • Thi hành các dịch vụ • Cấu hình, triển khai và kiểm thử các dịch vụ • Cấu hình services trong configuration file • Triển khai lên IIS 7 • Kiểm thử
  • 11. Data Contract • [DataContract]: cho biết một class được khai báo có thể được serialized và deserialized như một XML stream bởi WCF • [DataMember]: cho biết thuộc tính nào sẽ được serialized và deserialized
  • 12. Service Contract • [ServiceContract ]: cho biết một interface là một service contract. WCF dựa vào thuộc tính này để sinh ra metadata cho client khi sử dụng • [OperationContract]: cho biết phương thức nào sẽ được đưa vào sử dụng
  • 13. Thi hành các dịch vụ • Một class được cung cấp bởi một dịch vụ WCF phải thực thi đầy đủ một service contract.
  • 14. Cấu hình các dịch vụ WCF • ProductService.svc • Web.config <serviceModel>: chứa thông tin cấu hình cho một dịch vụ Web WCF <services>: chứa thông tin chi tiết của mỗi service được thực thi <service>: chỉ ra namespace và class mà thực thi service <endpoint>: cung cấp thông tin chi tiết của service mà các ứng dụng client yêu cầu theo thứ tự để liên lạc với service <behavior >: cho phép metadata được công bố tới client
  • 15. Triển khai trên IIS 7 (Vista)
  • 17. Xây dựng ứng dụng client
  • 18. Nguyên lý ABCs của WCF
  • 19. Kiến trúc ABCs của WCF Service Host Client Service Bv A B C Bv Bv C B A Message A B C Bv Address Binding Contract (Where) (How) (What) Endpoint
  • 20. Endpoints • Address: Where? – Chỉ ra nơi nào để gửi và nhận thông điệp – Chỉ ra nơi nào để tìm ra Endpoints • Binding: How? – Chỉ ra làm cách nào để gửi thông điệp – Chỉ ra làm sao để client liên lạc với Service endpoints • Contract: What? – Chỉ ra nhưng cái gì được bao gồm trong thông điệp – Chỉ ra những dịch vụ nào client có thể sử dụng • Behaviours: – Triển khai chi tiết
  • 21. Address • Nơi để truyền và nhận thông điệp • Cung cấp thông tin: – Đường dẫn – Giao thức vận chuyển – Tên Host – Cổng truy cập [transport]://[machine][:optional port] http://localhost http://localhost:8081 http://localhost:8081/Service net.tcp://localhost:8082/Service net.pipe://localhost/Pipe
  • 22. Address URI Peer to Peer Scheme net.p2p://localhost/MyService NetPeerTcpBinding Host MSMQ Port net.msmq://localhost/private/MyService Path NetMsmqBinding Named Pipes TCP net.pipe://localhost/MyService net.tcp://localhost:8088/MyService NetNamedPipeBinding NetTcpBinding HTTP Chia sẻ Port thông qua http://localhost:80/MyService TCP Port Sharing Service Chia sẻ Port thông qua BasicHttpBinding HTTP.SYS WSHttpBinding WSDualHttpBinding WSFederationHttpBinding
  • 23. Bindings (Gắn kết) • Mô tả cách Client kết nối với services • Định dạng dữ liệu mong muốn • Có thể bao gồm các thông tin – Giao thức vận chuyển – Định dạng mã hóa thông điệp – Cơ chế bảo mật – Cơ chế giao dịch Một số bindings phổ biến BasicHttpBinding – Tính tin cậy trong liên lạc NetTcpBinding WSHttpBinding NetMsqmqBinding
  • 24. Contracts (Hợp đồng) • [Service Contract]: Là một Interface • [OperationContract]: Mô tả các phép toán có thể thực thi bởi service – Toàn bộ data phải được serializable • [Data Contract]: Mô tả cấu trúc dữ liệu và cách mà dữ liệu được serializable.
  • 25. Hosting and Demo IIS 7 và WAS Windows Service Ứng dụng User
  • 26. Hosting: Ứng dụng người dùng class HelloHost { static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof(HelloService)); host.Open(); Console.ReadLine(); host.Close(); } } <service name="HelloService"> <host> <baseAddresses> <add baseAddress="http://localhost:8000"/> </baseAddresses> </host> … </service>
  • 27. Hosting: Ứng dụng người dùng • Thuận lợi – Kiểm soát toàn vẹn – Không giới hạn trong việc binding/behavior – Sử dụng các ứng dụng có giao diện • Khó khăn – Không có các chức năng quản lý Hosting
  • 28. Hosting: Windows Service public class WindowsService : ServiceBase { ServiceHost host; protected override void OnStart(string[] args) { host = new ServiceHost(typeof(HelloService)); host.Open(); } protected override void OnStop() { host.Close(); } } [RunInstaller(true)] public class WindowsServiceInstaller : Installer { public WindowsServiceInstaller() { ServiceProcessInstaller spi = new ServiceProcessInstaller(); ServiceInstaller si = new ServiceInstaller(); Installers.Add(spi); Installers.Add(si); } }
  • 29. Hosting: Windows Service • Thuận lợi – Tự động Start/Stop/Restart – Có tool quản lý service – Có thể thực thi ở tài khoản máy cũng như người dùng • Khó khăn – Sự kích hoạt không có thông báo
  • 30. Hosting: IIS7/WAS http://localhost/HelloService/HelloService.svc <%@ Service language="C#" class="HelloService" %> using System; using System.ServiceModel; public class HelloService : IHelloService { … }
  • 31. Hosting: IIS7/WAS • Thuận lợi – Kích hoạt sẵn có trong IIS – Hỗ trợ Named Pipes, TCP, and MSMQ – Sử dụng công cụ quản lý IIS7 mới • Khó khăn – Chỉ hoạt động trên VISTA
  • 32. Tóm tắt về WCF • WCF là công nghệ cho tính toán phân tán • WCF tích hợp tất cả các công nghệ phân tán tốt nhất • Sử dụng chuẩn Web Services để tương tác và tích hợp với các giải pháp đang tồn tại • WCF sẵn có trong Windows Vista, Windows XP SP2, Windows Server 2008
  • 33. Tham khảo thêm…. Check out the WCF community site for a list of useful resources: http://windowscommunication.net Download and prototype on the WCF CTP Releases: http://msdn.microsoft.com/windowsvista/getthebeta/d efault.aspx Leverage the community forum to post comments and connect with the feature team: http://forums.microsoft.com/MSDN/ShowForum.aspx? ForumID=118&SiteID=1

Hinweis der Redaktion

  1. Speaker NotesThese are the what we refer to as the three pillars of WCF. They are the three design goals of WCF that really sum up what that technology is all about. They’re what we’ll be drilling into for the remainder of this presentation.&lt;click&gt;The first design goal is unification. When we talk about unification, we’re talking about bringing together the various technologies available today for building distributed applications (COM+ and .NET Enterprise services, MSMQ, .NET Remoting, ASP.NET Web Services, Web Services Enhancements (WSE)) into a single, unified programming model. Why is this important? First, it reduces complexity by allowing us to focus on a single programming model rather than learn multiple programming models. Second, it allows us to compose/combine the functionality of today’s technologies in ways that we can’t today. Finally, it allows us to use a single programming model for building distributed applications that communicate with one another on a single machine, across multiple machines, and across the Internet.&lt;click&gt;The second design goal is interoperability and integration. We talk about interoperability and integration on two different pivots. First, WCF enables you to build services that speak advanced Web services protocols (WS-*), enabling your application to communicate with other WS-* compliant services running on other platforms. Second, we built WCF to provide a smooth upgrade and interop story for your distributed applications built on today’s technologies (WSE, ASMX, .NET Enterprise Services, System.Messaging, .NET Remoting). Why are Interop and Integration important?First, the ability to communicate with applications running on other platforms provides you with the flexibility you need when working in a heterogeneous environment.Second, the ability to communicate with existing applications protects your investments and provides you with an optional, incremental upgrade path to WCF.&lt;click&gt;The third design goal is all about productivity and service orientation. WCF provides developers with a highly productive programming model for building service-oriented applications. By using WCF’s attribute-based programming to define your services, you can dramatically reduce the amount of code you write to build secure, reliable services. WCF also facilitates the development of applications that adhere to the “four tenets of service-orientation” that we’ll drill into later in the presentation. These tenets help ensure that your services are extremely flexible and resilient to change, thereby reducing long-term maintenance costs.Transition to next slide:We’ll spend the rest of this presentation drilling into these 3 concepts, but before doing so, let’s quickly discuss some of the basics of WCF…
  2. &lt;serviceModel&gt;: chứathông tin cấuhìnhchomộtdịchvụ Web WCF&lt;services&gt;:chứathông tin chi tiếtcủamỗi service đượcthựcthi&lt;service&gt;: chỉra namespace và class màthựcthi service&lt;endpoint&gt;: cungcấpthông tin chi tiếtcủa service màcácứngdụng client yêucầutheothứtựđểliênlạcvới service&lt;behavior&gt;: chophép metadata đượccôngbốtới client. Mặcđịnh WCF sẽkhôngcôngbốvìlý do bảomật
  3. Mộtdịchvụ WCF làmộtđốitượngcungcấpcácthaotácxửlýchocácứngdụng clientĐểthựcthidịchvụcầncungcấpmôitrườngthựcthi, đóchínhlàmộtứngdụng hostMột host đảmđươngnhiệmvụBậtvàtắtdịchvụLắngnghelờigọitừ client vàchuyểnnótớidịchvụGửiphảnhồinhậnđượctừphíadịchvụtới client
  4. Self-Host: using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri(&quot;net.tcp://localhost:9000&quot;))){  host.AddServiceEndpoint( typeof(HelloIndigo.IHelloIndigoService), new NetTcpBinding(), &quot;HelloIndigo&quot;);  host.Open();Config Base Addresses:  &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress=&quot;http://localhost:8000&quot;/&gt;&lt;/baseAddresses&gt;&lt;/host&gt;Self-Host: using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri(&quot;net.tcp://localhost:9000&quot;))){  host.AddServiceEndpoint( typeof(HelloIndigo.IHelloIndigoService), new NetTcpBinding(), &quot;HelloIndigo&quot;);  host.Open();Config Base Addresses:  &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress=&quot;http://localhost:8000&quot;/&gt;&lt;/baseAddresses&gt;&lt;/host&gt;Get off UI thread: [ServiceBehavior(UseSynchronizationContext=false)]Get off UI thread: [ServiceBehavior(UseSynchronizationContext=false)]
  5. Windows Service: Subclass ServiceBase, Override OnStart/OnStop, Subclass Installer (VS support)MethodInvoker del = delegate  {  this.listBox1.Items.Add(message);  };  this.Invoke(del);http://msdn.microsoft.com/msdnmag/issues/01/12/NETServ/
  6. Self-Host: using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri(&quot;net.tcp://localhost:9000&quot;))){  host.AddServiceEndpoint( typeof(HelloIndigo.IHelloIndigoService), new NetTcpBinding(), &quot;HelloIndigo&quot;);  host.Open();Config Base Addresses:  &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress=&quot;http://localhost:8000&quot;/&gt;&lt;/baseAddresses&gt;&lt;/host&gt;Self-Host: using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri(&quot;net.tcp://localhost:9000&quot;))){  host.AddServiceEndpoint( typeof(HelloIndigo.IHelloIndigoService), new NetTcpBinding(), &quot;HelloIndigo&quot;);  host.Open();Config Base Addresses:  &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress=&quot;http://localhost:8000&quot;/&gt;&lt;/baseAddresses&gt;&lt;/host&gt;Get off UI thread: [ServiceBehavior(UseSynchronizationContext=false)]Get off UI thread: [ServiceBehavior(UseSynchronizationContext=false)]
  7. Windows Service: Subclass ServiceBase, Override OnStart/OnStop, Subclass Installer (VS support)MethodInvoker del = delegate  {  this.listBox1.Items.Add(message);  };  this.Invoke(del);http://msdn.microsoft.com/msdnmag/issues/01/12/NETServ/
  8. Windows Service: Subclass ServiceBase, Override OnStart/OnStop, Subclass Installer (VS support)MethodInvoker del = delegate  {  this.listBox1.Items.Add(message);  };  this.Invoke(del);http://msdn.microsoft.com/msdnmag/issues/01/12/NETServ/