WCF學習系列一【WCF Interview Questions-Part 1 翻譯系列】


WCF Interview Questions – Part 1

This WCF Tutorial is a collection of most frequently asked interview questions about Windows Communication Foundation (WCF) covering the beginner to professional level.

這個WCF教程,是WCF常見問題的集合,它主要面向WCF初學者的專業水平。

Following are the links to other posts in this WCF Questions Series:

下面是WCF系列問答教程中的一部分:

  1. WCF Service Interview Questions – Part 1
  2. WCF Service Interview Questions – Part 2
  3. WCF Service Interview Questions – Part 3
  4. WCF Service Interview Questions – Part 4

Note: Please look into the Top 10 WCF Interview Questions also.

注意:同時請關注前10個WCF問題: Top 10 WCF Interview Questions

 

frequently asked questions[FAQ]:常見問答

 

MCSD Exam: 70-487

  1. What is WCF?【什么是WCF】
  2. Why to use WCF? or What are the advantages of using WCF?【為什么要使用WCF,或者WCF有哪些優點】
  3. What are the core components of WCF Service?【WCF服務,核心的組件是?】
  4. What are the new features introduced in WCF 4.5?【WCF 4.5版本中介紹了哪些新特性】
  5. What is the difference between WCF and ASMX Web services?【WCF和ASMX Web服務之間的不同是什么?】
  6. What are the Endpoints in WCF? or Explain ABCs of endpoint?【WCF的節點是什么?或者解釋一兩點出來】
  7. What is the difference between Service EndPoint and Client Endpoint?【服務節點和客戶端節點有什么不同?】
  8. What is a WCF Binding? How many different types of bindings available in WCF?【什么是WCF綁定,WCF中允許哪些類型的綁定?】
  9. What is WebHttpBinding in WCF?【WCF中WebHttpBinding是什么?】
  10. Can we have multiple endpoints for different binding types in order to serve different types of clients?【為了服務不同類型的客戶端,我們可以有多個不同類型的綁定節點么?】
  11. What are the hosting options for WCF Services? Explain.【WCF的托管選項是什么?請解釋。】

What is WCF?【什么是WCF】

Microsoft refers WCF as a programming platform that is used to build Service-Oriented applications. Windows Communication Foundation is basically a unified programming model for developing, configuring and deploying distributed services.  Microsoft has unified all its existing distributed application technologies (e.g. MS Enterprise Services, ASMX web services, MSMQ, .NET Remoting etc) at one platform i.e. WCF. Code name for WCF was Indigo. Below diagram clearly explains it:

      微軟把WCF作為,用於構建面向服務的應用程序的編程平台。Windows Communication Foundation基本上是一個統一的編程模型開發、配置和部署分布式服務。微軟統一了現有的分布式應用程序【例如MS Enterprise Services, ASMX web services, MSMQ, .NET Remoting 等等】集中在一個平台上,也就是WCF。為WCF取名為Indigo,下面的圖表清晰的解釋了:

Windows Communication Foundation

Why to use WCF? or What are the advantages of using WCF?

為什么使用WCF,它的優點是?

Advantages of WCF 支持面向服務的架構;簡單、可靠、安全;便於協同操作;一個服務可以服務多個客戶端;可擴展。

 

  • Service Orientation is one of the key advantages of WCF. We can easily build service-oriented applications using WCF.【面向服務是WCF關鍵的優點。我們使用WCF可以很簡單的構建面向服務的應用程序。】
  • If compared with ASMX web services, WCF service provides reliability and security with simplicity.【和ASMX Web 服務相比,WCF服務提供了可靠性,安全性,簡單性】
  • As oppose to .NET Remoting, WCF services are interoperable.【相對.NET Remoting,WCF服務是可以互操作的。】
  • Different clients can interact with same service using different communication mechanism. This is achieved by using service endpoints. A single WCF service can have multiple endpoints. So, developer will write code for service once and just by changing configuration (defining another service endpoint), it will be available for other clients as well.【不同的客戶端,和同一個服務的交互,可以使用不同的通信機制。這可以通過使用服務節點實現。一個簡單的WCF服務可以有多個節點。因此,開發者只需要寫一次服務端的代碼,然后僅僅通過改變配置(定義其他的服務節點),那么這個服務,將會同時可以被其他的客互端使用。】
  • Extensibility is another key advantage of WCF.  We can easily customize a service behavior if required.【可擴展是WCF另外一個關鍵性的優點,如果有需要的話,我們可以很簡單的定制服務的行為。】

What are the core components of WCF Service?【WCF的關鍵組件是什么】

A WCF service has at least following core components.【一個WCF服務,至少需要下面的關鍵組件】
  • Service Class:  A service class implementing in any CLR-based language and expose at least one method.
        服務類:一個服務類是基於任何CLR基礎的語言實現的,並且至少暴露一個方法。
  • Hosting Environment: a managed process for running service.
        托管環境:為運行服務管理進程。
  • Endpoint: a client uses it to communicate with service.
       節點:客戶端使用節點和服務端通信。
  • Core WCF Components

What are the new features introduced in WCF 4.5?【WCF 4.5版本中介紹了哪些新特性】

Windows Communication Foundation v4.5 was released with a number of cool features. Here we simply list down most important features but you can find thorough detail about each feature with helping code snippet in 7 parts series of new features in WCF 4.5. These important features are:

Windows Communication Foundation v4.5發布了一些很酷的特點。這里我們僅僅列出最重要的特點,但是你可以從這篇文章中parts series of new features in WCF 4.5.找到每個特性的深入細節的代碼片段。這些重要的特性是:

  • Simplified Configuration files【簡化的配置文件】
  • ToolTip and Intellisense support【工具提示和智能感知的支持】
  • Task-based asynchronous Programming Model【基於任務的異步編程模型】
  • BasicHttpsBinding support【BasicHttpsBinding支持】
  • Single WSDL Document【單個的WSDL文件】
  • WCF Configuration Validation【WCF配置驗證】
  • ASP.NET Compatibility Mode changed【ASP.NET兼容模型改變】
  • Contract First Development【Contract First開發】
  • Multiple Authentication Types【多個身份驗證類型】
  • XmlDictionaryReaderQuotas default value changed【XmlDictionaryReaderQuotas默認值改變】
  • UDP Transport Support【支持UDP傳輸】
  • and many more…【更多....】

For more on key WCF 4.5 features, please follow here.【想要了解更多WCF 4.5的特性,請看這:  follow here

What is the difference between WCF and ASMX Web services?【WCF和ASMX Web服務之間的不同是什么?】

The basic difference is that ASMX web service is designed to send and receive messages using SOAP over HTTP only. While WCF service can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, Named Pipes etc).ASMX Web Services Vs WCFYou can find detailed discussion on WCF Vs ASMX Web services here.

基本區別是,ASMX web服務是使用HTTP上的SOAP,僅僅用於發送和接收消息。而WCF可以在任何傳輸協議(HTTP, TCP/IP, MSMQ, Named Pipes etc)上,使用任何格式(默認是SOAP)交換信息。在這兒,WCF Vs ASMX Web services ,你可以找到更多關於WCF和ASMX Web服務的討論。

What are the Endpoints in WCF? or Explain ABCs of endpoint?【WCF的節點是什么?或者解釋一兩點出來】

For WCF services to be consumed, it’s necessary that it must be exposed; Clients need information about service to communicate with it. This is where service endpoints play their role.

隨着WCF討論的繼續,很有必要弄清楚什么是WCF;客戶端需要服務的信息來通信,這就是服務節點所扮演的角色。
A service endpoint has three basic elements or also called ABCs of an endpoint i.e. Address, Binding and Contract.

一個服務節點有三個基本的元素,或者稱作ABCs節點,那就是Address, Binding and Contract.

ABC's of WCF EndPoint

  • AddressIt defines “WHERE”. Address is the URL that identifies the location of the service.
    Address:它定義了“哪里”,Address是一個URL,它定義了服務的位置。
  • BindingIt defines “HOW”. Binding defines how the service can be accessed.
        Binding:它定義了“怎樣”,Binding定義了如何訪問服務。
  • ContractIt defines “WHAT”. Contract identifies what is exposed by the service.
        Contract:它定義了“什么”。Contract確定了,服務公開了什么。
  • WCF Endpoint

What is the difference between Service EndPoint and Client Endpoint?【服務端節點和客戶端節點有什么不同?】

As we already understood the concept of an Endpoint and it’s ABC (Address, Binding, Contract). Both Service and Client Endpoint has same ABC but we think in different perspective while working with them. We can differentiate between Service and Client Endpoint with respect to Address, Binding and Contract as:

我們已經理解了節點的概念,知道了它有ABCs-->【Address, Binding, Contract】,服務端節點和客戶端節點都同樣有ABCs,但是我們可以從不同的角度來思考、使用它們。我們可以根據 Address, Binding and Contract,從以下幾個方面來區分服務端節點和客戶端節點:

 

Service Endpoint【服務端節點】

Client Endpoint【客戶端節點】

WHERE: URL of hosted service.【托管服務的URL】 WHERE: where to connect with hosted service.【連接托管服務】
WHAT: bindings being used.【使用綁定】 WHAT: binding supported by service.【服務支持的綁定】
CONTRACT: Service Contract i.e. interfaces【服務契約,例如接口。】 CONTRACT: what to pass and expect while communicating with service.【和服務通信的時候傳遞,期望值

 

What is a WCF Binding? How many different types of bindings available in WCF?【什么是WCF綁定,WCF中允許哪些類型的綁定?】

Bindings in WCF actually defines that how to communicate with the service. Binding specifies that what communication protocol as well as encoding method will be used. Optionally, binding can specify other important factors like transactions, reliable sessions and security.
Another WCF Tutorial gives more detailed understanding of Binding concept in WCF.

There are different built-in bindings available in WCF, each designed to fulfill some specific need.

     WCF中的Bindings,實際上定義了如何與服務進行通信.綁定指定了通信的協議還有使用的編碼的方法。可選地,Binding可以指定其他重要因素,如事務,可靠的Sessions和安全性。另外的一片文章:WCF Tutorial給出了更多WCF中Binding概念的細節。

下面這些不同的內置綁定在WCF中,都是可行的,每一個都是實現一些特定的需要。

  • basicHttpBinding
  • wsHttpBinding
  • netNamedPipeBinding
  • netTcpBinding
  • netPeerTcpBinding
  • netmsmqBindingWCF Bindings

For details on different binding types, please follow the link to WCF bindings.

想要了解很多不同的綁定類型,請看這個鏈接的文章:WCF bindings.

What is a WebHttpBinding in WCF?【WCF中WebHttpBinding是什么?】

WebHttpBinding is the one that is used for creating WCF RESTful services. In Windows Communication Foundation v3.5, Microsoft introduces support for building RESTful services. REST (Representational State Transfer) is an architectural design that uses HTTP the way it should be used.

      WebHttpBinding 被用來創建:WCF RESTful services,在WCF 3.5中,微軟就支持創建RESTful 服務。REST (Representational State Transfer)是一個使用HTTP的設計結構。

Instead of using HTTP just as a transport (in case of SOAP-based WCF Services), RESTful WCF services uses full features of HTTP (for all CRUD Operations including Create, Retrieve, Update and Delete).

You can find WebHttpBinding in action as in below configuration screenshot.

      代替使用HTTP作為運輸(在基於SOAP的WCF下), RESTful WCF services uses full features of HTTP(可以做所有的CRUD操作,包括增刪查改。)你可以在下面的配置中找到WebHttpBinding 。

WebHttpBinding

Can we have multiple endpoints for different binding types in order to serve different types of clients?【為了服務不同類型的客戶端,我們可以有多個不同類型的綁定節點么?】

Yes, we can have multiple endpoints for different binding types. For example, an endpoint with wsHttpBinding and another one with netTcpBinging.
是的,對於不用的綁定類型,我們可以有多個節點。例如一個節點上帶有wsHttpBinding ,另外一個節點上有netTcpBinging。

What are the hosting options for WCF Services? Explain.【WCF的托管選項是什么?請解釋。】

For a service to host, we need at least a managed process, a ServiceHost instance and an Endpoint configured. Possible approaches for hosting a service are:

對於一個服務托管,我們至少需要一個管理進程,ServiceHost實例和一個節點配置。,下面的這些都是可以為服務托管的方法:

  • Hosting in a Managed Application/ Self Hosting【托管在一個托管的應用程序中/自我托管】
  • Hosting on Web Server【托管在Web服務器上】
    • IIS 6.0 (ASP.NET Application supports only HTTP)【IIS 6.0 ASP.NET應用程序僅僅支持HTTP】
    • Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP,【窗體進程激活服務(WAS),例如IIS 7.0 支持 HTTP,TCP,NamedPipes, MSMQ】
      NamedPipes, MSMQ.

Next WCF Tutorial on Interview Questions and Answers in this series is about Proxy and Channel Factory, Concurrency and Throttling in WCF.

下一篇WCF系列教程中,將會說道代理,渠道工廠,WCF的並發性和節流。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM