WCF RESTful Service      Interview Questions         WCF Bindings             WCF Tracing                              

Tuesday, June 26, 2012

An ASP.NET setting has been detected that....

After deploying my Windows Communication Foundation service on IIS 7.5, i was getting the following error.

HTTP Error 500.24 - Internal Server Error
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.


I tried to google it out but unable to find exact solution for this one. Later on, after researching and looking into IIS settings, I resolved the issue and here in this WCF Tutorial, you can find the steps to resolution.

1. Firstly, ensure that WCF is registered properly with IIS and ASP.NET (exact version).
For details on how to register WCF with IIS and ASP.NET?

2. Secondly, Open IIS and go to Advanced Settings of your website/virtual directory. In "Advance Setting" popup, change the Application Pool to "Classic .NET AppPool" and click ok.

Important thing to remember is that the Application Pool that is being used by our application should have two important settings.
a) Managed Pipeline Mode of AppPool should set to "Classic" instead of "Integrated".
b) .NET Framework Version of AppPool should be the same we used for the WCF service.

Having these two settings, we can create and use a new AppPool for our application and we don't need to be specific to "Classic .NET AppPool".


Be social and share with others via:


.NET Jobs from Indeed
Reader of this article might also be interested in:

By Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.

Sunday, June 24, 2012

Understanding WCF Bindings and Channel Stack

In order to understand Windows Communication Foundation Bindings in details, it’s important to understand the Channel Stack as part of WCF runtime.

WCF binding is composed of binding elements and each binding element is corresponding to a specific channel in Channel Stack. The Channel Stack can be categorized into two major areas i.e. Protocol Channels and Transport Channels.

Protocol Channels are Transaction Protocol, Reliable Messaging Protocol and Security Protocol while Transport Channels includes Message Encoding and Transport Protocol.
Transaction flow   is the optional element that controls the incoming transactions flow.

Reliability is also the optional binding element specifies that reliable messaging is supported or not.

Security is another element that specifies that how security concepts like authentication, authorization, confidentiality and integrity will work.

Encoding is the required message encoding element that specifies which encoding method will be used i.e. text, binary, or MTOM.

Transport is also required binding element that specifies which transport protocol will be used i.e. TCP, NamedPipes, HTTP, HTTPS, MSMQ, or Peer-to-Peer or we can define our own custom one.



Each request coming from the client will go through Channel Stack from top to bottom and then encoded byte stream message will travels over wire. On the other end, message travel from bottom to top and reaches the service as shown in above diagram.

A complete picture of WCF runtime with Service Instance, Dispatcher and Channel Stack is as follows:


WCF is extensible, so we can defined our own bindings but there are different built-in bindings available in WCF, each designed to fulfill some specific needs.
  1. basicHttpBinding
  2. wsHttpBinding
  3. netNamedPipeBinding
  4. netTcpBinding
  5. netPeerTcpBinding
You can find difference between basicHttpBinding and wsHttpBinding in another WCF Tutorial on this blog.
For example, We should go for basicHttpBinding or wsHttpBinding, if interoperability is our concern and we need to communicate with non-WCF systems. In some case, our service can reside on a single system, In such scenario netNamedPipeBinding will be the most efficient option.
netTcpBinding or netPeerTcpBinding might be best options, if we need to communicate across multiple computers.
And if the service needs support for disconnected or queued calls, netMsmqBinding or msmqIntegrationBinding will be the candidate options.

Finally an important thing to note is, if at all possible, tries to customize an existing standard binding rather than creating a custom binding because creating new one will add the complexity to our solution.



Be social and share with others via:
WCF Tutorials With Examples:
.NET Jobs from Indeed

By Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.

Tuesday, June 19, 2012

WCF Vs ASMX Web Services

First of all, it needs to understand that WCF Service provides all the capabilities of .NET web servies and further extends it.

Simple and basic difference is that ASMX web service is designed to send and receive messages using SOAP over HTTP only. While WCF service can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).
ASMX is simple but limited in many ways as compared to WCF.


  1. ASMX web services can be hosted only in IIS while WCF service has all the following hosting options:
    a. IIS
    b. WAS (Windows Process Activation Services)
    c. Console Application
    d. Windows NT Services
    e. WCF provided Host
  2. ASMX web services support is limited to HTTP while WCF supports HTTP, TCP, MSMQ, NamedPipes.
  3. ASMX Security is limited. Normally authentication and authorization is done using IIS and ASP.NET security configuration and transport layer security.For message layer security, WSE can be used.
    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 security is consistent regardless of the host that is used to implement WCF service.
  4. Another major difference is that ASMX web services uses XmlSerializer for serialization while WCF uses DataContractSerializer which is far better in performance than XmlSerializer.
    Key Issues with XmlSerializer in serializing .NET types to xml are:
    a. Only public fields or properties of the .NET types can be translated to Xml.
    b. Only the classes that implement IEnumerable can be translated.
    c. Classes that implement IDictionary, such as Hashtable cannot be serialized.
Hopefully, this WCF Tutorial will be helpful in understanding the difference between WCF and ASP.NET Web Services.


Be social and share with others via:


Other WCF and Related Tutorials:
.NET Jobs from Indeed

By Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.

Monday, June 18, 2012

How to register WCF with IIS and ASP.NET

If we have installed .NET framework before installing IIS on our machine and we wanted to deploy a WCF service. Then we need to do some additional steps by registering Windows Communication Foundation with IIS and ASP.NET. This WCF tutorial focuses on  simple steps to resolution.

Firstly, register ASP.NET with IIS by executing following:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i


Secondly, register WCF by executing following:
C:\Windows\Microsoft.NET\Framework\3.0\Windows Communication Foundation\ServiceModelReg -i

This is a common issue for which sometimes we spend hours of our time to understand and resolve.

Be social and share with others via:


Other WCF and Related Tutorials:
.NET Jobs from Indeed

By Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.

Friday, June 15, 2012

Top 10 WCF Interview Questions

This Top WCF Tutorials post has most important and basic questions that are asked during a WCF interview on hot topics with detailed answers and explanation.


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:

      1.    Hosting in a Managed Application/ Self Hosting
             a.    Console Application
             b.    Windows Application
             c.    Windows Service
        2.    Hosting on Web Server
             a.    IIS 6.0 (ASP.NET Application supports only HTTP)
             b.    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.

[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.

Please follow "3 techniques for Instance Management in WCF".

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.
                    
             <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:

             <basicHttpBinding>
             <binding name=”basicHttp”>
               <security mode=”TransportWithMessageCredential”>
                          <Transport />
                               <Message clientCredentialType=”UserName” />
               </security>
             </binding>
             </basicHttpBinding>

In this WCF Tutorial, we discussed about the most important top 10 interview questions and answers only but you can go through a series of articles on WCF Interview Questions here.


Be social and share with others via:


Related Web Development Tutorials:
.NET Jobs from Indeed

By Imran Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.

Thursday, June 7, 2012

4 simple steps to enable tracing in WCF

Tracing mechanism in Windows Communication Foundation is based on the classes that resides in System.Diagnostic namespace.Important classes are Trace, TraceSource and TraceListener. For better understanding we will follow step by step approach in this WCF Tutorial.

Following are the steps to enable tracing in WCF:

1. Configuring WCF to emit tracing information/Define Trace Source, we have the following options:
  • System.ServiceModel 
  • System.ServiceModel.MessageLogging 
  • System.ServiceModel.IdentityModel
  • System.ServiceModel.Activation 
  • System.Runtime.Serialization 
  • System.IO.Log
  • Cardspace
      In configuration file, we will define a source to enable this configuration as follows:
      <source name="System.ServiceModel.MessageLogging">

2. Setting Tracing Level, we have the following available options, we need to set this tracing level to available options other than default "Off":
  • Off
  • Critical
  • Error
  • Warning
  • Information
  • Verbose
  • ActivityTracing
  • All
      In configuration file, we can choose above values for switchValue attribute as follows:
      <source name="System.ServiceModel.MessageLogging"
                               switchValue=”Information”>


3. Configuring a trace listener
    For configuring a trace listener, we will add following to config file.
     <listeners>
                 <add name="messages"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="d:\logs\messages.svclog" />
      </listeners>


4. Enabling message logging
      <system.serviceModel>
         <diagnostics>
            <messageLogging
                    logEntireMessage="true"
                    logMalformedMessages="false"
                    logMessagesAtServiceLevel="true"
                    logMessagesAtTransportLevel="false"
                    maxMessagesToLog="3000"
                    maxSizeOfMessageToLog="2000"/>
         </diagnostics>
    </system.serviceModel>
logEntireMessage: By default, only the message header is logged but if we set it to true, entire message including message header as well as body will be logged.
logMalformedMessages: this option log messages those are rejected by WCF stack at any stage are known as malformed messages.
logMessagesAtServiceLevel: messages those are about to enter or leave user code.
logMessagesAtTransportLevel: messages those are about to encode or decode.
maxMessagesToLog: maximum quota for messages. Default value is 10000.
maxSizeOfMessageToLog: message size in bytes.
Putting all this together, configuration file will appear like this.
--------------------------------------------------------------------------- 
    <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messagelistener"
               type="System.Diagnostics.XmlWriterTraceListener" initializeData="d:\logs\myMessages.svclog"></add>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
    <system.serviceModel>       
      <diagnostics>
        <messageLogging logEntireMessage="true"
                        logMessagesAtServiceLevel="false"
                        logMessagesAtTransportLevel="false"
                        logMalformedMessages="true"
                        maxMessagesToLog="5000"
                        maxSizeOfMessageToLog="2000">         
        </messageLogging>
      </diagnostics>
    </system.serviceModel>
---------------------------------------------------------------------------                                                                      
Note: In this case, information will be buffered and not published to file automatically, So, we can set the autoflush property of the trace under sources as follows:
<trace autoflush ="true" />

Be social and share with others via:


Other Top WCF Service Tutorials:
.NET Jobs from Indeed

By Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.

Sunday, June 3, 2012

Serializer Vs Encoder in WCF


Object Graph >>------(Serializer)------>> WCF Message >>---------(Encoder)------->>Byte Stream

In Windows Communication Foundation, Object graph is rendered to WCF Message by a serializer, while further that WCF Message is tranformed to byte stream by an Encoder so that i can be tranported on wire.

WCF provides two serializers to perform the job of rendering to WCF Message from object graph.
  1. DataContract Serializer
  2. XmlSerializer
Further, in chain of channels, there is an encoder whose job is to encode the Message object to byte stream in a particular concrete syntax.

You can follow other related Web Development concept Encoding Vs Encryption.

Be social and share with others via:


.NET Jobs from Indeed
Reader of this article might also be interested in:

By Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.

Saturday, June 2, 2012

WCF Service - Bindings default security

When we talk about security in Windows Communication Foundation, It can be at two different levels i.e.
  • Transport Level Security
  • Message Level Security

Different WCF bindings have security defaults as follows:
1. BasicHttpBinding
  • No Security
  • Interopable with ASMX Web Services
2. WsHttpBinding
  • Message Level Security
  • SOAP Messages are encrypted
3. NetTcpBinding
  • Transport Level Security
  • Packets are encrypted but not the messages (SOAP messages)

Be social and share with others via:


WCF Tutorials With Examples:
.NET Jobs from Indeed

By Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates
Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net & www.topwcftutorials.net.