Learn from scratch WCF 3 (Configuration Service)

Source: Internet
Author: User
Tags website hosting

Configuration Service Overview

After the design and the four-line service agreement, you can configure the service. You can define and customize how to publish services to the client, including specifying the service address, the transmission and message encoding that the Service uses to send and receive messages, and the security type required by the Service.

Configure the service type

-- Use the configuration file to configure

-- InCodeForce configuration

In fact, writing a configuration is a WCF application.ProgramThe main part of programming.

Configure the WCF Service using the configuration file

-- By using the configuration file to configure the Windows Communication Foundation (WCF) service, you can provide flexibility to provide endpoints and service behavior data during deployment.

-- You can use the. NET Framework Configuration Technology to configure the WCF Service. Generally, XML elements are added to the web. config file of the intrnet Information Service (IIS) website hosting the WCF Service. With these elements, you can change detailed information, such as the endpoint address (the actual address used to communicate with the Service), on one computer ). In addition, WCF includes several system elements that can be used to quickly select the most basic functions of a service.

-- Using system. configuration of. NET Framework in WCF

1. Use IIS to host services-use the web. config file

2. Use any other host environment-use the app. config file to specify the settings.

Service Element

Each Service has the following attributes:

-- Name: Specifies the implementation type of the listener agreement. This is a fully qualified name (namespace and type name ).

-- Behaviorconfiguration. specifies the name of a behabior element found in the behabiors element, and specifies the behavior control operation, such as whether the service allows simulation.

Endpoint Element

Each endpoint requires the addresses, bindings, and protocols represented by the following attributes:

-- Address. specifies the Uniform Resource Identifier (URI) of the service. It can be an absolute address or an address relative to the base address of the service. If it is set to an empty string, it indicates that the endpoint is available on the specified base address when the servicehost of the service is created.

-- Binding. generally, you can specify a binding provided by a system similar to wshttpbinding, but you can also specify a user-defined binding. The specified binding determines the transport protocol type, security, and encoding used, and whether reliable sessions, transactions, or streams are supported or enabled.

-- Bindingconfiguration. If you must modify the default binding value, you can configure the binding element in the bindings element to perform this operation. The Secondary attribute should be assigned the same value as the name attribute of the binding element used to change the default value.

-- Contract. specifies the interface for defining the protocol. This interface is implemented in the Common Language Runtime Library (CLR) type specified by the name attribute of the service element.

Configure binding

Binding is an object used to specify the communication details required to connect to the Windows Communication Foundation (WCF) service endpoint. You must specify the binding correctly for each endpoint in the WCF Service.

At least the transmission (such as HTTP or TCP) to be used must be specified for binding ). You can also bind other features, such as security and transaction support.

The binding information may be very basic or complex. The most basic binding only specifies the Transport Protocol (such as HTTP) that must be used to connect to the endpoint. In general, the binding includes information about how to connect to the endpoint.

-- Protocol

Determine the security mechanism to be used, reliable message passing function or transaction context stream settings.

-- Encoding

Determine the message encoding (for example, text or binary ).

-- Transmission

Determine the basic transmission protocol (for example, TCP or HTTP) to use ).

The binding information may be complex, and some settings may be incompatible with other settings. Therefore, WCF contains the binding provided by a group of systems. These bindings are designed to meet the requirements of most applications. The following classes represent some binding examples provided by the system:

-- Basichttpbinding: an HTTP Protocol binding, applicable to Web services that connect to a composite WS-1 that neither can configure file specifications (for example, services based on ASP. NET web services ).

-- Wshttpbinding: an interoperable binding that is suitable for connecting to the endpoints of the composite WS _ * protocol.

-- Netnamepipebinding: use. net. Framework to connect to other WCF endpoints on the same computer.

-- Netmsmqbinding: uses the. NET Framework to create a queue message connection with other WCF endpoints.

Use your own binding

-- If the binding provided by the system does not have the correct combination of functions required by the service application, you can create your own binding. There are two ways to achieve this.

-- The Warrior custombinding object can be used to create a new binding from a pre-existing binding element.

-- You can also create user-defined bindings by deriving from binding.

Use binding

-- Two basic steps are required for binding:

-- Select and define the binding. The simplest way is to select one of the systems included in the WCF and use it through the default settings of the binding ..

-- Create an end point that uses the selected or defined binding.

Services bindings behaviors client, four nodes under the system. servicemodel Node

Let's take a look at

Next, let's take a look at

Let's take a look at

Finally, let's take a look at

A service node can have one or more service nodes. Let's take a look at

 

 

Finally, load all the configuration files

<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <! -- <System. servicemodel> section --> <system. servicemodel> <! -- The services element contains the Configuration Requirements for all services resident in the Application --> <services> <! -- Configuration Attribute description for each service: Name-specifies the service that the service configuration is for. It is a fully qualified name (namespace) of a service class that implements certain contract. type name), after servicehost loads a service, find the configuration behaviorconfiguration of <service> that matches the name attribute with the service in the <services> configuration in the configuration file-specify the name of <behavior> under <servicebehaviors>, this specific <behavior> defines some behaviors for this service, such as whether the service allows identity simulation --> <service name = "namespace. type name "behaviorconfiguration =" behavior name "> <! -- Each service can have multiple endpoints. The <endpoint> element below configures the attribute descriptions for each endpoint separately: Address-specifies the external URI of this endpoint, which can be an absolute address, it can also be a relative address relative to baseaddress. If this attribute is blank, the endpoint address is baseaddress binding-specify the binding used by this endpoint. This banding can be one of the nine predefined bindings in the system, for example, basichttpbinding, it can also be a custom mbmbinding. Binding determines the communication type, security, encoding, session-based, transaction-based, etc. Contract-specifies the fully qualified name (namespace) of the contract corresponding to this endpoint. type name), this contract should be implemented by the service specified by the service element name bindingconfiguration-specify a binding configuration name, the name of the <binding> similar to the <bindings> name below matches the name of the name-endpoint. An optional attribute. Each contract can have multiple endpoints, however, multiple endpoint names corresponding to each contract must be unique --> <endpoint address = "Uri" binding = "basichttpbinding" Contract = "contract fully qualified name" bindingconfiguration = "binding Name "name =" "> <! -- A set of custom XML elements, generally used as the header content of soap --> 

 

 

 

Configuration endpoint

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.