[Solution] Step by Step WCF (2) then describe the Endpoint and wcfendpoint
Busy day after day, no matter what other, continue to the WCF first.
An Endpoint includes three elements: Address, binding, and contract. As the largest communication framework in Windows. All communication functions are carried through the endpoints. So the end point will be very important.
This section describes
- SOA
- Address
- Bingding
- Contract
- Behavior
SOA
Service-Oriented Architecture represents the idea of separation of concerns, which has different meanings for different people.
WebService, WCF, and Web Services on other platforms are the technical means to realize the idea of SOA.
SOA still has some basic features that are recognized by everyone.
| Design principles |
Description |
| Service Contract |
Service Description functions and objectives through contract documents |
| Loose coupling |
Minimize dependency |
| Abstraction |
Hide specific implementations of services, only publish contract files |
| Reuse |
A service can be reused by other services. |
| Autonomy |
Services are independent |
| Discoverable |
Service metadata allows you to find and call services. |
| Combination |
A service can be composed of other services. |
While WCF is a completely SOA-based communication framework, and it unifies all the distributed technologies of Microsoft. For example,. Net Remoting WebService MSMQ.
Address
Address refers to System. ServiceModel. EndpointAddress.
The following attributes are available:
The core is URI. It can be used as the unique identifier of an Endpoint.
URI structure: scheme: // ip: point/path, for example, http: // 127.0.0.1: 10000/a/B. svc
Common scheme:
Http/https: stateless, http default port 80, https default port 443
Net. tcp: stable support for duplex communication. Default port 808.
Net. pipe: communication between different processes on the same machine. Although the named pipe itself can be implemented across platforms, it is only used on the same machine in WCF, so the ip address can only be the local machine.
Net. msmq: Message Queue mode.
Base Address:
In addition to the above absolute address method, you can also set it using the "base address + relative address" method.
How to set the base address:
class Program { static void Main(string[] args) { var uris = new []{new Uri("http://localhost:10000/"),new Uri("net.tcp://localhost:10001/")}; using (ServiceHost host = new ServiceHost(typeof(SomeService),uris) { host.AddServiceEndpoint(typeof(ISomeService),new BasicHttpBinding(),"SomeName"); host.open(); Console.Read(); } } }
Uris defines the base address, and SomeName is the name of the relative address. You can access the service by accessing any base address + SomeName of uris. For example, http: // localhost: 10000/SomeName
Note: One transmission protocol can only have one base address.
<system.serviceModel> <services> <service name="SomeService"> <endpoint address="SomeName" binding="basicHttpBinding" contract="ISomeService"></endpoint>
In addition to Uri, Address also includes Identity and Headers (additional information included during transmission)
Port Sharing:
Requirements:
To avoid network attacks as much as possible, only a few ports are exposed. In this case, Port Sharing is of great significance.
Problem:
Generally, a port can only be exclusive to one process.
Implementation:
Http/https: in the form of IIS virtual path.
Net. tcp: Start the shared service and set properties.
Start this service
Set attributes
var bind = new NetTcpBinding();bind.PortSharingEnabled = true;
Binding
For an SOA system, the interaction between systems is in the form of Message. Address is used for addressing. Binding is used to explain all the underlying details of interaction between systems.
Most importantly, Transport and Encode ).
The following table lists the layers of Binding.
Layer |
Options |
Required |
Transactions |
TransactionFlowBindingElement |
No |
Reliability |
ReliableSessionBindingElement |
No |
Security |
SecurityBindingElement |
No |
Encoding |
Text, Binary, MTOM, Custom |
Yes |
Transport |
TCP, Named Pipes, HTTP, HTTPS, MSMQ, Custom |
Yes |
Contract
The main function of Contract is to expose all valid Functionality provided by a WCF Service. So Contract solves What functionalities do the Service provide?
It is worth noting that the Contract interface should be marked with the service mark of WCF when it is linked to the WCF. (ServiceContract, OperationContract, and other features)
For example:
[ServiceContract] interface ICar { [OperationContract] void Run(); }
Behavior
Behavior is also an Endpoint attribute. It is mainly used to define some necessary behavior information of an Endpoint, including the publishing of metadata. (Currently, I only know that metadata is used for publishing ?)
Author: Never, C
Link: http://www.cnblogs.com/neverc/p/4682394.html