1.What is an
Endpoint? How to configure an end point in WCF Application? Is it possible to
create an end point dynamically?
An Endpoint is the interface through which the Business
Services are exposed to external world. Each Endpoint in a WCF application
consists of following things:
(a) Address – An
address is the URL through which the client applications interact with the
services. The Address can be configured in the Configuration file of the
Service application.
(b) Binding – A
Binding is the one that decides how client applications can interact with the
Services. This is used to specify transport, encoding and protocol details
required for client applications and services to communicate each other.
(c) Contract – A
Contract is the service which is supposed to be exposed to the external world
that client applications consume.
Configuring Endpoint in the Configuration File:
<endpoint
address="http://localhost/SampleServices/Service"
binding="basicHttpBinding"
contract="SampleService.IService" />
Creating an Endpoint Programmatically:
Sometimes we might have to create the Endpoints through the
program based on business requirements. An equivalent C# code which would
create the end point from the code looks like below:
string
serviceAddress = "http://localhost/SampleServices/Service";
BasicHttpBinding basicHBinding = new BasicHttpBinding();
using
(ServiceHost hostService = new ServiceHost(typeof(Service1)))
{
hostService.AddServiceEndpoint(typeof(IService1), basicHBinding,
serviceAddress);
}
Note that the above code snippet needs to be placed in the
Host Application which hosts the WCF services.
2.What are bindings
in a Service? How many types of bindings are available?
A Binding is the one that decides how client applications
can interact with the Services. This is used to specify transport, encoding and
protocol details required for client applications and services to communicate
each other.
All the binding configurations should be set in a separate
section with the name “bindings” in the configuration file. This section is
under the main section:
<system.serviceModel>
<bindings>
</bindings>
</system.serviceModel>
You can define more than one binding configuration inside
the “bindings” section.
There are many types of bindings available by default in WCF
framework. Out of these, primarily four bindings are very commonly used. They
are:
(a)
BasicHTTPBinding – This binding is used for basic web service
communication. This is mainly used for interoperability. No security is
available with this binding. The medium of communication is through web (HTTP
protocol). The typical configuration settings for this binding looks like
below:
<bindings>
<basicHttpBinding>
<binding
name="sampleBasicHttpBinding">
</binding>
</basicHttpBinding>
</bindings>
The above section gives the flexibility to give name to your
configuration settings. You could reuse this configuration setting in one or
more endpoint (use the name of the binding on the “binding” attribute in your
end point).
(b) WsHTTPBinding –
This binding is used for secure, reliable, interoperable binding. This binding
is used for a web service with WS-* support like WS-Reliable Messaging for
reliability, and WS-Security for message security and authentication. To
simplify, this web service is used whenever you need some kind of security to
you basic web service. The medium of communication is through web (HTTP
protocol). The configuration for this type of binding starts like this:
<bindings>
<wsHttpBinding>
<binding
name="sampleWsHBinding">
</binding>
</wsHttpBinding>
</bindings>
(c)
MsmqIntegrationBinding – This binding is used when the WCF Service needs
to interact with the MSMQ. The service with this binding can listen to the MSMQ
and read or insert messages into the queue. The client applications insert the
messages into a queue and the service can read the message from the queue. The
medium of communication is through MSMQ in this case. The configuration for
this type of binding starts like this:
<bindings>
<msmqIntegrationBinding>
<binding
name="sampleMsmqBinding">
</binding>
</msmqIntegrationBinding>
</bindings>
(d) NetTcpBinding –
This binding is used when the communication between two applications on two
computers which are directly connected. This binding uses TCP protocol for
communication. The configuration for this type of binding starts like this:
<bindings>
<netTcpBinding>
<binding
name="sampleNetTcpBinding">
</binding>
</netTcpBinding>
</bindings>
Along with the already built-in bindings, the WCF framework
also allows the developers to create custom bindings.
4.What is the
difference between BasicHttpBinding and WsHttpBinding? When do you use what?
Following are the differences between BasicHttpBinding and
WsHttpBinding. They are:
(a)
BasicHttpBinding supports wide variety of clients (like clients built on
.NET, PHP, RUBY etc) whereas WsHttpBinding has limited compatibility to client
applications that were built on various technologies
(b)
BasicHttpBinding sends the messages in plain text by default over the
network where as WsHttpBinding sends them in an encrypted format by default
over the network
(c)
BasicHttpBinding cannot send reliable messaging whereas WsHttpBiding
does it.
(d) BasicHttpBiding
cannot support PerSession Instance Context mode where WsHttpBinding does.
5.Why an interface is
required to define the Service Contract and Operation Contract?
It is always a best practice to program to an interface
rather than programming to an implementation. As WCF service is invoked by wide
variety of clients, it is always better to expose the Interface rather than the
implementation. This give you the flexibility to change the implementation as
per your business node without any impact on the client applications since the
client applications are aware of the interface only and does not the implementation
class (neither its name or namespace).
6.What is Service Behavior? What role does it play? How to
configure the behavior of a Service?
Service Behavior is the configuration setting that decides
the execution behavior of the Service. For example, if you would like the
Service to use the single instance of its implementation all the time, this can
be achieved by configuring the service behavior accordingly.
The behavior of the service can be controlled by placing a
ServiceBehavior attribute on top of the Service implementation. For example,
below code shows how the ServiveBehavior attribute can be placed on top of a
Service implementation.
[ServiceBehavior()]
public class Service1 : IService1
{
[OperationContract]
public string
GetData(int value)
{
return
string.Format("You entered: {0}", value);
}
}
If you notice the ServiceBehavior attribute in the above
code snippet, it is a blank attribute. There are many properties that can be
defined within this ServiceBehavior attribute. Few of the important properties
are:
(a) ConcurrencyMode
(b)
IncludeExceptionDetailInFaults
(c)
InstanceContextMode
(d) Name
(e) Namespace
Service Behavior can also be configured from the
Configuration file. The below sample configuration gives an idea of how it can
be done:
<behaviors>
<serviceBehaviors>
<behavior
name="sampleBehavior">
</behavior>
</serviceBehaviors>
</behaviors>
The configured behavior can be attached to the end point in
the below fashion:
<endpoint
address="http://localhost/SampleServices/Service"
binding="basicHttpBinding"
contract="SampleService.IService"
behaviorConfiguration=" sampleBehavior"/>
7.What are different
Instance Context Modes available in WCF and when do you use what? How to
configure them in the code?
Instance Context Mode settings control the services
instances created for the client requests. There are three Instance Context
modes that can be set. They are:
(a) PerCall
(b) PerSession
(c) Single
When the service is configured to run on PerCall instance
context mode, the below program returns the output as “1” always.
[ServiceBehavior(InstanceContextMode =
InstanceContextMode.PerCall)]
public class
Service1 : IService1
{
int counter =
0;
[OperationContract]
public string
GetData(int value)
{
counter ;
return counter.ToString();
}
}
8.When the service is
configured to run on PerSession instance context mode, the below program holds
the value of “counter” variable as long as the client proxy object is live and
increments it in each call. For example, if you call GetData method 10 times
using the same Client Object, the value returned will be 10 on tenth call.
[ServiceBehavior(InstanceContextMode =
InstanceContextMode.PerSession)]
public class
Service1 : IService1
{
int counter =
0;
[OperationContract]
public string
GetData(int value)
{
counter ;
return
string.Format("You entered: {0}", counter.ToString());
}
}
When the service is configured to run on Single Instance
Context mode, the below program holds the value of “counter” variable forever
irrespective of the client application that is calling it. For example, Client
A calls the below program 10 times and Client B calls the below service 10
times. The value that is returned to Client B on its 10th call will be 20 and
not 10 or 1.
[ServiceBehavior(InstanceContextMode =
InstanceContextMode.Single)]
public class
Service1 : IService1
{
int counter =
0;
[OperationContract]
public string
GetData(int value)
{
counter ;
return
string.Format("You entered: {0}", counter.ToString());
}
}
9.What is Concurrency
Mode and how does that impact the Service behavior?
Concurrency Mode settings control whether an instance of a
Service Application processes messages sequentially or concurrently.
There are three modes available. They are:
(a) Single – each
service processes one message at a time
(b) Multiple – each
service processes multiple messages concurrently
(c) Reentrant –
each service instance processes one message at a time, but accepts the calls
concurrently when the current message call is calling out.
The Concurrency Mode can be set using the ServiceBehavior
attribute. The below code snippet shows an example.
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
public class
Service1 : IService1
{
int counter =
0;
[OperationContract]
public string
GetData(int value)
{
counter ;
return
string.Format("You entered: {0}", counter.ToString());
}
}
10.What is WCF
Throttling? How do you configure the code to throttle based on the need?
Throttling provides an ability to control the number of
calls that the WCF service can handle. Throttling Settings limits the number of
concurrent calls that can be made to the service and concurrent instances
created at the service end and this provides an ability to configure the
service to make use of resource effectively.
The below configuration settings control the number of
calls, instances and sessions that can be made to the Service.
<serviceBehaviors>
<behavior
name="sampleBehavior">
<serviceThrottling maxConcurrentCalls="10"
maxConcurrentInstances="10"
maxConcurrentSessions="10"/>
</behavior>
</serviceBehaviors>
To look in more detail into this setting, “maxConcurrentCalls
= 10” setting allows only maximum of 10 concurrent calls to be made to the
Service method. Any other call that is coming to the service needs to wait
until, at least one of the call in the above 10 calls is complete.
11.How does tracing
and logging of WCF service can be configured?
All you need to do is make some configuration settings to
enable tracing and logging in WCF. The service logging and tracing can be
easily configured using the inbuilt tool – (svcConfigEditor.exe). Open the WCF
Application configuration file from this tool and configure the settings.
How to make WCF Services operate on multiple threaded?
This can be achieved by using WCF Throttling. Refer to
Question #8.
How to define the behavior of a WCF service based on the
load?
This can be achieved by using WCF Throttling. Refer to
Question #8.
How to increase the response message size in a WCF Service?
When you have a large amount of data that needs to be
returned from the Service application to the client application, at times the
service throws an exception stating that the message not former properly. This
is because of the message size settings configured in the configuration file.
Below configuration setting provides an idea on where to change the configuration
settings:
<bindings>
<netTcpBinding>
<binding
name="sampleNetTcpBinding" maxReceivedMessageSize="" >
</binding>
</netTcpBinding>
</bindings>
Under the binding node, the “maxReceivedMessageSize”
attribute needs to be configured properly.
12.How to increase
the request time out in WCF Service?
If the service application takes long time to respond a
request, the request might timeout on the client side before the service
application returns the response. This can be handled by configuring the
receiveTimeout attribute properly. Below configuration settings show how:
<bindings>
<netTcpBinding>
<binding
name="sampleNetTcpBinding" receiveTimeout="">
</binding>
</netTcpBinding>
</bindings>
12.How to hide a
property defined inside a DataContract class?
DataContract is the attribute placed on top of the customer
data objects (composite data types) to make them serializeable. As you know,
the response from the service is always serialized and sent back to the client.
Below code snippet shows how to do this:
[DataContract]
public class
CompositeType
{
}
When this attribute is placed on top of the object
CompositeType, the object can be recognized at the client application end.
Now come to the properties inside the CompositeType, every
property inside this class needs to be decorated with the attribute “DataMember”,
to have the property recognized at the client end. If no “DataMember” attribute
is placed, the propertly is not visible at client application end. Following
code snippet shows how to do this.
[DataContract]
public class
CompositeType
{
bool boolValue
= true;
string
stringValue = "Hello ";
[DataMember]
public bool
BoolValue
{
get {
return boolValue; }
set {
boolValue = value; }
}
[DataMember]
public string
StringValue
{
get {
return stringValue; }
set {
stringValue = value; }
}
}
13.How to enable
Sessions usage in WCF Service?
Session based call can be achieved using PerSession Instance
Context mode. But please note that PerSession Instance Context mode is not
supported by the BasicHttpBinding. If there is a specific need for running the
service on BasicHttpBinding for better interoperability, then there is an
alternative to enable sessions at the level of BasicHttpBinding by enabling
ASP.NET Sessions at Service level. The ASP.NET Compatibility can be set by
placing the attribute “AspNetCompatibilityRequirements” on top of the Service
Implementation. Below code snippet explains how to do this:
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Required)]
public class
Service1 : IService1
{
int counter =
0;
[OperationContract]
public string
GetData(int value)
{
counter ;
return
string.Format("You entered: {0}", counter.ToString());
}
}
14.What is the
difference between Service endpoint and Client endpoint?
Endpoint in WCF
service is the combination of three things address, binding and contract.
Service endpoint is for the server, server where your WCF service is hosted.
Service endpoint defines where the service is hosted, what are the bindings and
the contract i.e. methods and interfaces.
While client endpoint
is for the client. Client endpoint specifies which service to connect, where
it's located etc.
15.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.
16.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.
17.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
18.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.
19.Where we can host
WCF services?
Every WCF services
must be hosted somewhere. There are three ways of hosting WCF services.
They are
1. IIS
2. Self Hosting
3. WAS (Windows
Activation Service)
20.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.
21.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.
22.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.
23.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
24.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
25.What are different
elements of WCF Srevices 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>
26.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.
27.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
28.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.
29.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.
30. 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)
Q32. 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.
Q33. 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.
Q34. 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:
Q35. 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
Q36. 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
Q37. What are the various ways of hosting a WCF Service?
a)IIS
b)Self Hosting
c)WAS (Windows Activation Service)
Q38. What 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
Q39. 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
Q40.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.
Q41.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.
Code Below show How to create a Service Contract:
Code:
[ServiceContract]
Public Interface IEmpOperations
{
[OperationContract]
Decimal Get EmpSal(int EmpId);
}
Class MyEmp: IEmpOperations
{
Decimal Get EmpSal()
{
// Implementation of this method.
}
}
42.What is the difference WCF and Web services?
Web services can only be invoked by HTTP. While Service or a WCF component can be invoked
by any protocol and any transport type. Second web services are not flexible. However, 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.
43.What are the main components of WCF?
The main components of WCF are
1. Service class
2. Hosting environment
3. End point
44.Where we can host WCF services?
Every WCF services must be hosted somewhere. There are three ways of hosting WCF services.
They are
1. IIS
2. Self Hosting
3. WAS (Windows Activation Service)
45.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.
46.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, TCP binding, Peer network binding, IPC binding, Web Service (WS) binding, Federated WS binding, Duplex WS binding, MSMQ binding, MSMQ integration binding).
47.what are the various ways of hosting a WCF service?
There are three major ways to host a WCF service:-
• Self-hosting the service in his own application domain. This we have already covered in
the first section. 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.
48.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
49.What 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
50.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
51.How to test the WCF Service?
We can use the WCF Test client to test the WCF Service. Tool enables users to input test parameters, submit that input to the service, and view the response.
We can use the following command at command line. wcfTestClient.exe URI1 URI2 …
52.What are SOAP Faults in WCF?
Common language runtime (CLR) exceptions do not flow across service boundaries. At the maximum, a CLR exceptions may propagate up to the service tier from business components. Unhandled CLR exceptions reach the service channel and are serialized as SOAP faults before reporting to clients. An unhandled CLR exception will fault the service channel, taking any existing sessions with it. That is why it is very importatnt to convert the CLR exceptions into SOAP faults. Where possible, throw fault exceptions
53.What happens if there is an unhandled exception in WCF?
If there is an unhandled exception in WCF, the the service model returns a general SOAP fault, that does not include any exception specific details by default. However, you can include exception details in SOAP faults, using IncludeExceptionDetailsInFaults attribute. If IncludeExceptionDetailsInFaults is enabled, exception details including stack trace are included in the generated SOAP fault. IncludeExceptionDetailsInFaults should be enabled for debugging purposes only. Sending stack trace details is risky.
No comments:
Post a Comment