Dot Net

How can we use MSMQ bindings in WCF?

First let’s understand why MSMQ came in to picture and then rest will follow. Let’s take a scenario where your client needs to upload data to a central server. If everything will work fine and if server is available 24 hours to client then there are no issues. In case the server is not available the clients will fail and the data will not be delivered. There’s where MSMQ comes in to picture. It eliminates the need of persistent connection to a server. So what you do is deploy a MSMQ server and let the clients post message to this More >

How can we host a service on two different protocols on a single server?

Let’s first understand what this question actually means. Let’s say we have made a service and we want to host this service using HTTP as well as TCP. You must be wondering why to ever host services on two different types of protocol. When we host a service it’s consumed by multiple types of client and it’s very much possible that they have own protocol of communication. A good service has the capability to downgrade or upgrade its protocol according the client who is consuming him.

Let’s do a small sample in which we will host the ServiceGetCost on TCP and More >

Can you explain duplex contracts in WCF?

In duplex contracts when client initiates an operation the server service provides a reference call back Uri back to the client. So the client initiates a call using the proxy class and when server finishes its work it notifies the client using the callback channel. This is called as duplex messaging in WCF. If you remember in the previous question we had now way to know when the server finished its task.

What is one way operation?

IsOneWay equal to true ensures that the client does not have to wait for the response. So methods marked by IsOneWay to true should always return void. In this the caller does not get anything in return so it is called as one-way communication.

In order to understand one way implementation in WCF lets make a code walkthrough of a sample.

What are different bindings supported by WCF?

WCF includes predefined bindings. They cover most of bindings widely needed in day to day application. But just incase you find that you need to define something custom WCF does not stop you. So let’s try to understand what each binding provides.

BasicHttpBinding: – This binding is used when we need to use SOAP over HTTP. This binding can also be configured to be used as HTTPS. It can be also configured to send data in plain text or in optimized form like MTOM.

Note: – MTOM is discussed in on the questions in this chapter.

WsHttpBinding: – It is same like BasicHttpBinding. More >

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. But Services are flexible. If you make a new version of the service then you need to just expose a new end point. So services are agile and which is a very practical approach looking at the current business trends.

what are the advantages of hosting WCF Services in IIS as compared to self hosting?

There are two main advantages of using IIS over self hosting:-

Automatic activation

IIS provides automatic activation that means 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.

Process recycling

If IIS finds that a service is not healthy that means if it has memory leaks etc, IIS recycles the process. Ok let us try to understand what is recycling in IIS process. For every browser instance a worker process is spawned and the request is More >

How do we host a WCF service in IIS?

First thing you will need is to create the SVC file which exposes the service class. SVC file contains the pointer to the class. You can see from the figure below the class attribute points to the class whose interface is exposed by the service.svc.cs file. Also not the actual interface is in service.svc.cs file. Below figure has both the files service.svc which has the class attribute which points to the service class and the interface which resides in service.svc.cs file. We have taken the same sample which was self hosted in the previous question.

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 ServiceHost class and the service closes when you call the Close of the ServiceHost class.
  • Host in application domain or process provided by IIS Server.
  • Host in Application domain and process provided by WAS (Windows Activation Service) Server.

Note: – This book does not cover the last hosting methodology provided. In the next question we will cover how to host a service in IIS process More >

what is a service contract, operation contract and Data Contract?

In this example we will make simple service which displays the total cost of the complete product group. In simple words this service will take three parameters per product cost, number of products and the product name. In return the service will return the total cost of all the products by multiplying number of products * cost per product. As we go ahead in this explanation we will try to understand all the terminologies which are asked in the above question.

First you need to create a Winfx service project. You can see in the below figure we have selected the More >