This article is targeted to beginners in WCF. This is a totally theoretical article. It will explain:
- All the theoretical concepts of an EndPoint in WCF.
- Addresses in WCF
- Binding and where, which binding should be used.
- Contracts.
ABCs of Endpoints in WCF
The three elements of an endpoint starts with letters that make a mnemonic phrase.
"ABCs of Endpoints"
Address of an Endpoint(A)
The three elements of an endpoint starts with letters that make a mnemonic phrase.
"ABCs of Endpoints"
Address of an Endpoint(A)
- A address specifes where the service is residing.
- This is a Uniform Resource Locator (URL).
- The address URL identifies the location of the service.
- The address should folllow the "Web Service Addressing" (WS-Addressing) standard.
The address depends on whether it is hosted in IIS or a managed application or WAS. This also depends on the binding being used.
The following are example of various types of addresses:
Binding of an Endpoint (B)
The Binding is how the service is to be used. The Binding specifies:
The following are example of various types of addresses:
Binding of an Endpoint (B)
The Binding is how the service is to be used. The Binding specifies:
- Which protocol to use.
- Which encoding to use.
- What type of security requeiremnets are to be used, like SSL or SOAP message security.
System provided Bindings
The system-provided Bindings are basicHttpBinding, wsHttpBinding, wsDualHttpBinding, webHttpBinding, wsFederationHttpBinding, netTCPBinding, netNamedPipeBinding, netMSMQBinding, netPeerTCPBinding, msmqIntegrationBinding, basicHttpContextBinding, netTCPContextBinding and wsHttpContextBinding.
The following describes basicHttpBinding:
The following describes basicHttpBinding:
- This is interoperable binding.
- This is commonly used as a replacement for earler web services based on ASMX.
- It supports HTTP & HTTPS protocols.
- It supports MTOM encoding.
- It supports text encoding.
The following describes wsHttpBinding:
- This is a secure binding.
- This is interoperable binding.
- This uses SOAP over HTTP.
- This supports reliability over internet.
- This supports transaction over internet.
- This supports security over internet.
- This supports HTTP/HTTPS proptcol
- This supports text and MTOM encoding.
- This is default binding provided by WCF.
The following describes wsDualHttpBinding:
- This supports all the features of wsHttpBinding.
- This is mainly used for DUPLEX SERVICE CONTRACTS.
- This supports bidirectional communication.
The following describes webHttpBinding:
- This is a secure binding.
- This is a interoperable binding.
- It supports Http/Https protocol.
- It does not use SOAP message format.
The following describes wsFederationHttpBinding:
- This is a secure Binding.
- This is interoperable binding.
- This supports federated security
- This supports Https/Https protocols.
- This uses text/MTOM encoding.
The following describes netTCPBinding:
- This is a secure Binding.
- This could only be used if the client is also a WCF machine.
- This is used to send Binary encoded SOAP messages from one WCF computer to another.
- This uses Transimission Control Protocol (TCP).
- This supports reliability.
- This supports transaction.
- This supports security.
The following describes netNamedPipeBinding:
- This is a secure Binding.
- This could be used over a single WCF computer.
- This sends Binary encoded SOAP message over named pipes.
The following describes netMSMQBinding:
- This is a queued Binding.
- This uses Binary encoded SOAP message.
- This sends message over MSMQ.
- Here the communication should occur between two computers.
The following describes netPeerTCPBinding:
- This is a secure Binding.
- This uses TCP over peer to peer.
- The Communication should occur between two or more computers.
The following describes msmqIntegrationBinding:
basicHttpContextBinding
This Binding is the same as basicHttpBinding except with more attributes, as in the following:
basicHttpContextBinding
This Binding is the same as basicHttpBinding except with more attributes, as in the following:
- It supports HTTP cookies
- It eanbles SOAP haeders to exchange context.
- This binding is mainly used for Durable services.
netTCPContextBinding
This Binding is the same as netTCPBinding except with more attributes, as in the following
This Binding is the same as netTCPBinding except with more attributes, as in the following
- It eanble SOAP haeders to excahnge context.
- This binding is mainly used for Durable services.
wsHttpContextBinding
This Binding is the same as wsHttpBinding with more attributes, as in the following:
This Binding is the same as wsHttpBinding with more attributes, as in the following:
- It eanble SOAP haeders to excahnge context.
- This binding is mainly used for Durable services.
Example :
<system.serviceModel>
<services>
<service name="WcfService2.Service1"behaviorConfiguration="WcfService2.Service1Behavior"> <!-- Service Endpoints -->
<system.serviceModel>
<services>
<service name="WcfService2.Service1"behaviorConfiguration="WcfService2.Service1Behavior"> <!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1"> <!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/> </identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"contract="IMetadataExchange"/> </service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService2.Service1Behavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/> </behavior>
</serviceBehaviors>
</behaviors> </system.serviceModel>
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/> </identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"contract="IMetadataExchange"/> </service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService2.Service1Behavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/> </behavior>
</serviceBehaviors>
</behaviors> </system.serviceModel>
Contract of and EndPoint (C)
- The contract should be an Interface
- The contract could be a class also but the better approach is interface.
- In the config file this is preceded by prpject name space name
<endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService
OR
EndPoint
WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world.
All the WCF communications are take place through end point. End point consists of three components.
Address
Basically URL, specifies where this WCF service is hosted .Client will use this url to connect to the service. e.g
http://localhost:8090/MyService/SimpleCalculator.svcBinding
Binding will describes how client will communicate with service. There are different protocols available for the WCF to communicate to the Client. You can mention the protocol type based on your requirements.
A binding has several characteristics, including the following:
- Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols.
- Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K).
- Protocol(Optional) - Defines information to be used in the binding such as Security, transaction or reliable messaging capability
The following table gives some list of protocols supported by WCF binding.
Binding | Description |
---|---|
BasicHttpBinding | Basic Web service communication. No security by default |
WSHttpBinding | Web services with WS-* support. Supports transactions |
WSDualHttpBinding | Web services with duplex contract and transaction support |
WSFederationHttpBinding | Web services with federated security. Supports transactions |
MsmqIntegrationBinding | Communication directly with MSMQ applications. Supports transactions |
NetMsmqBinding | Communication between WCF applications by using queuing. Supports transactions |
NetNamedPipeBinding | Communication between WCF applications on same computer. Supports duplex contracts and transactions |
NetPeerTcpBinding | Communication between computers across peer-to-peer services. Supports duplex contracts |
NetTcpBinding | Communication between WCF applications across computers. Supports duplex contracts and transactions |
Contract
Collection of operation that specifies what the endpoint will communicate with outside world. Usually name of the Interface will be mentioned in the Contract, so the client application will be aware of the operations which are exposed to the client. Each operation is a simple exchange pattern such as one-way, duplex and request/reply.
Below figure illustrate the functions of Endpoint
Example:
Endpoints will be mentioned in the web.config file on the created service.
<system.serviceModel> <services> <service name="MathService" behaviorConfiguration="MathServiceBehavior"> <endpoint address="http://localhost:8090/MyService/MathService.svc" contract="IMathService" binding="wsHttpBinding"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MathServiceBehavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
No comments:
Post a Comment