The document discusses various concepts related to Windows Communication Foundation (WCF) services such as:
1. The key differences between ASMX and WCF web services and how WCF allows for more flexible message exchange.
2. What WCF service endpoints are and how they define the address, binding, and contract for communicating with a service.
3. The possible ways of hosting a WCF service including self-hosting, IIS hosting, and Windows Service hosting.
4. Core WCF concepts like contracts, bindings, security modes, and instance management techniques.
5. Advanced topics like operation overloading, message exchange patterns, data contract serialization, and throttling.
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
WCF vs ASMX Web Services
1. 1. What is the difference between WCF and ASMX Web Services?
Simple and basic difference is thatASMX or ASP.NET web service is designed to send and receive messages using
SOAP over HTTP only. While WCF can exchange messages using anyformat(SOAP is default) over any transport
protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).
You can follow another tutorial WCF Vs ASMX for detailed discussion on this topic.
2. What are WCF Service Endpoints? Explain.
For Windows Communication Foundation services to be consumed,it’s necessarythat it mustbe exposed;Clients
need information aboutservice to communicate with it. This is where service endpoints playtheir role. Clientuses
endpointto communicate with WCF Service. A WCF service endpointhas three basic elements i.e.Address,Binding
and Contract
2. Address: It defines “WHERE”. Address is the URL that identifies the location of the service.
Binding: It defines “HOW”. Binding defines how the service can be accessed.
Contract: It defines “WHAT”. Contractidentifies whatis exposed by the service.
A WCF Service can have multiple endpoints configured to accommodate differentclients,for example,one client may
be using HTTP while other configured to communicate over TCP.
3. What are the possible ways of hosting a WCF service? Explain.
For a Windows Communication Foundation service to host,we need at least a managed process, a ServiceHost
instance and an Endpoint configured. Possible approaches for hosting a service are:
Hosting in a Managed Application/ Self Hosting
Console Application
Windows Application
Windows Service
Hosting on Web Server
IIS 6.0 (ASP.NET Application supports onlyHTTP)
Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP,TCP,
NamedPipes,MSMQ.
If you are looking for implementation ofall Hosting options,please follow here (Console | Windows Service | IIS |
WAS)
4. How we can achieve Operation Overloading while exposing WCF Services?
By default, WSDL doesn’tsupportoperation overloading.Overloading behavior can be achieved by using “Name”
property of OperationContractattribute.
[ServiceContract]
interface IMyCalculator
{
[OperationContract(Name = “SumInt”)]
int Sum(int arg1,int arg2);
[OperationContract(Name = “SumDouble”)]
3. double Sum(double arg1,double arg2);
}
When the proxy will be generated for these operations,itwill have 2 methods with differentnames i.e.SumIntand
SumDouble.
Important Note: Remember thatduring a technical Interview,interviewer always ask aboutthe latest feature of that
particular technology, so be prepare for it also.For latest features series on Windows Communication Foundation
v4.5, Click here.
5. What Message Exchange Patterns (MEPs) supported by WCF? Explain each of
them briefly.
Windows Communication Foundation supports the following Message Exchange Patterns (MEPs):
Request/Response
One Way
Duplex
Request/Response
It’s the defaultpattern. In this pattern, a response message will always be generated to consumer when the operation
is called, even with the void return type. In this scenario (void return type), response will have empty SOAP body.
4. One Way
In some cases,we are interested to send a message to service in order to execute certain business functionality but
not interested in receiving anything back. OneWay MEP will work in such scenarios. If we want queued message
delivery, OneWay is the only available option.
Duplex
The Duplex MEP is basicallya two-way message channel.In some cases, we want to send a message to service to
initiate some longer-running processing and require a notification back from service in order to confirm that the
requested process has been completed.
5. Please follow for detailed implementation for Message Exchange Patterns in WCF here.
6. What is DataContractSerializer and How its different from XmlSerializer?
Serialization is the process of converting an object instance to a portable and transferable format. So, whenever we
are talking about web services, serialization is very important.
Windows Communication Foundation has DataContractSerializer thatis new in .NET 3.0 and uses opt-in approach
as compared to XmlSerializer that uses opt-out.Opt-in means specifywhatever we want to serialize while Opt-out
means you don’thave to specify each and every property to serialize,specifyonly those you don’t wantto serialize.
DataContractSerializer is about10% faster than XmlSerializer but it has almostno control over how the objectwill be
serialized.If we wanted to have more control over how objectshould be serialized thatXmlSerializer is a better
choice.
6. 7. What are Contracts in WCF?
A Contract is basicallyan agreementbetween the two parties i.e.Service and Client.In WCF, Contracts can be
categorized as behavioral or structural.
1. Behavioral Contractsdefinethatwhatoperationsclientcanperform on a service.
ServiceContract attribute is used to mark a type as Service contract that contains operations.
OperationContract attributes is used to mark the operations thatwill be exposed.
Fault Contract defines whaterrors are raised by the service being exposed.
2. Structural Contracts
DataContract attribute define types that will be moved between the parties.
MessageContract attribute define the structure of SOAP message.
8. Which standard binding could be used for a service that was designed to
replace an existing ASMX web service?
The basicHttpBinding standard binding is designed to expose a service as if it is an ASMX/ASP.NET web service.
This will enable us to supportexisting clients as applications are upgrade to WCF.
9. Please explain briefly different Instance Modes in WCF?
WCF will bind an incoming message requestto a particular service instance,so the available modes are:
Per Call: instance created for each call,mostefficientin term of memorybutneed to maintain session.
Per Session: Instance created for a complete session ofa user.Session is maintained.
Single: Only one instance createdfor all clients/users and sharedamong all.Least efficient in terms
of memory
Please follow “3 techniques for Instance Managementin WCF“.
7. 10. Please explain different modes of security in WCF? Or Explain the difference
between Transport and Message Level Security.
In Windows Communication Foundation,we can configure to use security at different levels
a. Transport Level security means providing securityat the transportlayer itself. When dealing with security at
Transportlevel, we are concerned aboutintegrity, privacy and authentication ofmessage as ittravels along the
physical wire.It depends on the binding being used thathow WCF makes itsecure because mostofthe bindings
have built-in security.
<netTcpBinding>
<binding name=”netTcpTransportBinding”>
<security mode=”Transport”>
<Transport clientCredentialType=”Windows” />
</security>
</binding>
</netTcpBinding>
b. Message Level Security
For Tranport level security, we actually ensure the transportthat is being used should be secured butin message
level security, we actually secure the message.We encrypt the message before transporting it.
<wsHttpBinding>
<binding name=”wsHttpMessageBinding”>
<security mode=”Message”>
<Message clientCredentialType=”UserName” />
</security>
</binding>
</wsHttpBinding>
It totally depends upon the requirements butwe can use a mixed security mode also as follows:
<basicHttpBinding>
<binding name=”basicHttp”>
<security mode=”TransportWithMessageCredential”>
<Transport />
<Message clientCredentialType=”UserName” />
</security>
</binding>
</basicHttpBinding>
8. 11. What is the difference between Service EndPoint and Client Endpoint?
As we already understood the conceptof an Endpointand it’s ABC (Address,Binding,Contract).Both Service and
ClientEndpointhas same ABC but we think in different perspective while working with them.We can differentiate
between Service and ClientEndpointwith respectto Address,Binding and Contractas:
Service Endpoint Client Endpoint
WHERE: URL of hosted service.
WHERE: where to connect with hosted
service.
WHAT: bindings being used. WHAT: binding supported by service.
CONTRACT: Service Contract i.e.
interfaces
CONTRACT: what to pass and expect
while communicating with service.
12. What is a WCF Binding? How many different types of bindings available in WCF?
Bindings in WCF actually defines thathow to communicate with the service. Binding specifies thatwhat
communication protocol as well as encoding method will be used.Optionally,binding can specify other important
factors like transactions,reliable sessions and security.
Another WCF Tutorial gives more detailed understanding ofBinding conceptin WCF.
There are different built-in bindings available in WCF,each designed to fulfill som e specific need.
basicHttpBinding
wsHttpBinding
netNamedPipeBinding
netTcpBinding
netPeerTcpBinding
netmsmqBinding
9. 13. More WCF Interview Questions for Experienced
How can we use ServiceMetadataContractBehavior class in WCF?
ServiceMetadataContractBehavior is a class thatfacilitates us to specifywhether endpointshould be exposed in
service metadata or not. As we already know that a WCF Service can have multiple endpoints,so in certain
scenarios we mightnotbe interested to publish metadata for a specific endpointofour WCF service.
How we can use MessageContract partially with DataContract for a service
operation in WCF?
10. MessageContractmustbe used all or none. If we are using MessageContractinto an operation signature ,then we
mustuse MessageContractas the only parameter type and as the return type of the operation.
14. What is WCF throttling?
WCF throttling enables us to regulate the maximum number ofWCF instances,concurrentcalls and concurrent
sessions.Basic purpose is to control our WCF service performance by using Service throttling behavior. Above given
values are the defaultones,but we can update it after looking into the requirements ofour application.
In configuration file we can set this behavior as follows:
<serviceBehavior>
<behavior name=”MyServiceBehavior”>
<serviceThrottling
maxConcurrentInstances=”2147483647”
maxConcurrentCalls=”16″
maxConcurrentSessions=”10″
</behavior>
</serviceBehavior>
15. What are the core security concepts supported by WCF?
There are four core security Features
11. Confidentiality: It’s a confirmation aboutthe recipient. Only the valid recipientcan read the message when
it passed between service and client.
Integrity: is to ensure that message received is notbeing tempered or changed during exchange.
Authentication: is a way for the parties (sender and receiver) to identify each other.
Authorization: ensures thatwhatactions an authenticated user can perform?
16. Difference between Message Level securityand Transport Level security?
Security can be configured at two different levels in Windows Communication Foundation:
1. Transport Level Security
secures the transport (the pipe) over which the message passes through from client to a service.
2. Message Level Security
secures the message that is being transported from one end to another.
WCF Supports following Transfer Security Modes:
None – No security at all. Very risky to choose. (nguy hiểm)
Transport – Securing message transfer with transport protocol like TCP, IPs, HTTPs, MSMQ. It’s
Ideal for Intranet scenarios having point to point communication. (Bảo vệ truyền thông với giao thức
vận chuyển giống như TCP, IP, HTTPS, MSMQ. Đó là lý tưởng cho các kịch bản Intranet có giao
tiếp point to point)
Message – Securing message by encrypting it. Good for scenarios even when multiple
intermediaries involved. (bảo vệ tin nhắn bằng cách mã hóa message)
Mixed – TransportWithMessageCredential uses transport for message privacy and service
authentication with client authentication handled at message level. (sử dụng phương tiện giao
thông để bảo mật tin nhắn và xác thực với dịch vụ xác thực khách hàng được xử lý ở mức độ tin
nhắn.)
Both -Using both Message as well as transport security. In this case a secured encrypted message
travel over a secure transport (pipe) only supported by MSMQ Binding. (sử dụng cả message và
transport)
<wsHttpBinding>
<binding name=”SecurityModeDemo”>
<security mode=”[None|Transport|Message|….]”/>
</binding>
</wsHttpBinding>
17. Can you please explain which security mode supported by various WCF Bindings?
12. Following table illustrates in details about support for security mode in Windows Communication
Foundation for various WCF Bindings.
WCF Binding None Transport Message Mixed Both
BasicHttpBinding Default Yes Yes Yes No
WSHttpBinding Yes Yes Default Yes No
WSDualHttpBinding Yes No Default Yes No
NetTcpBinding Yes Default Yes Yes No
NetNamedPipeBinding Yes Default No No No
NetMsmqBinding Yes Default Yes No Yes
18. What is the difference between wsdl & mex endpoint?
It's pretty the same thing but mex is designed to support non-HTTP protocols and for advanced
configuration/security scenarios. WSDL is the legacy way and MEX is the new improved version with
WCF.
19. What is the meaning of httpGetEnabled="false" or httpGetEnabled="true"
It will expose metadata via wsdl through the defautl url, even if you don't have defined a mex endpoint for
your service.