WCF review first, basic concepts and application scenarios

Source: Internet
Author: User
Tags msmq

First, WCF describes

WCF is a platform of communication framework based on service-oriented architecture, which has been widely used in distributed framework. Getting started with WCF is simple, and it takes just a few minutes to write a complete WCF program, and WCF is actually a very large concept, and it takes a lot of effort to delve into it.

Second, WCF Advantage 1, the integration of various communication technologies

WCF is the integration of technologies such as Web service,net remoting,enterprise service,wse,msmq

The presentation layer can be based on SOAP XML transport and rest HTTP calls

The transport layer can be based on HTTP HTTPS TCP pipe MSMQ (I personally prefer TCP for performance and flexibility in the case that all can meet the requirements)

2, the use of service-oriented implementation, so that the programming becomes more simple

Software development approach: object-oriented, process-oriented programming-oriented architecture for component development

Service-oriented benefits:

A project, if there are many styles of technology, third-party DLLs or two technologies can not be run under the same system under the situation will be difficult to maintain and coding, but all of these functions are separated into a service project, through a service interface to call, multiple environments to publish, Both to understand the decoupling and improve the cohesion, the code in the rotten eye does not bother.

Iii. Basic concepts of WCF

WCF programs are divided into server and client , the WCF program is hosted into the process through the host , read the configuration and start the service, the client through the proxy class implementation call.

1 Contract:

(1) Service contract: A set of interfaces exposed to the client that needs to be added with the [ServiceContract] feature, the client can invoke the service.

(2) Operation contract: function name plus [OperationContract], the function can only be called in the service.

[ServiceContract]    Public interface IService1     {         [OperationContract]        string GetData (int value);           [OperationContract]         Compositetype Getdatabydata (dataclass DC);            }

  

(3) Data contract: The class required by the client and the server is tagged with the attribute [DataContract] as the data contract, the member property of the class plus the DataMember attribute label shared member

Note: Even if you do not add the attribute DataContract, the default is DataContract, only the data contract can be lazy and not write

[Datacontract]public class dataclass{    [DataMember] public       double Totalprice {get; set;}}

  

(4) Message contract: This is more interesting, online saying a lot, about the application scenario of quite a few

My understanding: First, the message contract and the data contract support the flow, the return stream can be accompanied by other information, the data contract to do just a few more properties of the pendulum.

Message contract focus on the message of the word, the characteristics of the data is consistent, you are "1" I am also "1", but the message is different I can say that "1" can also be said to be "one", the difference lies in diversification.

The message contract assigns the transferred data to the SOAP head or the SOAP body, can order the data in multiple head or body, and can customize some message formats to diversify the transmission format, support the receiving of more devices, and can encrypt the head.

Data contracts all of the data together, and we have no control over what the generated soap looks like.

Note that each contract has its own characteristic parameters, and this does not introduce

2 Address

Each service can have multiple transport protocols, with only one call address per transport protocol

Like what:

Http://192.168.1:800/Service1

Net.tcp://localhost:8080/service1

3 agents

Project Right-click Add Service, enter the service address can easily generate proxy service, you can also use the tool to generate agents or handwriting.

4. WCF configuration file

Divided into three blocks of bindings, services and behaviors

(1) Services:

There can be multiple services, one service representing one,

A service can be multiple endpoint, endpoint role is mainly address, contract, binding

Endpoint For example, a binding HTTP address is a HTTP://192.168.1.1:80/SERVICE1 service contract is IService

(2) Behaviors:

A service can have a behavior that contracts services, such as whether a service error outputs a verbose error, whether metadata is displayed, and so on (metadata is the WCF browse page)

(3) Bindinds:

              A service can have a bingding to configure the transport protocol and the settings of the transport parameters for the service.

<?xml version= "1.0" encoding= "Utf-8"?><configuration> <system.web> <compilation debug= "true" targetframework= "4.0"/> </system.web> <system.serviceModel> <bindings> &LT;NETTCPBINDING&G        T <binding name= "Tcpbind" portsharingenabled= "true" transfermode= "Buffered" > <readerquotas maxdepth= "Maxstringcontentlength=" "8192" maxarraylength= "16384" maxbytesperread= "4096" maxnametablecharcount= "16384 "/> <security mode=" None "> </security> </binding> &LT;/NETTCPBINDING&G    T </bindings> <services> <service behaviorconfiguration= "myservicetypebehaviors" Name= "Wcfservice.say  Service "> <endpoint binding=" nettcpbinding "bindingconfiguration=" Tcpbind "contract=" Wcfservice.isayservice "    /> <endpoint address= "Mex" binding= "mextcpbinding" contract= "IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name= "Myservicetypebehaviors" >          <!--publish metadata, delete--<servicemetadata httpgetenabled= "true"/> <!--output error before publishing, delete--before publishing    <servicedebug includeexceptiondetailinfaults= "true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel></configuration>

  

=============================================================== purely Personal understanding ========================================== ===============

WCF review first, basic concepts and application scenarios

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.