In this article we will be Learning about the Config Files in WCF. In WCF you can define EndPoints in Code and also by using the Config file. Defining EndPoints:
Let's take a look at the Configuration that is part of the WCF Configuration File: ServiceModel Cofiguration: <system.serviceModel> contains configuration settings. Core Elements: <services> contains service type definitions i.e List of all the Services. You typically have one Service defined in a Config File, although you could have more than one. <endpoint> contains an address, binding and contract for a service. <bindings> contains one or more binding sections. - Here you Configure individual bindings <behaviours> contains definition of service or client behaviours. - This is the way you could configure a service or client <services> Element: The Services Element contains one or more individual <service> elements.The <service> element provides definitions of the service type and includes base addresses and endpoints for that type. The below screenshot shows an example of how the <services> element is defined: As you can see in the screenshot, there are two endpoints defined. One is the normal endpoint which gets added for the service. The Metadata Endpoint with binding mexHttpBinding and the contract IMetadataExchange, enables us to add a Service Reference. When the Client adds a Service Reference the metadata needs to be downloaded and the presence of this endpoint helps us download the metadata. Multiple EndPoints: You could define multiple endpoints for a service. You might provide a HTTP endpoint for external use and a TCP endpoint for internal use. As seen in the screenshot above I can easily create an internal and external endpoint for my service. The Contract remains the same in both the Endpoints because we are using the same service; what changed is the Binding.
Lets see some code examples: In this sample we have created a HttpEndPoint and TCPEndPoint as shown below: The HTTPEndPoint uses a BasicHTTPBinding whereas TCPEndPoint uses NetTcpBinding. In the next post I will show you an example of creating endpoints in the application and Configuration File.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: