.Net Interview Questions
رفتن به کانال در Telegram
1 794
مشترکین
+124 ساعت
+207 روز
+4930 روز
آرشیو پست ها
Address - The address where the WCF Service is hosted.
Binding - The binding that decides the protocol, message encoding and security to use. Binding also decides whether to use reliable messaging and transaction support.
Contract - The service contract defines what service operations are available to the client for consumption.
So the Address(A), Binding(B) and Contract(C) are called as the ABC of the service end point.
🚩2️⃣5️⃣7️⃣ What are the 3 things that a WCF Services must have? OR What is the ABC of a WCF service?
The main components of WCF are
1. Service class
2. Hosting environment
3. End point
WCF services are not tightly bound to a particular protocol, encoding format, or hosting environment. All of these are configurable. At the time of designing WCF services, you donot have to worry about what protocol, encoding format, or hosting environment to use to expose the service. you can worry about all these at the time of deployment.
To understand the advantage of using WCF over other distributed programming models like Web Services(ASMX), .NET Remoting, Enterprise Services stack etc, let's consider the following scenario. We have developed an application using web services. As we know web services use HTTP protocl and XML SOAP formatted messages, they are good for developing interoperable applications in a heterogeniuos environment. We have a new client. Our new client is using .NET and he wants binary formmatted messages over TCP protocol, because interoperability is not a concern and binary formmatted messages over TCP protocol are much faster than XML SOAP formmatted messages over HTTP. To satisfy the requirement of this client, now we cannot use our existing web service. So, we have to develop a brand new remoting application from the scratch. The business functionality is the same in web services and remoting application. Since our different clients have different requirements, we ended up creating the same business application using web services and remoting technologies. This approach has several disadvantages as listed below.
1. Developers have to be familiar with two different technologies (Web Services and Remoting).
2. We end up creating duplicate business applications with different technologies which also leads to maintainance overhead.
On the other hand WCF unifies Web Services, .NET Remoting, and Enterprise Services stacks under one roof. For the same requirement that we have seen untill now, we just create one application and expose multiple end points to satisfy the requirements of multiple clients. In WCF configuration drives protocol choices, messaging formats, process allocation, etc. WCF services are loosely coupled, meaning that a WCF service is not bound to a particular protocol, encoding format, or hosting environment. Everything is configurable.
🚩2️⃣5️⃣3️⃣ What is the advantage of using WCF over other distributed programming models like Web Services (ASMX), .NET Remoting, Enterprise Services stack etc.?
Automatic activation means the service starts and serves the request when a message request is received, but the service doesn't need to be running in advance.
There are a few scenarios in which the service needs to be running in advance. For example, in the case of Self-Hosting.
If we have control over the server and client, then the ChannelFactory is a good option because it relies on having local interfaces that actually describes the service i.e. service contract.
On the other hand, if we don't have control over the server and only have a WSDL/URL, then it's better to generate a proxy using Visual Studio or SvcUtil.
SvcUtil is a better option as compared to Visual Studio because we have more control using SvcUtil
🚩2️⃣5️⃣1️⃣ What is the difference between use of ChannelFactory and Proxies in WCF?
A service proxy or simply proxy in WCF enables application(s) to interact with a WCF Service by sending and receiving messages. It's basically a class that encapsulates service details i.e. service path, service implementation technology, platform and communication protocol etc. It contains all the methods of a service contract (signature only, not the implementation). So, when the application interacts with the service through the proxy, it gives the impression that it's communicating a local object.
We can create a proxy for a service by using Visual Studio or the SvcUtil.exe.
WCF
It can be hosted in IIS, Windows service, self-Hosting, Windows activation Service
[ServiceContract] attribute has to be added to the class.
It can be done with Structural or OOPs Programming
One-Way, Request-Response and Duplex are the Operations supported in WCF
System.Runtime.Serialization namespace is needed for Serialization
Encoding:- XML 1.0, MTOM, Binary, Custom
Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
Can be accesses through any Format(SOAP is Default) using (HTTP,TCP/IP, MSMQ, NamedPipes etc).
WCF provides a consistent security programming model for any protocol and it supports many of the same capabilities as IIS and WS-* security protocols, additionally, it provides support for claim-based authorization that provides finer-grained control over resources than role-based security
WCF uses DataContractSerializer which is far better in performance
Can be multithreaded via ServiceBehavior Class
WCF is Heterogeneous. Can communicate with more that one end point at a time.
File extension is .svc
In WCF Services, unhandled exceptions are not returned to clients as SOAP faults. A configuration setting is provided to have the unhandled exceptions returned to clients for the purpose of debugging.
---------------------------------------------------------------------------
Webservices
It can only be hosted in IIS
[WebService] attribute has to be added.
It is a simple procedural programming type
One-Way and Request-response are the Operations supported in WebService.
System.xml.Serialization namespace is needed for Serialization
Encoding:-XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom
Can be accessed through HTTP, TCP, Custom
Uses SOAP over Http only
ASMX Security is limited. Normally authentication and authorization is done using IIS and ASP.NET security configuration and transport layer security.
ASMX web services uses XmlSerializer
Cannot be Multithreaded
It is Homogeneous. Can communicate with one end point only at a time.
File Extension is .asmx
In ASP.NET Web services, unhandled exceptions are returned to the client as SOAP faults.
Webservices
It can only be hosted in IIS
[WebService] attribute has to be added.
It is a simple procedural programming type
One-Way and Request-response are the Operations supported in WebService.
--------------------------------------------------
WCF
It can be hosted in IIS, Windows service, self-Hosting, Windows activation Service
[ServiceContract] attribute has to be added to the class.
It can be done with Structural or OOPs Programming
One-Way, Request-Response and Duplex are the Operations supported in WCF
WCF stands for Windows Communication Foundation (WCF) and is considered as the Microsoft Service-Oriented Architecture (SOA) platform for building distributed and interoperable applications. WCF unifies ASMX, Remoting, and Enterprise Services stacks and provides a single programming model. WCF services are interoperable and supports all the core Web services standards. WCF services also provide extension points to quickly adapt to new protocols and updates and integrate very easily with the earlier Microsoft technologies like Enterprise Services, COM and MSMQ and are released in version 3.0.
