Blog author: Imghani
| Posted on: 9/16/2012 | Category: WCF Blogs
| Views: 637 | Status: [Member]
| Points: 75
| Alert Moderator
This WCF Tutorial is part-2 in series of WCF
Service FAQs. Previous part in this series is already published at WCF Service FAQs - Part 1.
What are the
different ways to expose WCF Metadata?
By default, WCF doesn't expose metadata. We can expose it by choosing one of
the following ways:
In configuration file, by
enabling metadata exchange as follows:
expose a metadata exchange endpoint to access metadata at runtime.
using (ServiceHost host = new
= new ServiceMetadataBehavior();
mexHttpBinding in WCF?
In order to generate proxy, we need service metadata and mexHttpBinding returns
If we look into our configuration file, service will have an endpoint with
mexHttpBinding as follows:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
and service metadata behavior will be configured as follows:
deployment of application to production machine, it should be disabled.
In order to support other protocols, related bindings are mexHttpBinding,
What is a Service Proxy in WCF?
A service proxy or simply proxy in WCF enables application(s) to
interact with WCF Service by sending and receiving messages. It's basically a
class that encapsulates service details i.e. service path, service implementation
technology, platform and communication protocol etc. It contains all the
methods of service contract (signature only, not the implementation). So, when
the application interact the service through proxy, it gives the impression
that it's communicating a local object.
We can create proxy for a service by using Visual Studio or SvcUtil.exe.
What are the different ways to generate proxy in WCF?
Generating proxy using Visual Studio is simple and straight forward.
i) Right click References and
choose "Add Service Reference".
ii) Provide base address of the
service on "Add Service Reference" dialog box and click "Go" button.
Service will be listed below.
iii) Provide namespace and click
Visual studio will generate a proxy automatically.
generate proxy using svcutil.exe utility using command line. This utility
requires few parameters like HTTP-GET address or the metadata exchange endpoint
address and a proxy filename i.e. optional.
If we are hosting the service at a different port(other than default for IIS
which is 80), we need to provide port number in base address.
For parameter details regarding svcutil,
please follow the MSDN link
Difference between using ChannelFactory and Proxies in WCF?
If we have control over Server and Client, then ChannelFactory is a good
option because it relies on having local interfaces that actually describes the
service i.e. service contract.
On the other hand, If we don't have control over server and
only have WSDL/URL, then it's better to generate proxy using Visual Studio or
SvcUtil is better option as compared to Visual Studio because we have more
control in case of SvcUtil.
How to create proxy for Non-WCF Services?
In case of
Non-WCF Services, we can create proxy by either using Visual Studio or svcUtil.exe
tool by pointing to WSDL of the non-WCF service. In this scenario, we can't
create proxy through ChannelFactory or manually developing proxy class because
we don't have local interfaces i.e. service contract.
Breifly explain Automatic Activation in WCF?
Automatic activation means service starts and serves the
request when a message request is received, but service doesn't need to be
running in advance.
There are few scenarios in which service needs to be running in advance, For
example, in case of Self-Hosting.
What are the different WCF Instance Activation Methods available?
three different types of Instance Activation methods
- Per Call
- Per Session
on WCF Instance Activation Methods, please refer other article "WCF
What are the different ways to handle concurrency in WCF?
There are three different ways to handle concurrency in WCF that
Single: means at a given time, only a single request
can be processed by WCF service instance. Other requests will be waiting until
the first one is fully served.
Multiple: means multiple requests can be served by multiple
threads of a single WCF service instance.
Reentrant: means a single WCF service instance can
process one request at a given time but the thread can exit the service to call
We can apply these concurrency settings by putting
ConcurrencyMode property in ServiceBehavior as follows:
Public class MyService : IMyService
What is WCF throttling?
throttling enables us to regulate the maximum number of WCF instances,
concurrent calls and concurrent sessions. Basic purpose is to control our WCF
service performance by using Service throttling behavior.
configuration file we can set this behavior as follows:
given values are the default ones, but we can update it after looking into the
requirements of our application.
Imran Abdul Ghani