WCF Interview Questions:
- What are the different ways to expose WCF Metadata?
- What is mexHttpBinding in WCF?
- What is a Service Proxy in Windows Communication Foundation?
- What are the different ways to generate proxy in WCF?
- Difference between using ChannelFactory and Proxies in WCF?
- What are the different ways to handle concurrency in WCF?
- What is WCF throttling?
- What is Session Mode Enumeration in WCF?
1.What are the different ways to expose WCF Metadata?
By default, WCF does not expose metadata. There are 2 ways to expose Metadata in WCF.
- In configuration file, by enabling metadata exchange as follows:
- ServiceHost can expose a metadata exchange endpoint to access metadata at runtime.
1 2 3 4 5 6 7 8 9 10 |
using (ServiceHost host = new ServiceHost(typeof(WcfService1))) { ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; host.Description.Behaviors.Add(behavior); host.Open(); Console.WriteLine(“My Service started.”); Console.ReadLine(); host.Close(); } |
2. What is mexHttpBinding in WCF?
In order to generate proxy, we need service metadata and mexHttpBinding is the binding that returns service metadata.
If we look into our configuration file, service will have an endpoint with mexHttpBinding as follows:
and service metadata behavior will be configured as follows:
3. 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 using Visual studio or svcutil.exe.
4. What all are the different ways to generate proxy in WCF?
i.Generating proxy using Visual Studio is simple.
- Right click References and choose “Add Service Reference”.
- Provide base address of the service on “Add Service Reference” dialog box and click “Go” button. Service will be listed below.
- Provide namespace and click OK.
Visual studio will generate a proxy automatically.
ii.We can 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.
SvcUtil http://localhost/HelloService/Service1.svc /out:HelloServiceProxy.cs
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.
SvcUtil http://localhost:8080/HelloService/Service1.svc /out:HelloServiceProxy.cs
5. Difference between using ChannelFactory and proxies in WCF?
A channel factory creates channels of different types that are used by client to send messages to the service.
ChannelFactory class is used with a known interface to create the channel. This approach is commonly used when you have access control to both the server and the client.
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.
you can read the detailed difference between ChannelFactory and Proxies here.
6. What are the different ways to handle concurrency in WCF?
Multiple threads executing the application code simultaneously is called Concurrency.
There are 3 ways to handle concurrency.
- Single
- Multiple
- Reentrant
Single: only a single request can be processed by WCF service instance. Other requests will be waiting until the first one is fully served.
Multiple: multiple requests can be served by multiple threads of a single WCF service instance.
Reentrant: A single WCF service instance can process one request at a given time but the thread can exit the service to call another service.
Reference books, you may like:
Programming WCF Services: Design and Build Maintainable Service-Oriented SystemsWCF Multi-Layer Services Development with Entity Framework, 4th Edition
Learning WCF: A Hands-on Guide
You can read the detailed explanation on WCF concurrency here.
7. What is WCF Throttling?
Throttling controls how many messages are processed.
WCF throttling enables us to regulate the maximum number of WCF instances, concurrent calls and concurrent sessions.
1 2 3 4 5 6 7 8 |
<serviceBehavior> <behavior name=”MyServiceBehavior”> <serviceThrottling maxConcurrentInstances=”2147483647” maxConcurrentCalls=”16″ maxConcurrentSessions=”10″ </behavior> </serviceBehavior> |
8.What is Session Mode Enumeration in WCF?
SessionMode enumeration is used with the service contract to allow or restrict bindings to use sessions.
There are 3 ways to handle SessionMode enumeration.
- Allowed
- Not Allowed
- Required
You can read more on SessionMode Enumeration here.
© 2015, admin. All rights reserved.
Pingback: Top 10 Interview Questions on the web in 2015 (Worth Reading !!!) – CsharpStar