WCF Windows Communication Foundation
Q1. What is WCF?
WCF stands for Windows Communication Foundation. It is a Software
development kit for developing services on Windows. WCF is introduced in
.NET 3.0. in the System.ServiceModel namespace. WCF is based on basic
concepts of Service oriented architecture (SOA)
Q2. What is endpoint in WCF service?
The endpoint is an Interface which defines how a client will communicate
with the service. It consists of three main points: Address,Binding and
Contract.
Q3. Explain Address,Binding and contract for a WCF Service?
Address:Address defines where the service resides.
Binding:Binding defines how to communicate with the service.
Contract:Contract defines what is done by the service.
Q4. What are the various address format in WCF?
a)HTTP Address Format:--> http://localhost:
b)TCP Address Format:--> net.tcp://localhost:
c)MSMQ Address Format:--> net.msmq://localhost:
Q5. What are the types of binding available in WCF?
A binding is identified by the transport it supports and the encoding it
uses. Transport may be HTTP,TCP etc and encoding may be text,binary
etc. The popular types of binding may be as below:
a)BasicHttpBinding
b)NetTcpBinding
c)WSHttpBinding
d)NetMsmqBinding
Q6. What are the types of contract available in WCF?
The main contracts are:
a)Service Contract:Describes what operations the client can perform.
b)Operation Contract : defines the method inside Interface of Service.
c)Data Contract:Defines what data types are passed
d)Message Contract:Defines wheather a service can interact directly with messages
Q7. What are the various ways of hosting a WCF Service?
a)IIS b)Self Hosting c)WAS (Windows Activation Service)
Q8. WWhat is the proxy for WCF Service?
A proxy is a class by which a service client can Interact with the service.
By the use of proxy in the client application we are able to call the different methods exposed by the service
Q9. How can we create Proxy for the WCF Service?
We can create proxy using the tool svcutil.exe after creating the service.
We can use the following command at command line.
svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config
Q10.What is the difference between WCF Service and Web Service?
a)WCF Service supports both http and tcp protocol while webservice supports only http protocol.
b)WCF Service is more flexible than web service.
Q11.What is DataContract and ServiceContract?Explain
Data represented by creating DataContract which expose the
data which will be transefered /consumend from the serive
to its clients.
**Operations which is the functions provided by this
service.
To write an operation on WCF,you have to write it as an
interface,This interface contains the "Signature" of the
methods tagged by ServiceContract attribute,and all methods
signature will be impelemtned on this interface tagged with
OperationContract attribute.
and to implement these serivce contract you have to create
a class which implement the interface and the actual
implementation will be on that class
const
and readonly
perform a similar function on data members, but they have a few important differences.
const
A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the
const
keyword and must be initialized as they are declared. For example;
public class MyClass
{
public const double PI = 3.14159;
}
PI
cannot be changed in the application anywhere else in the code as this will cause a compiler error.
Constants must be a value type (
sbyte
,
byte
,
short
,
ushort
,
int
,
uint
,
long
,
ulong
,
char
,
float
,
double
,
decimal
, or
bool
), an enumeration, a string literal, or a reference to
null
.
Since classes or structures are initialized at run time with the
new
keyword, and not at compile time, you can't set a constant to a class or structure.
Constants can be marked as
public
,
private
,
protected
,
internal
, or
protected internal
.
Constants are accessed as if they were static fields, although they cannot use the
static
keyword.
To use a constant outside of the class that it is declared in, you must fully qualify it using the class name.
readonly
A read only member is like a constant in that it represents an unchanging value. The difference is that a
readonly
member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared. For example:
public class MyClass
{
public readonly double PI = 3.14159;
}
public class MyClass
{
public readonly double PI;
public MyClass()
{
PI = 3.14159;
}
}
Because a
readonly
field can be initialized either at the declaration or in a constructor,
readonly
fields can have different values depending on the constructor used. A
readonly
field can also be used for runtime constants as in the following example:
public static readonly uint l1 = (uint)DateTime.Now.Ticks;
Notes
-
readonly
members are not implicitly static
, and therefore the static
keyword can be applied to a readonly
field explicitly if required.
- A
readonly
member can hold a complex object by using the new
keyword at initialization.
static
Use of the
static
modifier to declare a
static
member, means that the member is no longer tied to a specific object.
This means that the member can be accessed without creating an instance
of the class. Only one copy of
static
fields and events exists, and
static
methods and properties can only access
static
fields and
static
events. For example:
public class Car
{
public static int NumberOfWheels = 4;
}
The
static
modifier can be used with classes, fields,
methods, properties, operators, events and constructors, but cannot be
used with indexers, destructors, or types other than classes.
static
members are initialized before the
static
member is accessed for the first time, and before the
static
constructor, if any is called. To access a
static
class member, use the name of the class instead of a variable name to specify the location of the member. For example:
int i = Car.NumberOfWheels;