Navigation:(1) The journey to WCF
(2) Solution to the Problem of WCF port number
(3) applications cannot be found when WCF adds service references.
(4) source of service reference in WCF
Order:
After reading the WPF for several days, the header is not small, but now it is bigger. Change your mind to learn about WCF today (both technologies will be used in future work ).
I personally think that WCF is more difficult to understand than WPF, but it also varies from person to person. That sentence is always the same-it's not difficult to meet, but it's not difficult. I think WCF is more focused on some networks, although it is still necessaryCodeBut I understand more things. I will summarize the gains of today through my one-day study. I also hope to help other children's shoes who have just begun learning with limited personal abilities, I hope the prawns will criticize and correct it.
Overview:
WCF (Windows Communication FoundationIs a group of data communication applications developed by Microsoft.ProgramThe development interface provides the most basic and flexible support for data communication. Before that, Microsoft developed web service and ,. net remoting and basic Winsock communication support. Because different communication methods have different designs and overlap with each other, for developers, different options have different programming models and must be re-learned, making it inconvenient for developers to use them. Therefore, WCF was born.
The communication mode between the two parties is set by the contract (also translated: contract. The communication method followed by both parties is set by Protocol binding. The security during communication is determined by the security level agreed by both parties.
The basic concept of WCF is to define a contract between the two parties,The contract must be presented as an interface, and the actual service code must be derived and implemented by these contract interfaces..
There are four types of contracts:
Data contract)The data format for communication between the two parties.
Service Contract)To define the service.
Operation contract)Specifies the method provided by the Service.
Message contract)To rewrite the message content specification during communication.
Sample Code:
1 Using System. servicemodel;
2
3 Namespace Wcfdemo. Contracts
4 {
5 /// <Summary>
6 /// Define service contract and reference the system. servicemodel assembly.
7 /// (Most of the implementations of the WCF framework and API definitions are in this Assembly)
8 /// </Summary>
9 [Servicecontract (name = " Calculatorservice " , Namespace = " Http://www.artech.com " )]
10 Public Interface Icalculator
11 {
12 [Operationcontract]
13 Double Add ( Double X, Double Y );
14
15 [Operationcontract]
16 Double Subtract ( Double X, Double Y );
17
18 [Operationcontract]
19 Double Multiply ( Double X, Double Y );
20
21 [Operationcontract]
22 Double Divide ( Double X,Double Y );
23
24 }
25 }
Since WCF supports HTTP, TCP, named pipe, MSMQ, peer-to-peer TCP and other protocols, HTTP is divided into basic HTTP support (basichttpbinding) and WS-HTTP support (wshttpbinding ), TCP also supports communication methods such as nettcpbinding and netpeertcpbinding. Therefore, both parties must unify the communication protocol and ensure consistency in encoding and format.
An example of setting Communication Protocol binding is as follows:
1 <? XML version = " 1.0 " Encoding =" UTF-8 " ?>
2 <Configuration>
3 <System. servicemodel>
4 <Behaviors>
5 <Servicebehaviors>
6 <Behavior name = " Metadatabehavior " >
7 <Servicemetadata httpgetenabled = " True " Httpgeturl = " Http: // 127.0.0.1: 9999/calculatorservice/metadata " />
8 </Behavior>
9 </Servicebehaviors>
10 </Behaviors>
11 <Services>
12 <Service behaviorconfiguration = " Metadatabehavior " Name = " Wcfdemo. Services. calculatorservice " >
13 <Endpoint address = " Http: // 127.0.0.1: 9999/calculatorservice " Binding = " Wshttpbinding " Contract = " Wcfdemo. Contracts. icalculator " > </Endpoint>
14 </Service>
15 </Services>
16 </System. servicemodel>
17 </Configuration>
I am not very familiar with this part, but I just found some instructions: the WCF implementation already supports the transport-level security (transport-level security) and message-level security (Message-level security).
Transport Layer Security: encryption during data transmission, such as SSL. Message-level security: encryption during data processing, such as digital signatures, hashes, or key encryption.
The birth of this article is also dependent on the blog of artech, my WCF travel series handouts. Today, I only read my blog and will study it later. My gains will surely be shared with you! Happy learning!