WCF SDK

  Home  Applications Programs  WCF SDK


“Learn Windows Communication Foundation (WCF) SDK Interview Questions and Answers”



71 WCF SDK Questions And Answers

1⟩ 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.

 213 views

2⟩ 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.

 271 views

4⟩ 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.

 258 views

5⟩ 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

 213 views

6⟩ 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

 237 views

7⟩ 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.

 222 views

8⟩ 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.

 254 views

9⟩ 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

 235 views

10⟩ 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)

For more details see http://msdn.microsoft.com/en-us/library/bb332338.aspx

 210 views

11⟩ 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>

 258 views

12⟩ 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.

 238 views

13⟩ 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

 236 views

14⟩ 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.

 239 views

15⟩ 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.

 255 views

16⟩ Tell me how to avoid ANR status?

Android allows the system to protect the applications that are not responsive for a period of time by displaying a status called as ANR (Application not responding). Methods should use the main thread for work, as it takes long time for the main thread to complete the task. The work should be divided and another thread named as child thread be used for executing more tasks, as it takes less time. Main thread should provide a handler for child threads to post back upon completion.

 210 views

17⟩ List the file features used in android?

Android is rich in file features and it provides lots of variations in them as well. The file features are as follows:

Intent filters:

Includes bundle of information which describes a desired action.

Icons and Labels:

Includes information for small icon and a text label that can be displayed to users. These are set for an intent filter and are used to represent a component which fulfills the function advertised by the filter.

Permissions:

It is a restriction or limitation access to a part of code or data on the device. It is given as:-android.permission.CALL_EMERGENCY_NUMBERS

Libraries:

It includes the basic packages for building and developing applications.

 202 views

18⟩ Define localization and how to achieve?

Localization is a way of representing the products in different languages. Android is an operating system which runs in many regions, so to reach different users localization is a must. Localization in Android can be achieved by incorporating different languages in the application which you are using. To do this knowledge of Java, XML elements, Activity lifecycle and general principles of internationalization and localization are required.

 205 views

19⟩ Define Android Application Architecture?

Android application architecture allows the simplification and reuse of any application. It provides a better way to publish the capabilities of the application so that any other application can make good use of those capabilities.

This architecture includes the following components:

Intent: perform some operation on some activity and service

Resource Externalization - such as strings and graphics

Notification signaling users - light, sound, icon etc.

Content Providers - sharing of data between various applications

 227 views

20⟩ Which dialog boxes are supported by android?

There are 4 dialog boxes which have been supported by Android.

These are as follows:

AlertDialog:

It supports 0 to 3 buttons with a list of select-able elements that includes check boxes and radio buttons.

ProgressDialog:

It displays the progress of any dialog or application. It is an extension of AlertDialog and supports adding buttons.

DatePickerDialog:

It is used to give provision to the user to select the date

TimePickerDialog:

It is used to give provision to the user to select the time

 255 views