WCF

1. WCF VS Web Service

Difference between WCF and Web service

Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them.

FeaturesWeb ServiceWCF
HostingIt can be hosted in IISIt can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming[WebService] attribute has to be added to the class[ServiceContract] attribute has to be added to the class
Model[WebMethod] attribute represents the method exposed to client[OperationContract] attribute represents the method exposed to client
OperationOne-way, Request- Response are the different operations supported in web serviceOne-Way, Request-Response, Duplex are different type of operations supported in WCF
XMLSystem.Xml.serialization name space is used for serializationSystem.Runtime.Serialization namespace is used for serialization
EncodingXML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, CustomXML 1.0, MTOM, Binary, Custom
TransportsCan be accessed through HTTP, TCP, CustomCan be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
ProtocolsSecuritySecurity, Reliable messaging, Transactions

 

 2. Bindings 和 Behavior

BindingDescription
BasicHttpBindingBasic Web service communication. No security by default
WSHttpBindingWeb services with WS-* support. Supports transactions
WSDualHttpBindingWeb services with duplex contract and transaction support
WSFederationHttpBindingWeb services with federated security. Supports transactions
MsmqIntegrationBindingCommunication directly with MSMQ applications. Supports transactions
NetMsmqBindingCommunication between WCF applications by using queuing. Supports transactions
NetNamedPipeBindingCommunication between WCF applications on same computer. Supports duplex contracts and transactions
NetPeerTcpBindingCommunication between computers across peer-to-peer services. Supports duplex contracts
NetTcpBindingCommunication between WCF applications across computers. Supports duplex contracts and transactions

 

Binding 是和behavior相关,是How的操作;Simple definition for Binding describes how the client will communicate with service。

 

3. EndPoint

 

 

4. Tips

  • Always create the service with Interface->Implementation format, mention the contract in Interface.
  • Define the service in Class library and refer the class library in Host project. Don’t use service class in host project.
  • Change the instance mode to per call as default.
  • Always catch exception using try/catch block and throw exception using FaultException < T >.
  • Logging and Include exception should be enable while compiling the project in debug mode. While in production deployment disable the logging and Include exception details.

 

5. Contact 和 Service Host

  1. Mainly there are four types of contracts available in WCF: 

    a. Service Contract

    b. Data Contract

    c. Message Contract

    d. Fault Contract

  2. Services can be hosted or executed, so that it will be available to everyone accessing from the client. WCF service can be hosted by following mechanism

    • IIS

      Internet information Service provides number of advantages if a Service uses Http as protocol. It does not require Host code to activate the service, it automatically activates service code.

    • Windows Activation Service

      (WAS) is the new process activation mechanism that ships with IIS 7.0. In addition to HTTP based communication, WCF can also use WAS to provide message-based activation over other protocols, such as TCP and named pipes.

    • Self-Hosting

      WCF service can be self hosted as console application, Win Forms or WPF application with graphical UI.

    • Windows Service

      WCF can also be hosted as a Windows Service, so that it is under control of the Service Control Manager (SCM).

 

 

6. Message and Channel

  1. WCF Message --  is the unit of data exchange between client and service. It consists of several parts, including a body and headers.

  2. WCF Runtime -- WCF runtime is the set of object responsible for sending and receiving message. For example formatting the message, applying security and transmitting and receiving message using various protocol.

  3. Channels -- Channels are the core abstraction for sending message to and receiving message from an Endpoint. 大致分为以下两种:

    a. Transport Channels -- Handles sending and receiving message from network. Protocols like HTTP, TCP name pipes and MSMQ.

    b. Protocol Channels -- Implements SOAP based protocol by processing and possibly modifying message. e.g. WS-Security and WS-Reliability.

 

7. WCF Client

  1. A client application is a managed application that uses a WCF client to communicate with another application.

 

8. WCF Architecture

  

 

9. 

 

 

http://www.wcftutorial.net/Contracts-and-Service-Host.aspx

转载于:https://www.cnblogs.com/qijiage/p/3376560.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值