1. What is the difference between WCF and ASMX Web Services?
Simple and basic difference is that ASMX or ASP.NET web service is designed to send and receive messages using SOAP over HTTP only. While WCF can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).
Another tutorial WCF Vs ASMX has detailed discussion on it.
2. What are WCF Service Endpoints? Explain.
For Windows Communication Foundation services to be consumed, it’s necessary that it must be exposed; Clients need information about service to communicate with it. This is where service endpoints play their role.
A WCF service endpoint has three basic elements i.e. Address, Binding and Contract.
Address: It defines "WHERE". Address is the URL that identifies the location of the service.
Binding: It defines "HOW". Binding defines how the service can be accessed.
Contract: It defines "WHAT". Contract identifies what is exposed by the service.
3. What are the possible ways of hosting a WCF service? Explain.
For a Windows Communication Foundation service to host, we need at least a managed process, a ServiceHost instance and an Endpoint configured. Possible approaches for hosting a service are:
Hosting in a Managed Application/ Self Hosting
Console Application
Windows Application
Windows Service
Hosting on Web Server
IIS 6.0 (ASP.NET Application supports only HTTP)
Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP, NamedPipes, MSMQ.
4. How we can achieve Operation Overloading while exposing WCF Services?
By default, WSDL doesn’t support operation overloading. Overloading behavior can be achieved by using "Name" property of OperationContract attribute.
Collapse | Copy Code
[ServiceContract]
interface IMyCalculator
{
[OperationContract(Name = "SumInt")]
int Sum(int arg1,int arg2);
[OperationContract(Name = "SumDouble")]
double Sum(double arg1,double arg2);
}
When the proxy will be generated for these operations, it will have 2 methods with different names i.e. SumInt and SumDouble.
5. What Message Exchange Patterns (MEPs) supported by WCF? Explain each of them briefly.
1. Request/Response 2. One Way 3. Duplex
Request/Response
It’s the default pattern. In this pattern, a response message will always be generated to consumer when the operation is called, even with the void return type. In this scenario, response will have empty SOAP body.
One Way
In some cases, we are interested to send a message to service in order to execute certain business functionality but not interested in receiving anything back. OneWay MEP will work in such scenarios. If we want queued message delivery, OneWay is the only available option.
Duplex
The Duplex MEP is basically a two-way message channel. In some cases, we want to send a message to service to initiate some longer-running processing and require a notification back from service in order to confirm that the requested process has been completed.
6. What is DataContractSerializer and How its different from XmlSerializer?
Serialization is the process of converting an object instance to a portable and transferable format. So, whenever we are talking about web services, serialization is very important.
Windows Communication Foundation has DataContractSerializer that is new in .NET 3.0 and uses opt-in approach as compared to XmlSerializer that uses opt-out. Opt-in means specify whatever we want to serialize while Opt-out means you don’t have to specify each and every property to serialize, specify only those you don’t want to serialize. DataContractSerializer is about 10% faster than XmlSerializer but it has almost no control over how the object will be serialized. If we wanted to have more control over how object should be serialized that XmlSerializer is a better choice.
7. How we can use MessageContract partially with DataContract for a service operation in WCF?
MessageContract must be used all or none. If we are using MessageContract into an operation signature, then we must use MessageContract as the only parameter type and as the return type of the operation.
8. Which standard binding could be used for a service that was designed to replace an existing ASMX web service?
The basicHttpBinding standard binding is designed to expose a service as if it is an ASMX/ASP.NET web service. This will enable us to support existing clients as applications are upgrade to WCF.
9. Please explain briefly different Instance Modes in WCF?
WCF will bind an incoming message request to a particular service instance, so the available modes are:
Per Call: instance created for each call, most efficient in term of memory but need to maintain session.
Per Session: Instance created for a complete session of a user. Session is maintained.
Single: Only one instance created for all clients/users and shared among all.Least efficient in terms of memory.
10. Please explain different modes of security in WCF? Or Explain the difference between Transport and Message Level Security.
In Windows Communication Foundation, we can configure to use security at different levels
a. Transport Level security means providing security at the transport layer itself. When dealing with security at Transport level, we are concerned about integrity, privacy and authentication of message as it travels along the physical wire. It depends on the binding being used that how WCF makes it secure because most of the bindings have built-in security.
Collapse | Copy Code
<netTcpBinding>
<binding name="netTcpTransportBinding">
<security mode="Transport">
<Transport clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
b. Message Level Security For Tranport level security, we actually ensure the transport that is being used should be secured but in message level security, we actually secure the message. We encrypt the message before transporting it.
<wsHttpBinding>
<binding name="wsHttpMessageBinding">
<security mode="Message">
<Message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
It totally depends upon the requirements but we can use a mixed security mode also as follows:
Collapse | Copy Code
<basicHttpBinding>
<binding name="basicHttp">
<security mode="TransportWithMessageCredential">
<Transport />
<Message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
There is scenerio, when one client has to access service SOAP using Http and other client have to access Binary using TCP, how can you acheive?
This can be acheived by adding extra endpoint in configuration file.
<endpoint address="http://locahost:8090/Service" contact="IMathService" binding="wsHttpBinding"/>
<endpoint address="net.tcp://locahost:8080/Service" contact="IMathService" binding="netTcpBinding"/>
What is Service Host in WCF?
Service Host object is in process of hosting the WCF service and registering endpoints. It loads the service configuration endpoints, apply the settings. System.ServiceModel.ServiceHost namespace holds this object. This object is created while self hosting the WCF service.
Difference between WCF and Web Service?
1) Web Services support hosting in IIS whereas WCF support hosting in IIS, WAS and Self-hosting.
2) Web Services can be invoked by Http whereas WCF service can be invoked by Http, Tcp, Named Pipes, MSMQ.
3) WCF Services are more reliable and secure as compare to Web Services.
4) WCF Services are more flexible as we make a new version of service we just have to expose a new endpoint.
5) In Web Service, [WebMethod] attribute specifies the method exposed to client. In WCF [OperationContract] attribute represents the method.
Explain contract and all types of contract in WCF?
Contract is platform-neutral and standard way of describing what services does. In WCF, all services are exposed as contract. There are four types of contracts :
Service Contract – It describes operation provided by service. A service should contain at least one service contract. Service Contract is defined by using [ServiceContract] attribute , it is similar to [WebMethod] of Web Services.
Data Contract – It describes data exchange between service and client. Data Contract is defined using [DataContract] and [DataMember] attribute.
Message Contract – It transfers information from service to client. WCF uses SOAP message format for communication.
Fault Contract – It handles and convey error message to the client when service get error.
What are types of Binding available in WCF?
BasicHttpBinding – It uses SOAP over HTTP.
WsHttpBinding – It uses SOAP over HTTP, it also supports reliable message transfer.
NetTcpbinding – It uses SOAP over TCP, but server and client should be in .Net.
NetNamedPipesBinding – It uses SOAP over Named Pipes.
Why it is dangerous to send a oneway message in WCF ?
It is dangerous to send a oneway message since there is no assurance that the operation is processed or not.
State 3 Duplex contract problems in WCF ?
1) Threading problems can occur if either of the Callback channels are not empty.
(2) If the client and service has a long running work then this pattern doesn't scale very well. It can block the client or the service until the process is completes !
(3) It requires a connection back to the client. And there may be a chance to not connect back due to firewall and Network Address Translation problems.
Note :- It is always better to use Request / Response MEP rather than using Duplex method.
Which command is used to convert WSDL to a proxy
svcutil.exe command will convert the WSDL to a proxy class for our client
Open visual studio command prompt window
click on visual studio command prompt,set the current folder to the location where you want the generated proxy and configuration files to be created.
Run SvcUtil.exe to generate the output files.
Which type of securities are available in WCF?
None, Transport, Message, Mixed Mode(Transport & Message) and Both, these are the five modes of security are available in WCF, They are use in different Binding mode.
Which are the available types of transport schemas in WCF?
HTTP, TCP, Peer Network, MSMQ, IPC (Inter-Process Communication over named pipes)
Which is/are the possible value/s of ConcurrencyMode enumeration in WCF?
Single
Reentrant
Multiple
What is/are the type/s of Messaging pattern/s in WCF?
Request Reply
Simplex
Duplex
You are developing data access service that access by several types of clients (non-.net or .net) to access a back-end database server running Microsoft SQL Server. Which approach should you use?
USE a WCF web service
You are developing a web service that will be accessed by Clients might be running JavaScript or the .NET Framework.
you need to Create the data access layer with the least amount of development effort.
You can create a WCF data services data access layer in only a few minutes.
ASP.NET web service that provided access to an underlying database, it would require far more programming than using
WCF data services.
Which is/are available Instance Mode/s in WCF?
Per Call.
Per Session.
Single.
Which message encoding format/s is/are available in WCF?
Binary
MTOM
Text
What is MTOM?
MTOM stands for Message Transmission Optimization Mechanism and is an Interoperable standard that reduces the overhead for transfer large binary data in WCF. Its a mechanism for transmitting large binary attachments with SOAP messages as raw bytes.
What is the difference between a standard void operation and a one-way operation?
Suppose you have the following ServiceContract implemented:
[ServiceContract]
public interface IMyTask
{
[OperationContract(IsOneWay=false)]
void MyTask();
[OperationContract(IsOneWay = true)]
void MyTaskOneWay();
}
By invoking the two operations from the client side and capturing the HTTP message, we can get different response messages.
The normal void operation will return HTTP 200 status code and the complete SOAP Response in the body and the one-way operation will only return a HTTP 202 Accepted status header. This indicates that the one-way operation call gets finished as long as the
server side received the request, while the normal void operation will wait for the server side to execute and return the response data.
Which of the following represent the .net attribute from System.Servicemodel namespace that you will use while define a new Service Contract ?
ServiceContractAttribute and OperationContractAttribute
At a minimum, you will nned the ServiceContractAttribute to declare the contract and OperationcontractAttribute to declare any operations in that service contract.
Which of the following properties you should enable, so can your service will expose its metadata through HTTP-GET
httpGetEnabled property is part of serviceMetadata element set true. So client can access your service metaData.
behaviors element contains all behaviors related to a service.
Which standard binding you would be use if your service will hosted on the same computer as the client ?
Named pipe binding uses named pipe as transport for same machine communication using an efficient binary encoding method.
Basic binding exposes a service like an prior asmx web service
What is RoundTripping ?
A client with an older version (v1.0) of a data contract can communicate with a service with a newer version(v2.0) of the same data contract, or a client with a newer version of a data contract can communicate with an older version of the same data contract. this new-to-old-to-new interaction is called versioning roundtrip.
Round-tripping guarantees that no data is lost. WCF does have some built-in support it (IExtensibleDataObject interface).
In WCF, which is the default place for maintain session state ?
By default, WCF stores session state in memory.
You want to use performance monitor to track the no of rejected messages in your developed WCF application.
Queue Rejected Message
Identified the no of rejected messages for the service.
Calls Faulted or Calls Faulted per second performance object, track Number of calls that returned as faults.
No comments:
Post a Comment