All java c# .net servlet jdbc c sqlserver android javascript php wcf clearcase angularjs 2

Explain the difference between classic web services (ASMX) and WCF?

ASMX is:

  • easy and simple to write and configure
  • only available in IIS
  • only callable from HTTP

WCF can be:

  • hosted in IIS, a Windows Service, a Winforms application, a console app - you have total freedom
  • used with HTTP (REST and SOAP), TCP/IP, MSMQ and many more protocols
ASMX Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type. Second, ASMX web services are not flexible. However, WCF 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. We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc

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 there 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 HTTP protocol.

Once we are done the server side coding its time to see make a client by which we can switch between the protocols and see the results. Below is the code snippet of the client side for multi-protocol hosting

WCF services that arej hosted under IIS. This feature is not enabled by default. To enable it you must add the multipleSiteBindingsEnabled attribute to the element in your Web.config file and set it to true, as shown in the following example. XML When hosting a WCF service under IIS, IIS creates one base address for you based on the URI to the virtual directory that contains the application. You can add additional base addresses that use the same protocol by using Internet Information Services Manager to add one or more bindings to your Web site. For each binding specify a protocol (HTTP or HTTPS), an IP address, a port, and a host name. For more information about using Internet Information Services Manager, see IIS Manager (IIS 7). For more information about adding bindings to a site, see Create a Web Site (IIS 7)

Explain the components used in WCF

Below are the essential components of WCF –

  • Service class
  • End point
  • Hosting Environment

WCF Service is composed of three components:

Service class: It implements the service needed.

Host environment:It is an environment that hosts the developed service.

Endpoints: This are the connection points for the clients to connect to the service. Clients find the end points through three components like service contract, binding, and address.

A WCF service has at least following core components. Service Class: A service class implementing in any CLR-based language and expose at least one method. Hosting Environment: a managed process for running service. Endpoint: a client uses it to communicate with service.

Define Service Contracts and Operation Contracts in WCF?

there 2 type of contract Service Contract Operation Contract

A Service Contract basically describes the operations a service exposes to another party (in other words a client). We can map a WCF Service Contract to a Web Service Description Language (WSDL).

It's recommended to apply the ServiceContract attribute to an interface, although it can be applied to a class as well. Applying it to an interface provides us a clear separation of contract and its implementation.

It describes:

  • What operations are exposed by the service
  • Platform independent description of the interface as well as methods of our service
  • A Message Exchange Pattern (MEP) between the parties, in other words Request/Response, One-Way or Duplex. Please follow here for a detailed description of MEPs.

To define a Service Contract, we will apply the ServiceContract attribute to a .NET Interface and OperationContract attribute to methods 

Explain dependency properties?

CLR property is just a wrapper around private variables. It uses Get / Set methods to retrieve and store value of a variable into it. So to be frank with you, a CLR property gives you only one block in which you can write code to invoke whenever a property is get or set. Hence CLR property system is fairly straightforward. On the other hand, the capabilities of Dependency property system is huge. The idea of Dependency property is to compute the value of the property based on the value of other external inputs. The external inputs might be styles, themes, system properties, animations, etc. So, you can say a dependency property works with most of the WPF inbuilt features that were introduced.
A Dependency Property is a property whose value depends on the external sources, such as animation, data binding, styles, or visual tree inheritance. Not only this, but a Dependency Property also has the builtin feature of providing notification when the property has changed, data binding and styling.

What is Self Hosting in WCF?

We have our project (it may be Windows or a web application or something else) and we want to host one WCF service within this solution locally. This type of hosting is called Self-Hosting. To implement self-hosting we need to include System.Service.Model.ServiceHost namespace.

We can host a WCF service in IIS and a Windows service also. A service can also be in-process, in other words the client and service are in the same process. Now let's create the WCF Service that is hosted in a console application.

Define Clients and Servers?

  • A Client is generally a single user PC or workstation that provides a highly user friendly interface to the end user. It runs client processes, which send service requests to the server.
  • A Server is generally a relatively large computer that manages a shared resource and provides a set of shared user services to the clients. It runs the server process, which services client requests for use of the resource managed by the server. The network may be a single LAN or WAN or an internet of networks.

      A client is the requesting program or user in a client/server relationship. For example, the user of a Web browser is effectively          making client requests for pages from servers all over the Web. The browser itself is a client in its relationship with the computer that is getting and returning the requested HTML file. The computer handling the request and sending back the HTML file is a server.

A server is a computer designed to process requests and deliver data to other(client) computers over a local network or the internet.

WCF ChannelFactory caching

Before the inner channel (the transparent proxy) of ClientBase is created, the caching logic for the current ClientBase can be disabled if other public properties (such as ChannelFactory, Endpoint, and ClientCredentials) are accessed.
Use the ChannelFactory to create an instance of the factory, then cache that instance. You can then create communicatino channels as needed/desired from the cached istance. Do you have a need for multiple channel factories (i.e.., are there multiple services)? In my experience, that's where you'll see the biggest benefit in performance. Creating a channel is a fairly inexpensive task; it's setting everything up at the start that takes time.I have a static helper class in my application, and within that class I have a dictionary and a method to create communication channels from the channelf factory. public static Dictionary OpenChannels { get { if (Cache["OpenChannels"] == null) { Cache["OpenChannels"] = new Dictionary(); } return (Dictionary)Cache["OpenChannels"]; } set { Cache["OpenChannels"] = value; } }

What is WCF Messaging Layer?

Messaging layer is composed of channels. A channel is a component that processes a message in some way. Channels are the core abstraction for sending messages to and receiving messages from an Endpoint. 

Message Structure:

WCF uses messages to pass data or exchange information from one point to another. All messages are SOAP messages. The basic structures of a SOAP message are made up of three components.

SOAP Envelope: 

The SOAP envelope is a container for the two most important pieces of a SOAP message, the SOAP header and the SOAP body. A SOAP envelope contains several pieces of key information in the form of elements. 

SOAP Header:

Using a SOAP header, we can pass useful information about the services to the outer world if needed; it's just for information sharing. Any child elements of the header element are called "header blocks". This provides a mechanism for grouping logical data together.

SOAP Body:

This element contains the actual SOAP message for communication with the SOAP receiver; a message can contain zero or more bodies. Any information intended to be exchanged when the message reaches the intended destination goes in the message body.

A messaging layer is a packet of data containing several pieces of important information being routed from a source to a destination. All messages are formatted in XML. Message Structure. WCF uses messages to pass data or exchange information from one point to another. All messages are SOAP messages.

Explain what are the MEPs available in WCF?

MEP stand for Message Exchange Pattern, three types of message exchanged patterns are allowed. Data Gram Request and Response Duplex
Message Exchange Patterns describes the way of communication between Client and Server means how client and server would be exchange messages to each other. There are three types of message exchange patterns Request-Reply: In this communication, client sends the message to the service and waits for reply from the service. Within a ReceiveTimeout period (default timeout is one minute). One-Way: In this communication, client sends the message to the service and doesn't wait for reply from the service. In this pattern, receiver doesn’t send any response to the sender, even if any error occurs in the communication. Duplex: In this communication, client and services can sends messages to each other by using One-way or request-reply messaging.

MEP stand for Message Exchange Pattern, three types of message exchanged patterns are allowed :-

  • Data Gram
  • Request and Response
  • Duplex