The first night of WCF learning: Basic knowledge

Source: Internet
Author: User

 

The Windows Communication Foundation (WCF) is a comprehensive Hierarchical Architecture oriented to Service programming. It features cross-platform, secure, trustworthy, and transactional features .. It can be seen as a collection of asmx,. Net remoting, Enterprise Service, WSE, MSMQ, and other technologies.

Note: service-oriented (SO) is an abstraction of a set of principles and is used to create service-oriented applications.Program. The existing experiences of software engineering can be referred to as process-oriented, object-oriented, component-oriented, and service-oriented. Service-oriented is technically unrelated. That is to say, I (client) should not know which technology you are using or where your server is located. The service only needs to expose its own logical operations to the client, telling the client what I can do, how you should deal with me, and everything else is hidden in the service boundary, the public information should be unrelated to the type. The service boundary is like the "Three or eight lines" in the seat when I was a child, which separates the server and the client, but unlike the "Three or eight lines, the service boundary also needs to send messages to both sides.

WCF consists of the following important factors: Service, endpoint, message, hosting, and metadata exchange.

Services are related to addresses, bindings, and contracts. The address defines the service location, the binding defines the service communication mode, and the contract defines the service content. WCF uses an endpoint to represent such a composite relationship. An endpoint is a mixture of addresses, contracts, and bindings. Each endpoint contains three elements, and the host is responsible for making public the endpoint. Logically, the endpoint is equivalent to the service interface.

Each service must expose at least one business endpoint. Each endpoint has only one service contract. All endpoints of a Service contain unique addresses. A single service can publish multiple endpoints. These endpoints can use the same or different bindings to publish identical or different contracts. There is no relationship between different endpoints provided by each service.

An endpoint is a structure used to send and receive messages.

Most methods of WCF are in the system. servicemodel namespace.

A service agreement is a class or interface marked with servicecontractattribute.

Service operations are marked using the operationcontractattribute on methods.

Parameters and return values-each service operation has a return value and a parameter, even if they are void. You can use the local method to pass the object reference from one object to another. However, unlike the local method, service operations do not pass references to the object, they pass only copies of objects. Each type used in a parameter or return value must be serializable (it must be converted to a byte stream and can be converted from a byte stream to an object ).

Message modes of service operations: Request/response, one-way, and duplex.

    1. request/response:

      the client will receive a response related to the request. This is the default mode, which supports input or return. The result of this slave operation is: unless the client calls the operation asynchronously, the client stops processing and knows that the returned message is received, even if the message is null normally.

      the disadvantage is that the client is prone to false positives.

    2. unidirectional:

      the client does not have to wait for the Operation to complete and ignores soap errors. Therefore, this operation can be used to specify one-way message mode. Unless the client sends a large amount of data, the client can perform the Next Step almost immediately.

      set operationcontract (isoneway = true)

    3. duplex:

      the service and client can independently send messages to the other party, regardless of whether one-way message transmission is used or when a request/request is sent. This form is useful for services that must communicate directly with the client or provide an asynchronous experience (Event-like behavior) to any party that exchanges messages.

      to design a duplex protocol, you must design a callback, the callback protocol type is assigned to the callbackcontract attribute of servicecontractattribute set by the tag service.

      to implement duplex mode, you must create a second interface, which contains the method declaration called by the client.

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.