WCF Interview Questions and Answers (209) - Page 6

Can we use both WCF Services and WCF Data Services in a single service ?

NOTE: This is objective type question, Please click question title for correct answer.
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 the Open 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.



Thanks and Regards
Akiii
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.



Thanks and Regards
Akiii
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.




Thanks and Regards
Akiii
How is WCF One Way Contract is implemented ?

WCF one way contract is implemented via "IsOneWay = true/false" attribute.
For example :-

[ServiceContract]

interface IMyContract
{
[OperationContract(IsOneWay = true)]
void MyMethod( );
}




Thanks and Regards
Akiii
In WCF, what is the default value of IsOneWay property ?

NOTE: This is objective type question, Please click question title for correct answer.
In WCF, while using one way contract, suppose a client invokes a method and the server while executing it, encounters an error. Will the error message propagate to the client or will the client ever know that there was an error on the server side ?

No, one-way operations cannot return values and any exception thrown on the service side will not make its way to the client. The client will never know whether there was an error or not !




Thanks and Regards
Akiii
Is the below code correct :- [ServiceContract] interface IMyContract { [OperationContract(IsOneWay = true)] int MyMethod( ); }

No, there should be no reply associated with a one-way operation. In the above an integer value is returned even though the IsOneWay property is true !



Thanks and Regards
Akiii
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.


Please note that the above is a bad design because clients are never meant to be blocked when using one way contract.


Thansks and Regards
Akiii
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.


Thanks and Regards
Akiii
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



Thanks and Regards
Akiii
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.



Thanks and Regards
Akiii
Can you show a sample of Duplex Contract in WCF ?


[ServiceContract(Namespace = "http://www.Microsoft.com",
SessionMode = SessionMode.Required,
CallbackContract = typeof(IDuplexCallBack) )]

public interface IService1
{
[OperationContract(IsOneWay = true)]
void getData();
}

public interface IDuplexCallBack
{
[OperationContract(IsOneWay = true)]
void filterData(DataSet Output);
}


In the above code, getData() is a method which will be called by the client on the Service. This getdata() is implemented in the server side.

filterData() is a method which will be called by the server on the Client. This method is implemented in the client side.

CallbackContract is the name of the contract which will be called by the server on the client to raise an event or to get some information from the client.



Thanks and Regards
Akiii
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.

So finally, both are different but related concepts
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.

You can use use AppFabric in place of Memcached because AppFabric provides more feature than Memcached
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 is WCF.

WCF is Windows Communication Foundation that uses message based communication. Messages will be sent between endpoints generated by Client or Service.
It ia an advanced version of the below technologies as these require
specialized knowledge and service to implement.

1. ASP .NET Web services(.asmx)
2. Remoting
3. MSMQ (Microsoft Message Queue)
4. Enterprise Services

WCF simplifies developer's task by unifying the strength of each .NET technology for network distributed services and applications

Thanks and Regards,
Gayathri P
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories