What is WCF?
Windows
Communication Foundation (WCF) is an SDK for developing and deploying services
on Windows. WCF provides a runtime environment for services, enabling you to
expose CLR types as services, and to consume other services as CLR types. WCF is part of .NET 3.0 and requires .NET
2.0, so it can only run on systems that support it.
What is service and client in
perspective of data communication?
A
service is a unit of functionality exposed to the world.
The
client of a service is merely the party consuming the service.
What is address in WCF and how many
types of transport schemas are there in WCF?
Address
is a way of letting client know that where a service is located. In WCF, every
service is associated with a unique address. This contains the location of the
service and transport schemas.
WCF
supports following transport schemas
·
HTTP
·
TCP
·
Peer network
·
IPC (Inter-Process Communication over named
pipes)
·
MSMQ
The
sample address for above transport schema may look like
http://localhost:81
http://localhost:81/MyService
net.tcp://localhost:82/MyService
net.pipe://localhost/MyPipeService
net.msmq://localhost/private/MyMsMqService
net.msmq://localhost/MyMsMqService
What are contracts in WCF?
In
WCF, all services expose contracts. The contract is a platform-neutral and
standard way of describing what the service does.
WCF
defines four types of contracts.
Service
contracts: Describe which
operations the client can perform on the service.
There
are two types of Service Contracts.
·
ServiceContract - This attribute is used to
define the Interface.
·
OperationContract - This attribute is used
to define the method inside Interface.
[ServiceContract]
interface
IMyContract
{
[OperationContract]
string
MyMethod( );
}
class
MyService : IMyContract
{
public
string MyMethod( )
{
return "Hello
World";
}
}
Data
contracts: Define which data types are passed to and
from the service. WCF defines implicit contracts for built-in types such as int
and string, but we can easily define explicit opt-in data contracts for custom
types.
There
are two types of Data Contracts.
·
DataContract - attribute used to define the
class
·
DataMember - attribute used to define the
properties.
[DataContract]
class
Contact
{
[DataMember]
public
string FirstName;
[DataMember]
public
string LastName;
}
If
DataMember attributes are not specified for a properties in the class that
property can't be passed to-from web service.
Fault
contracts: Define which errors are raised by the service, and how
the service handles and propagates errors to its clients.
Message
contracts: Allow the service to interact directly with
messages. Message contracts can be typed or untyped, and are useful in
interoperability cases and when there is an existing message format we have to
comply with.
Where we can host WCF services?
Every
WCF services must be hosted somewhere. There are three ways of hosting WCF
services.
1.
IIS
2.
Self Hosting
3.
WAS (Windows Activation Service)
What is binding and how many types of
bindings are there in WCF?
A
binding defines how an endpoint communicates to the world. A binding defines
the transport (such as HTTP or TCP) and the encoding being used (such as text
or binary). A binding can contain binding elements that specify details like the
security mechanisms used to secure messages, or the message pattern used by an
endpoint.
WCF
supports nine types of bindings.
Basic
binding: Offered by the
BasicHttpBinding class, this is designed to expose a WCF service as a legacy
ASMX web service, so that old clients can work with new services. When used by
the client, this binding enables new WCF clients to work with old ASMX
services.
TCP
binding: Offered by the NetTcpBinding class, this uses TCP for
cross-machine communication on the intranet. It supports a variety of features,
including reliability, transactions, and security, and is optimized for
WCF-to-WCF communication. As a result, it requires both the client and the
service to use WCF.
Peer
network binding : Offered by the NetPeerTcpBinding class,
this uses peer networking as a transport. The peer network-enabled client and
services all subscribe to the same grid and broadcast messages to it.
IPC
binding : Offered by the NetNamedPipeBinding class, this uses
named pipes as a transport for same-machine communication. It is the most
secure binding since it cannot accept calls from outside the machine and it
supports a variety of features similar to the TCP binding.
Web
Service (WS) binding: Offered by the WSHttpBinding class,
this uses HTTP or HTTPS for transport, and is designed to offer a variety of
features such as reliability, transactions, and security over the Internet.
Federated
WS binding: Offered by the WSFederationHttpBinding
class, this is a specialization of the WS binding, offering support for
federated security.
Duplex
WS binding: Offered by the WSDualHttpBinding class,
this is similar to the WS binding except it also supports bidirectional
communication from the service to the client.
MSMQ
binding: Offered
by the NetMsmqBinding class, this uses MSMQ for transport and is designed to
offer support for disconnected queued calls.
MSMQ
integration binding: Offered
by the MsmqIntegrationBinding class, this converts WCF messages to and from
MSMQ messages, and is designed to interoperate with legacy MSMQ clients.
What is endpoint in WCF?
Every
service must have Address that defines where the service resides, Contract that
defines what the service does and a Binding that defines how to communicate
with the service. In WCF the relationship between Address, Contract and Binding
is called Endpoint.
The
Endpoint is the fusion of Address, Contract and Binding.
How to define a service as REST based
service in WCF?
WCF
3.5 provides explicit support for RESTful communication using a new binding
named WebHttpBinding.
The
below code shows how to expose a RESTful service:
[ServiceContract]
interface
IStock
{
[OperationContract]
[WebGet]
int GetStock(string StockId);
}
By
adding the WebGetAttribute, we can define a service as REST based service that
can be accessible using HTTP GET operation.
What is the address formats of the WCF
transport schemas?
Address
format of WCF transport schema always follow
[transport]://[machine
or domain][:optional port] format.
for
example:
HTTP
Address Format
http://localhost:8888
the
way to read the above url is
"Using
HTTP, go to the machine called localhost, where on port 8888 someone is
waiting"
When
the port number is not specified, the default port is 80.
TCP
Address Format
net.tcp://localhost:8888/MyService
When
a port number is not specified, the default port is 808:
net.tcp://localhost/MyService
NOTE:
Two HTTP and TCP addresses from the same host can share a port, even on the
same machine.
IPC
Address Format
net.pipe://localhost/MyPipe
We
can only open a named pipe once per machine, and therefore it is not possible
for two named pipe addresses to share a pipe name on the same machine.
MSMQ
Address Format
net.msmq://localhost/private/MyService
net.msmq://localhost/MyService
What is Proxy and how to generate
proxy for WCF Services?
The
proxy is a CLR class that exposes a single CLR interface representing the
service contract. The proxy provides the same operations as service's contract,
but also has additional methods for managing the proxy life cycle and the
connection to the service. The proxy completely encapsulates every aspect of
the service: its location, its implementation technology and runtime platform,
and the communication transport.
The
proxy can be generated using Visual Studio by right clicking Reference and
clicking on Add Service Reference. This brings up the Add Service Reference
dialog box, where you need to supply the base address of the service (or a base
address and a MEX URI) and the namespace to contain the proxy.
Proxy
can also be generated by using SvcUtil.exe command-line utility. We need to
provide SvcUtil with the HTTP-GET address or the metadata exchange endpoint
address and, optionally, with a proxy filename. The default proxy filename is
output.cs but you can also use the /out switch to indicate a different name.
SvcUtil
http://localhost/MyService/MyService.svc /out:Proxy.cs
When
we are hosting in IIS and selecting a port other than port 80 (such as port
88), we must provide that port number as part of the base address:
SvcUtil
http://localhost:88/MyService/MyService.svc /out:Proxy.cs
What are different elements of WCF Services
Client configuration file?
WCF
Services client configuration file contains endpoint, address, binding and
contract. A sample client config file looks like
<system.serviceModel>
<client>
<endpoint name =
"MyEndpoint" address =
"http://localhost:8000/MyService/" binding = "wsHttpBinding" contract =
"IMyContract"/>
</client>
</system.serviceModel>
What is Transport and Message
Reliability?
Transport
reliability (such as the one offered by TCP) offers point-to-point guaranteed
delivery at the network packet level, as well as guarantees the order of the
packets. Transport reliability is not resilient to dropping network connections
and a variety of other communication problems.
Message
reliability deals with reliability at the message level independent of how many
packets are required to deliver the message. Message reliability provides for
end-to-end guaranteed delivery and order of messages, regardless of how many
intermediaries are involved, and how many network hops are required to deliver
the message from the client to the service.
How to configure Reliability while
communicating with WCF Services?
Reliability
can be configured in the client config file by adding reliableSession under
binding tag.
<system.serviceModel>
<services>
<service name = "MyService">
<endpoint address =
"net.tcp://localhost:8888/MyService" binding = "netTcpBinding" bindingConfiguration
= "ReliableCommunication" contract = "IMyContract" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name = "ReliableCommunication">
<reliableSession enabled = "true"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
Reliability
is supported by following bindings only
NetTcpBinding
WSHttpBinding
WSFederationHttpBinding
WSDualHttpBinding
How to set the timeout property for the
WCF Service client call?
The
timeout property can be set for the WCF Service client call using binding tag.
<client>
<endpoint
...
binding = "wsHttpBinding"
bindingConfiguration =
"LongTimeout"
...
/>
</client>
<bindings>
<wsHttpBinding>
<binding name =
"LongTimeout" sendTimeout = "00:04:00"/>
</wsHttpBinding>
</bindings>
If
no timeout has been specified, the default is considered as 1 minute.
How to deal with operation overloading
while exposing the WCF services?
By
default overload operations (methods) are not supported in WSDL based
operation. However by using Name property of OperationContract attribute, we
can deal with operation overloading scenario.
[ServiceContract]
interface
ICalculator
{
[OperationContract(Name =
"AddInt")]
int Add(int arg1,int arg2);
[OperationContract(Name
= "AddDouble")]
double Add(double arg1,double arg2);
}
Notice
that both method name in the above interface is same (Add), however the Name
property of the OperationContract is different. In this case client proxy will
have two methods with different name AddInt and AddDouble.
What was the code name for WCF?
The
code name of WCF was Indigo .
WCF
is a unification of .NET framework communication technologies which unites the
following technologies:-
·
NET remoting
·
MSMQ
·
Web services
·
COM+
What are the main components of WCF?
The
main components of WCF are
1.
Service class
2.
Hosting environment
3.
End point
What are various ways of hosting WCF
Services?
There
are three major ways of hosting a WCF services
• Self-hosting
the service in its own application domain. The service comes in to existence
when you create the object of Service Host class and the service closes when
you call the Close of the Service Host class.
•
Host in application domain or process provided by IIS Server.
•
Host in Application domain and process provided by WAS (Windows Activation
Service) Server.
What is the difference WCF and Web
services?
Web
services can only be invoked by HTTP (traditional webservice with .asmx). While
WCF Service or a WCF component can be invoked by any protocol (like http, tcp
etc.) and any transport type.
Second
web services are not flexible. However, WCF Services are flexible. If you make
a new version of the service then you need to just expose a new end. Therefore,
services are agile and which is a very practical approach looking at the
current business trends.
We
develop WCF as contracts, interface, operations, and data contracts. As the
developer we are more focused on the business logic services and need not worry
about channel stack. WCF is a unified programming API for any kind of services
so we create the service and use configuration information to set up the
communication mechanism like HTTP/TCP/MSMQ etc
What is three major points in WCF?
We
should remember ABC.
Address
--- Specifies the location of the service which will be like
http://Myserver/MyService.Clients will use this location to communicate with
our service.
Binding
--- Specifies how the two paries will communicate in term of transport and
encoding and protocols
Contract
--- Specifies the interface between client and the server.It's a simple
interface with some attribute.
Difference between WCF and Web
services?
Web
Services
1.
It can be accessed only over HTTP
2.
It works in stateless environment
3.
Web Services Use XmlSerializer
WCF
1.
WCF is flexible because its services can be hosted in different types of
applications.
2.
State management is possible
3.
WCF uses DataContractSerializer which is better in Performance as Compared to
XmlSerializer
Important difference between
DataContractSerializer and XMLSerializer.
1.
A practical benefit of the design of the DataContractSerializer is better
performance over Xmlserializer.
2.
XML Serialization does not indicate the which fields or properties of the type
are serialized into XML where as DataCotratSerializer Explicitly shows the
which fields or properties are serialized into XML.
3.
The DataContractSerializer can translate the HashTable into XML.
4.
DataContractSerializer is the default serializer fot the WCF
5.
DataContractSerializer is very fast.
6.
DataContractSerializer is basically for very small, simple subset of the XML
infoset.
7.
XMLSerializer is used for complex schemas.
What is a SOA Service?
SOA
is Service Oriented Architecture. SOA service is the encapsulation of a high
level business concept. A SOA service is composed of three parts.
1.
A service class implementing the service to be provided.
2.
An environment to host the service.
3.
One or more endpoints to which clients will connect.
What is the use of ServiceBehavior
attribute in WCF ?
ServiceBehaviour
attribute is used to specify the InstanceContextMode for the WCF Service class
(This can be used to maintained a state of the service or a client too)
There
are three instance Context Mode in the WFC
1.
PerSession : This is used to create a new instance for a service and the
same instance is used for all method for a particular client. (eg: State can be
maintained per session by declaring a variable)
2.
PerCall : This is used to create a new instance for every call from the
client whether same client or different. (eg: No state can be maintained as
every time a new instance of the service is created)
3.
Single : This is used to create only one instance of the service and the
same instance is used for all the client request. (eg: Global state can be
maintained but this will be applicable for all clients)
In WCF, Which contract is used to
document the errors occurred in the service to client?
Fault
Contract is used to document the errors occurred in the service to client.
What is the Messaging Pattern? Which
Messaging Pattern WCF supports?
Messaging
Pattern : Messaging patterns describes how client and server
should exchange the message. There is a protocol between client and server for
sending and receiving the message. These are also called Message Exchange
Pattern.
WCF
supports following 3 types of Message Exchange Patterns
1.
request - reply (default message exchange pattern)
2.
OneWay (Simplex / datagram)
3.
Duplex(CallBack)
What is .svc file in WCF?
.svc
file is a text file. This file is similar to our .asmx file in web services.
This
file contains the details required for WCF service to run it successfully.
This
file contains following details :
1.
Language (C# / VB)
2.
Name of the service
3.
Where the service code resides
Example
of .svc file
<%@
ServiceHost Language="C#/VB" Debug="true/false"
CodeBehind="Service code files path" Service="ServiceName"
What is XML Infoset?
The
XML Information Set defines a data model for XML. It is an abstract set of
concepts such as attributes and entities that can be used to describe a valid
XML document. According to the specification, "An XML document's
information set consists of a number of information items; the information set
for any well-formed XML document will contain at least a document information
item and several others."
What is the purpose of base address in
WCF service? How it is specified?
When
multiple endpoints are associated with WCF service, base address (one primary
address) is assigned to the service, and relative addresses are assigned to
each endpoint. Base address is specified in <host> element for each
service.
E.g.
<configuration>
<system.servicemodel>
<Services>
<service
name=”MyService>
<host>
<baseAddresses>
<add baseAddress
=”http://localhost:6070/MyService”>
</baseAddresses>
</host>
</service>
<services>
</system.servicemodel>
</configuration>
Which protocol is used for
platform-independent communication?
SOAP
(Simple Object Access Protocol), which is directly supported from WCF (Windows
Communication Foundation).
How the concurrency mode is specified
in WCF service?
The
concurrency mode is specified using the ServiceBehavior attribute on the class
that implements the service.
Ex.
[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single)]
Public
class ServiceClass : IServiceInterface{
//Implementation
Code
}
There
are 3 possible values of ConcurrencyMode enumeration
Single
Reentrant
Multiple
Which are the 3 types of transactions
manager WCF supports?
WCF
supports following 3 types of transactions managers:
a. LightWeight
b. OLE Transactions
c. WS-Atomic Transactions
How to set the instancing mode in WCF
service?
In
WCF, instancing mode is set at service level. For ex.
//Setting
PerSession instance mode
[ServiceBehavior(InstanceContextMode
= InstanceContextMode.PerSession)]
class
MyService : IMyService
{
//Implementation
goes there
}
What are the advantages of hosting WCF
service in WAS?
WAS
(Windows Activation Service) is a component of IIS 7.0. Following are few
advantages :
1.
We are not only limited to HTTP protocol. We can also use supported protocols
like TCP, named pipes and MSMQ
2.
No need to completely install IIS. We can only install WAS component and keep
away the WebServer.
What is service host factory in WCF?
1.
Service host factory is the mechanism by which we can create the instances of
service host dynamically as the request comes in.
2.
This is useful when we need to implement the event handlers for opening and
closing the service.
3.
WCF provides ServiceFactory class for this purpose.
What
does a Windows Communication Foundation, or WCF, service application use to
present exception information to clients by default?
However,
the service cannot return a .NET exception to the client. The WCF service and
the client communicate by passing SOAP messages. If an exception occurs, the
WCF runtime serializes the exception into XML and passes that to the client.
What is the use of Is Required
Property in Data Contracts?
Data
Contracts, is used to define Required or NonRequired data members. It can be
done with a property named IsRequired on DataMember attribute.
[DataContract]
public
class test
{
[DataMember(IsRequired=true)]
public string NameIsMust;
[DataMember(IsRequired=false)]
public string Phone;
}
What is Asynchronous Messaging ?
Asynchronous
messaging describes a way of communications that takes place between two
applications or systems, where the system places a message in a message queue
and does not need to wait for a reply to continue processing.
Why in WCF, the
"httpGetEnabled" attribute is essential ?
The
attribute "httpGetEnabled" is essential because we want other
applications to be able to locate the metadata of this service that we are
hosting.
<serviceMetadata
httpGetEnabled="true" />
Without
the metadata, client applications can't generate the proxy and thus won't be
able to use the service.
What is "Automatic
activation" in WCF ?
Automatic
Activation means that the service is not necessary to be running in advance.
When any message is received by the service it then launches and fulfills the
request. But in case of self hosting the service should always be running.
What is a proxy class for WCF Service
?
It
is a class by which a service client can interact with the service. The client
will make an object of the proxy class and by the help of it will call
different methods exposed by the service.
Explain briefly the three way of
communication between source and destination in WCF ?
Simplex - Also known as one way communication. Source will send a message to the target, but target will not respond to the message.
Request/Replay - It is two way communications, source send message to the target, target will resend the response message to the source. But in this scenario at a time only one can send a message (that is), either source or destination.
Duplex -Also known as two way communication, both source and target can send and receive message simultaneously.
State 3 primary aspects of WCF ?
Simplex - Also known as one way communication. Source will send a message to the target, but target will not respond to the message.
Request/Replay - It is two way communications, source send message to the target, target will resend the response message to the source. But in this scenario at a time only one can send a message (that is), either source or destination.
Duplex -Also known as two way communication, both source and target can send and receive message simultaneously.
State 3 primary aspects of WCF ?
(1) Inter-operability with applications built
on differnet technologies.
(2) Unification of the original Dotnet
Framework communication Technologies.
(3) Support for Service Oriented Architecture
(SOA).
If you
have a Dotnet Web Service and a Java Client Application, then which
Communication technology will you use other than WCF ?
Web Service (that is), ASMX will be the most
likely way to achieve cross-vender inter-operability.
Suppose
you have created a WCF service. You have an interface stating your methods that
must be exposed to the clients. But you have forgotten to specify
"[OperationContract]" attribute in any of your method. What will
happen ?
If you do not specify
"[OperationContract] " in any of the methods in your interface then
you will get the following error :-
IService1' has zero operations; a contract
must have at least one operation
Here, Iservice is the name of my Interface.
you can have your own name.
So, it is mandatory to label
"[OperationContract] " attribute to at least one method while
declaring your interface methods or ServiceContract.
In
WCF, can a struct be used as a DataContract ?
Yes, a struct can be used as a DataContract.
For example :-
[DataContract]
struct EmployeeInfo
{
[DataMember]
public int id;
[DataMember]
public string name;
[DataMember]
public DateTime joining_date;
}
How
can I encrypt sensitive data in the WCF configuration file?
To encrypt sensitive data in WCF configuration
file, use aspnet_regiis.exe tool.
Example: If you want to encrypt Connection
String section of WCF config file, use -pe that means provider encryption .
aspnet_regiis -pe "connectionStrings"
-app "/MachineDPAPI"
-prov
"DataProtectionConfigurationProvider"
-pe means provider encryption of configuration
section.
-app means your application's virtual path.
-prov means provider name
Briefly
explain WCF Data Services ?
WCF Data Services are used when you want to
expose your data model and associated logic through a RESTful interface. It
includes a full implementation of theOpen Data (OData) Protocol for .NET to
make this process very easy.
WCF Data Services was originally released as
‘ADO.NET Data Services’ with the release of .NET Framework 3.5.
Explain
in brief, WCF One Way Contract ?
WCF One Way Contract are methods/operations
which are invoked on the service by the client or the server in which either of
them do not expect a reply back. For example :-
If a client invokes a method on the service
then it will not expect a reply back from the service.
What
is the most primary reason to use WCF One Way Contract ?
One way contract is used to ensure that the
WCF client does not go in a blocking mode . If your WCF operation contracts are
returning nothing and they are doing some heavy process then it is better to
use one way contract.
How is
WCF One Way Contract implemented?
WCF one way contract is implemented via
"IsOneWay = true/false" attribute.
For example :-
[ServiceContract]
interface IMyContract
{
[OperationContract(IsOneWay = true)]
void
MyMethod( );
}
What
is Sessionful Services in WCF One Way Contract ?
[ServiceContract(SessionMode =
SessionMode.Required)]
interface IService
{
[OperationContract(IsOneWay = true)]
void
Method1();
}
If the client issues a one-way call and then
closes the proxy while the method executes, the client will still be blocked
until the operation completes.
What
is duplex contract in WCF?
In Duplex contract, clients and servers can
communicate with each other independently.
Duplex contracts consists of two one-way
contracts so that parallel communication is achieved.
What
are the 3 message patterns available in WCF ?
Three message patterns available in WCF are :-
(1) One Way Contract
(2) Duplex Contract
(3) Request-Reply Contract
What
is the primary reason for which Duplex Contract is used in WCF ?
Duplex Contracts are needed when the service
queries the client for some additional information or the service wants to
explicitly raise events on the client.
In
WCF, can data contract classes inherit from one another?
[DataContract]
public class A
{
[DataMember]
public MyCustomType AValue1{ get; set; }
[DataMember]
public MyCustomType AValue2 { get; set; }
}
[DataContract]
public class B: A
{
[DataMember]
public double BValue1{ get; set; }
[DataMember]
public double BValue2 { get; set; }
}
The metadata fails to load when testing the
services.
What needs to be done to load both super and
sub class.
We must add KnownType Attribute.
[DataContract]
[KnownType(typeof(B))]
public class A
{
[DataMember]
public string Value { get; set; }
}
[DataContract]
public class B : A
{
[DataMember]
public string OtherValue { get; set; }
}
In
what are the different ways a WCF Metadata can be accessed ?
WCF Metadata can be accessed in two ways :-
(1) WSDL document can be generated which
represents the endpoints and protocols
(2) Or the ServiceHost can expose a metadata
exchange endpoint to access metadata at runtime
Difference
between reliable messaging and reliable sessions in WCF ?
Reliable messaging is concerned with ensuring
that messages are delivered exactly once.
Reliable session provides a context for
sending and receiving a series of reliable messages. reliable sessions have a
dependency on reliable messaging.
You have to use reliable messaging to provide
an end-to-end reliable session between a client application and a service.
What
is Windows Server AppFabric?
It is a set of extensions to the Windows OS
aimed at making it easier for developers to build faster, scalable, and
more-easily managed services.
It provides a distributed in-memory caching
service and replication technology that helps developers improve the speed and
availability of .NET Web applications and WCF services.
If you are hosting WCF services by using IIS
or WAS in a production environment, you might want to consider implementing
Windows Server AppFabric.
What
is the difference between RIA and WCF services?
Some points are as under
1) WCF is concerned with technical aspects of
communication between servers across tiers and message data management whereas
RIA Web Services delegates this functionality to WCF.
2) WCF is a generic service that could be used
in Windows Forms for example whereas RIA Web Services is focused on Silverlight
and ASP.NET clients
3) WCF does not generate source code to
address class business logic such as validation that may need to be shared
across tiers like RIA Web Services does.
4) The RIA Services can either exist on top of
WCF or replace the WCF layer with RIA Services using alternatice data source
e.g. an ORM layer(EF/NHibernate etc.)
5) RIA Services allow serializing LINQ queries
between the client and server.
How
many different types of authorization supported by WCF ?
Role-based : Map users to roles and check
whether a role can perform the requested operation.
• Identity-based : Authorize users based on
their identity.
• Claims-based : Grant or deny access to the
operation or resources based on the client’s claims.
• Resource-based : Protect resources using
access control lists (ACLs)
What
are the benefits of WCF?
The benefits include the following
1. Transactional support
2. Asynchronous one-way messaging
3. Interoperability
4. Independent versioning
5. Platform Consolidation
What
are the principles WCF implement?
WCF services effectively communicates with the
clients through these principles.
1. Explicit boundaries
WCF services function using the defined
interfaces to identify the communications between server and client that flow
outside the boundaries of the service
2. Independent services
WCF services are deployed and managed
independently and each service interaction is independent of other
interactions. They are independent of deployment, installation and version
issues.
3. Schema and contract based communication
WCF services communicate with clients by
providing only the schema of the message and not its implementation classes.
The service implementation can be changed if required without impacting the
clients
4. Policy based compatibility
Compatibility between WCF services and clients
at runtime is determined using published policies. Policies help separate the
description of the service fro its implementation details.
What
are the four layers in WCF architecture?
SOA based WCF architecture has four layers.
1. Contracts
It describe the WCF message system. This is
achieved by three contracts with policies and bindings.
1. Service Contract - Describes the method
signature of the service using C# or VB
2. Data Contract - Enables .NET types to be in
XML
3. Message Contract - Defines the structure os
the SOAP message exchanged between the service and client
4. Policies and Bindings - Defines the
security level required by the clients
2. Service Runtime
This includes the behaviors that occur when
service is running.
3. Messaging
This layer contains the channels that process
messages and operate on messages and message headers
4. Hosting
Describes the ways in which WCF service can be
hosted.
List
the behaviors included in Service Runtime of the WCF layer?
The following behaviors are included in the
WCF Service Runtime layer..
1. Throttling behavior
Throttling behavior provides the options to
limit how many instances or sessions are created at the application level.
2. Error behavior
By implementing IErrorHandler interface WCF
allows an implementer to control the fault message returned to the caller and
also it performs custom error processing such as logging
3. Metadata behavior
Through the metadata behavior we can publish
metadata of the service by configuring an endpoint to expose the
IMetadataExchange contract as an implementation of a WS-MetadataExchange (MEX)
protocol. By default it is disabled.
4. Instance behavior
This behavior specifies how many instance of
the service has to be created while running WCF.
5. Transaction behavior
This is used to enables the rollback of
transacted operations if a failure occurs.
6. Dispatch behavior
This behavior controls how a message is
processed by the WCF Infrastructure.
7. Concurrency behavior
Concurrency behavior measures how many tasks
can be performed simultaneously
9. Parameter Filtering
This demonstrates how to validate the
parameters passed to a method before it is invoked.
Explain
the functionality of the Message layer in WCF.
The Messaging layer contains channels that
process messages and operate on messages and message headers. The messaging
layer has eight channels which defines the possible formats and data exchange
patterns.
The eight channels are divided into two
categories.
1. Transport Channels
These channels helps reads and write messages
from the network.
1. WS Security Channel
2. WS Reliable MessagingChannel
3. Encoders:Binary/ MTOM/ Text/ XML
2. Protocol Channels
These channels implement message processing
protocols.
1. HTTP Channel
2. TCP Channel
3. TransitionFlow Channel
4. NamedPipe Channel
5. MSMQ Channel
What
is a Throttling behavior in WCF?
Throttling behavior of the WCF service holds
the configuration for three limitations that control the amount of resources
that your service hosting can allocate to deal with the client request. Thus it
enables to
1. Manages resource Usage
2. Balances performance load
How
can we specify the throttling behavior for a WCF service?
Throttling behavior is specified by the
following three parameters.
1. MaxConcurrentCalls - Total no of concurrent
calls service will accept
2. MaxConcurrentSessions - Total no of
sessionful channels service will accept
3. MaxConcurrentInstances - Total no of
service instances will be created for servicing requests.
It can be specifed either through code or
configuration file. It requires the "System.SystemModel.Behavior"
namespace to be included.
What
is a metadata export?
Metadata Export is the process of describing
the service endpoints and projecting them into a parallel, standardized
representation that clients can use to understand how to use the service.
How to
publish service metadata?
WCF services publish its metadata by exposing
one or more metadata endpoints. Publishing service metadata makes service
metadata available using standardized protocols, such as MEX and HTTP/GET
requests.
Metadata endpoints are the same as other
service endpoints and have an address, a binding, and a contract.
You can add metadata endpoints to a service
host in configuration or in code.
In WCF, suppose you have a derived class
inherited from a datacontract class, will the derived class automatically have
a datacontract as well ?
The Data contract is not inherited, so any
derived class, would have to be explicitly declared as having a Data contract
attribute as well.
In
WCF, if your service wants an authentication before it is used then what is the
best way to handle an authentication mechanism with WCF?
The best way to handle this would be to design
a Message contract that accepts these authentication tokens in the header of
the message.
What
is meant by WS Addressing Standard in WCF ?
The address for an endpoint is a unique URL
that identifies the location of the service. The address should follow the Web
Service Addressing (WS-Addressing) standard, and they are:-
(1) Scheme - This is typically “http” followed
by a colon.
(2) Machine - Identifies the machine name,
which can be a public URL such as “www.google.com" or a local identifier
such as “localhost”.
(3) Port - The optional port number, preceded
by a colon.
(4) Path - The path used to locate the service
files. Typically, this is just the service name, but the path can consist of
more than one level when a service resides in a directory structure.
What
namespace is used by ASMX and WCF respectively for serialization ?
For serialization, WCF uses the
System.Runtime.Serialization namespace for serialization.
Web service(i.e), ASMX uses
System.Xml.serialization namespace.
State
3 Duplex contract problems in WCF ?
(1) Threading problems can occur if either of
the Callback channels are not empty.
(2) If the client and service has a long
running work then this pattern doesn't scale very well. It can block the client
or the service until the process is completes !
(3) It requires a connection back to the
client. And there may be a chance to not connect back due to firewall and
Network Address Translation problems.
Note :- It is always better to use Request /
Response MEP rather than using Duplex method.
Which
command is used to convert WSDL to a proxy
svcutil.exe command will convert the WSDL to a
proxy class for our client
Open visual studio command prompt window
click on visual studio command prompt,set the
current folder to the location where you want the generated proxy and
configuration files to be created.
Run SvcUtil.exe to generate the output files.
What
is MTOM?
MTOM stands for Message Transmission
Optimization Mechanism and is an Interoperable standard that reduces the
overhead for transfer large binary data in WCF. Its a mechanism for
transmitting large binary attachments with SOAP messages as raw bytes.
What
is the purpose of ExtensionDataObject in WCF? or How to make DataContract
forward compatible?
A .NET serialization system supports
backward-compatibility on custom data types naturally. However, sometimes we
also need forward-compatibility for data types used in a WCF
service.ExtensionDataObject property is used to achieve the Forward compatible
in WCF.
What
is RoundTripping ?
A client with an older version (v1.0) of a
data contract can communicate with a service with a newer version(v2.0) of the
same data contract, or a client with a newer version of a data contract can
communicate with an older version of the same data contract. this
new-to-old-to-new interaction is called versioning roundtrip.
Round-tripping guarantees that no data is
lost. WCF does have some built-in support it (IExtensibleDataObject interface).