Catalog :

One 、 What is? WCF

Two 、WCF What can be done

3、 ... and 、WCF Model of

Four 、WCF Basic concepts of

5、 ... and 、WCF Fast creation of

1.WCF What is it?

A、WindowsCommunication Foundation(WCF) It is a series of application frameworks developed by Microsoft to support data communication , Can be translated as Windows Communication development platform .

B、 It is .NET Part of the frame , from .NET Framework 3.0 Start introducing , And WPF( Interface graphics framework ) And WF( Workflow framework ) And called the new generation Windows The operating system and WinFX(Windows Vista Managed code programming model for ) Three major application development class libraries .

C、 stay .NETFramework 2.0 And in previous versions , Microsoft has developed WebService、.NET Remoting、Winsock And other communication support , Because the design methods of each communication method are different , And there's overlap between them , For developers , Different choices lead to different programming models , And it has to be relearned , There are a lot of inconveniences for developers in users . meanwhile , Service Oriented Architecture SOA It's also becoming popular in the software industry , So Microsoft revisited these communication methods , And designed a unified program development model , It provides the most basic and flexible support for data communication , This is it. WCF, therefore WCF Integrating the original windows Communicating .net Remoting,WebService,Socket The mechanism of , And there are HTTP and FTP Related technology .

2.WCF What can be done ?

According to Microsoft's official explanation ,WCF( The previous version was called “Indigo”) Is to build and run a service orientation using managed code (Service Oriented) Unified framework for applications .

It enables developers to build a cross platform security 、 A reliable 、 Transactional solutions , And compatible with existing systems .

WCF Microsoft is the integrator of distributed application development , It integrated. .Net All technologies related to distributed system under the platform , Such as Enterprise Sevices(COM+).Net Remoting、Web Service(ASMX)、WSE3.0 and MSMQ Message queue .

Communication (Communiation) Scope theory , It can cross process 、 Cross machine 、 Striding subnet 、 Enterprise network and even  Internet;

In terms of the host program , We can use ASP.NET,EXE,WPF,Windows Forms,NT Service,COM+ As a host (Host).

WCF The protocols that can be supported include TCP,HTTP, Cross process and customization , Safety mode includes SAML, Kerberos,X509, user / password , Various standards and modes such as customization . in other words , stay WCF Within the framework of , Based on Development SOA It's easy to build a distributed system , Microsoft includes all relevant technical elements , Mastered WCF, It's equivalent to mastering percussion SOA The key to the gate .

3.WCF Model :

WCF The architecture is as follows :

WCF The client and server models of are as follows :

4.WCF Basic concepts of :

(1) Address

WCF Every service has a unique address . The address includes service location and transport protocol ( Transmission style ). The service location includes the target machine name 、 Site 、 The Internet 、 port 、 Pipe or queue , And an optional specific path or URI.

The common format of address is :[ Base address ]/[ Optional URI], Such as “net.tcp://localhost:8081/MyService”.

The common format of base address is :[ Transfer protocol ]://[ Machine name or domain name ][: Optional port ], Such as “net.tcp://localhost:8081”.

WCF Support multiple transmission styles :

  • HTTP use http、https Protocol for transmission , Default port number 80.
  • TCP use net.tcp Protocol for transmission , The default address is 808.
  • Peer network( Peer to peer networks ) use net.p2p transmitted , use Windows Peer to peer transmission mechanism .
  • IPC( Internal process communication ) use net.pipe transmitted , Use Windows The named pipeline mechanism of , Can only receive calls from the same machine , And each machine can only open one named pipe .
  • MSMQ use net.msmq transmitted , Use Windows Of MSMQ Mechanism , The queue name must be specified , If it's dealing with private queues , You must specify the queue type .

(2) binding

Binding normalizes the direct combination of communication mode and interaction mode , Combine these communication features reasonably . A binding encapsulates things like transport protocols 、 Message encoding 、 reliability 、 Security 、 A combination of transaction propagation and interoperability options , Make them consistent .

WCF Defines six common bindings :

  • Basic binding from BasicHttpBinding Class provides , take WCF Service disclosure is Web service .
  • TCP binding from NetTcpBinding Class provides , Use TCP Protocol communication , Support multiple features , Including reliability 、 transactional 、 Safety and WCF Optimization of communication between , The disadvantage is that the client has to use WCF.
  • IPC binding from NetNamedPipeBinding Class provides , Using named pipes to transmit communication for the same machine , Supported features and TCP Binding is similar to , Is the best binding for performance and security .
  • Web Service binding from WSHttpBinding Class provides ,WS Binding uses HTTP or HTTPS transmitted , It provides such things as reliability 、 A variety of features, including transactional and security , These characteristics follow WS-* standard , The binding is designed to support WS-* Standard systems interoperate .
  • WS Two way binding from WSDualHttpBinding Class provides , Support two-way communication .
  • MSMQ binding from NetMsmqBinding Class provides , Use MSMQ transmitted .

Common binding transport protocols and coding formats are as follows :

Be careful :TCP、IPC and MSMQ The binary encoder used for binding is WCF Proprietary , Don't try to write custom parsers for it for other platforms .

(3) contract

WCF All of our services are exposed as contracts , Contracts have nothing to do with platforms , It's a standard way to describe service functions .WCF contain 4 Quasi contract :

  • Service contract Describes the service operations that the client can perform .
  • Data contract Defines the data types that interact with the service .
  • Wrong contract Defines the error thrown by the service , And how the service handles and delivers errors to the client .
  • Message contract   Message contracts allow services to interact directly with messages , For customizing proprietary message formats , It also means having your own application context , Because it increases the complexity of the code , So it's not a common usage .

(4) endpoints

The end point is WCF The only way to communicate ,ChannelFactory<T> Essentially, it's creating a service proxy for service invocation through a specified endpoint .

The end point is WCF In the system through System.ServiceModel.Description.ServiceEndpoint Type said , It contains three core attributes —— Address 、 binding 、 contract .

An endpoint is a construct for sending and receiving messages , Endpoints are really interfaces , It contains all the information needed for an object interface .

Each service must expose at least one business endpoint , Each endpoint has and can only have one contract .

All endpoints on the service contain unique addresses , A single service can expose multiple endpoints . These nodes can use the same or different binding , Make public the same or different contracts .

(5) Metadata

The metadata of a service describes the characteristics of a service , External entities need to understand these features in order to communicate with the service .

The metadata of the service includes XML、 Schema document ( Data contracts used to define Services ) and WSDL file ( Methods used to describe services ).

With metadata enabled ,WCF Automatically generate metadata for services by examining services and their endpoints .

(6) Context

WCF Context connects the service host to the public local CLR The type is a combination of the context of the service , Context is the core execution scope of a service instance , The context can be empty , That is, it does not contain any service instances .

(7) host

WCF Service class cannot exist out of thin air , Every WCF The service class must be hosted in a host process .

A single host process can host multiple services , The same service type can also be hosted in multiple host processes , If the service resides in the same process as the client , Is called in-process hosting . The common hosts are as follows :

  • Web Site
  • Windows Forms application
  • Windows service
  • Windows Activate service (WAS)

WCF The host architecture is as follows :

Every .NET Host processes contain multiple application domains , Each application domain contains zero to multiple host instances , Each service host instance is dedicated to a particular service type .

therefore , Create a host instance , In fact, it is to register a service host instance containing all endpoints for the type of host machine corresponding to the base address . Each service host instance has zero or more contexts . A context can be associated with zero or one service instance .

(8) agent

WCF Clients are not allowed to interact directly with services , The client uses a proxy to forward the call to the service . Even if the object is local ,WCF Still using the instantiation of the remote programming model , And use the proxy .

5.WCF Fast creation of :

First step : adopt VS Create a WCF Service application : Solution - name - Location customization

The second step : Click ok , Three files are generated automatically : Service contract interface , Service interface implementation class , The configuration file

The third step : Boarding Services , Click on Service1.svc View it in a browser , You can board the service

Step four : After boarding , We can view the metadata information and call the service to generate the client proxy class

Click the link to see the metadata information of the service as follows :

Step five : We go through svcutil.exe The tool generates client proxy classes and client configuration files

svcutil.exe Is a command line tool , In the path C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin Next , We can run the tool from the command line to generate the client proxy class

1. Input at run cmd Open the command line , Input cd C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

2. Input svcutil.exe /out:f:\TestProxy.cs /config:f:\App.config http://localhost:10998/Service1.svc?wsdl( Be careful : The port number is changed to the port number of the host computer service )

At this point, you will see an error in the client proxy class , The reason is that we don't refer to the assembly that the service requires . We quote System.Runtime.Serialization and System.ServiceModel

Step seven : stay Main() Method of the service :

Step eight : Set up the client (Client) For startup

function , See the following effect :

WCF( One ): First time to know WCF More articles about

  1. WCF And First time to know WCF

    Services are becoming more and more important in programming ,.net from 2.0 Of webservice, To 3.5 After that WCF, Services are becoming more and more powerful . Now let's start with a simple one , Have a look first WCF Service release . Now let's look at the step-by-step release WCF service . ...

  2. WCF Programming Series ( One ) First time to know WCF

    WCF Programming Series ( One ) First time to know WCF   Windows Communication Foundation(WCF) Microsoft's unified programming model for building service-oriented applications .WCF Basic concepts of :  Address : Define the ...

  3. Let's study together WCF First, I'm new to you WCF( Attached source code for comparative study )

    Preface : Last year, due to the need of work, I studied wcf Knowledge about , Early on wcf It's a bit of a mystery why and how to use it , Maybe it's not very clear right now . But through the project to wcf I have a preliminary model in my mind . Today I'm going to start with wc ...

  4. WCF The beginning of the series WCF

    This essay refers to WCF Programming Series ( One ) First time to know WCF, It's just reading notes , To deepen the memory . 1. brief introduction :Windows Communication Foundation(WCF) It's Microsoft's unified programming for building service-oriented applications ...

  5. First time to know WCF It uses the configuration file to deploy WCF Applications

    The beginning of February , Xiaobian is still on the road of project development , Start new knowledge ,EF,WCF,MVC etc. , Today, I'd like to make a brief summary about WCF Basic knowledge of , Before learning , Xiaobian asked himself two questions ,WCF What is it? ?WCF Can be used to do ...

  6. [WCF Programming ]1.WCF Introductory example

    One .WCF What is it? ? Windows Communication Foundation(WCF) It is a series of application frameworks developed by Microsoft to support data communication , Integrating the original windows Communicating .net Remotin ...

  7. WCF Services and WCF The difference between data services

    ask : Hi, I am newbie to wcf programming and a little bit confused between WCF Service and WCF Data  Se ...

  8. Big speed :remoting、WCF(http)、WCF(tcp)、WCF(RESTful)、asp.net core(RESTful)

    Recently, we are considering a service selection ,dotnet It provides many forms of remote services . I'm just thinking about dotnet To dotnet Under the situation of , We can choose remoting.WCF(http).WCF(tcp).WCF(RESTful). ...

  9. Big speed :remoting、WCF(http)、WCF(tcp)、WCF(RESTful)、asp.net core(RESTful) .net core The console program uses dependency injection (Autofac)

    Big speed :remoting.WCF(http).WCF(tcp).WCF(RESTful).asp.net core(RESTful) Recently, we are considering a service selection ,dotnet It provides many forms of remote services . In only ...

Random recommendation

  1. 【 turn 】Dubbo Use examples and compare with Spring Integrated use

    One . Write common interface class between client and server 1. Login interface class public interface LoginService {    public User login(String name, String psw ...

  2. Don't let catalogs Screw you eclipse

    Don't let catalogs Screw you eclipse Finally, the owner walked out of the campus , Set foot on the road of software career . There are many things new people have to learn , There are many things to overcome , These are things other than technology itself , And the fear of the unknown , New contact technology , Like a new framework , Maybe several ...

  3. windows platform eclipse for C++ Development environment construction

    Reference resources : 1 blog.sina.com.cn/s/blog_75f3c1f201014l5c.html 2 MinGW Official installation instructions One . Install and configure MinGW 1 MinGW Official website (www.mingw. ...

  4. Query the current running status -CPU , etc.

    Have a basic understanding of the current operation of the database ) DB_NAME(a.dbid) AS dbname , loginame , spid , cpu , b.text , lastwaittype , w ...

  5. JAVA Basic learning is XMLCDATA District 、XML A processing instruction 、XML Overview of constraints 、JavaBean、XML analysis (8)

    1.CDATA The district is writing XML When you file , Some content may not want to be parsed and executed by the parsing engine , It's treated as original content . In this case , You can put it in CDATA District , about CDATA Content in the area ,XML The parser doesn't handle , It's straight ...

  6. HttpContext.Current.RewritePath Method rewriting URL

    if (!IsPostBack) { // If you ask for ID It's empty , Then rewrite URL by :~/index.aspx?ID=shouji.115sou.com if (Request.QueryString[&quo ...

  7. php linux Deployment related

    http://www.itbulu.com/wdcp-php55.html http://www.wdlinux.cn/wdcp/install.html http://www.yiichina.co ...

  8. C# Print 100 Inner prime number

    bool b = false; ; i < ; i++) { ; j < i; j++) { ) { b = false; break; } else { b = true; } } if ...

  9. Android Images

    Android The rendering is divided into 2D Rendering and 3D There are two kinds of rendering , among 2D The rendering engine is Skia.3D The rendering engine is OpenGL ES. At the moment .Android Support OpenGL ES1.0 and OpenGL ES 2.0 Two standards . ...

  10. intellij idea Package invisibility problem

    Just used intellij idea Soon , There is a problem that the package is not visible . reason :jdk9 The problem of , It's using jdk9 That's the problem . terms of settlement : hold jsk9 Switch to jdk1.8 It can be solved .