<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ramani Sandeep&#039;s Blog</title>
	<atom:link href="http://ramanisandeep.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://ramanisandeep.net</link>
	<description>DotNetting - Fast , Easy Way of Developing Applications</description>
	<lastBuildDate>Tue, 29 May 2012 08:43:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ramanisandeep.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/ce733b90c7daf4f0c385a904fda5b532?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Ramani Sandeep&#039;s Blog</title>
		<link>http://ramanisandeep.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ramanisandeep.net/osd.xml" title="Ramani Sandeep&#039;s Blog" />
	<atom:link rel='hub' href='http://ramanisandeep.net/?pushpress=hub'/>
		<item>
		<title>“Article of the day” @ ASP.NET Microsoft Official Website</title>
		<link>http://ramanisandeep.net/2012/04/14/article-of-the-day-asp-net-microsoft-official-website/</link>
		<comments>http://ramanisandeep.net/2012/04/14/article-of-the-day-asp-net-microsoft-official-website/#comments</comments>
		<pubDate>Sat, 14 Apr 2012 19:21:11 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[Mics]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[microsoft official]]></category>

		<guid isPermaLink="false">http://ramanisandeep.net/?p=1021</guid>
		<description><![CDATA[Happy to announce that my article entitled “Add Custom Message Header in WCF 4 Calls&#8221; has been selected as “Article of the day” @ASP.NET Microsoft Official Website on April 12, 2012. You can check this out at : http://www.asp.net/community Thank you very much to all my readers/well wishers who has inspired me to post/write useful [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=1021&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Happy to announce that my article entitled “<a href="http://www.codeproject.com/Articles/352678/Add-Custom-Message-Header-in-WCF-4-Calls" target="_blank">Add Custom Message Header in WCF 4 Calls</a>&#8221; has been selected as “Article of the day” @ASP.NET Microsoft Official Website on April 12, 2012.</p>
<p>You can check this out at : <a href="http://www.asp.net/community">http://www.asp.net/community</a></p>
<p>Thank you very much to all my readers/well wishers who has inspired me to post/write useful content on the blog. I will try my best to provide useful information in upcoming days as well.</p>
<p><strong>With Regards</strong><br />
Sandeep Ramani</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/1021/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=1021&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2012/04/14/article-of-the-day-asp-net-microsoft-official-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>Add Custom Message Header in WCF 4 Calls</title>
		<link>http://ramanisandeep.net/2012/03/22/add-custom-message-header-in-wcf-4-calls/</link>
		<comments>http://ramanisandeep.net/2012/03/22/add-custom-message-header-in-wcf-4-calls/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 08:54:26 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[add custom header]]></category>
		<category><![CDATA[add custom header to wcf channel]]></category>
		<category><![CDATA[header authentication]]></category>
		<category><![CDATA[header parameters]]></category>
		<category><![CDATA[how to add custom header to every wcf calls]]></category>
		<category><![CDATA[wcf custom message headers]]></category>

		<guid isPermaLink="false">http://ramanisandeep.net/?p=1014</guid>
		<description><![CDATA[Often, we want to pass some data to some or maybe all our service operations. This data is usually context data such as user tokens, or environmental preferences of the user or machine. In simple web service we can pass custom header information using Attribute called “[SoapHeaderAttribute ("ServiceHeader", Direction=SoapHeaderDirection.In)]” along with Web Method signatures. But [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=1014&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Often, we want to pass some data to some or maybe all our service operations. This data is usually context data such as user tokens, or environmental preferences of the user or machine.</p>
<p style="text-align:justify;"><em>In simple web service we can pass custom header information using Attribute called “</em><strong><em>[SoapHeaderAttribute ("ServiceHeader", Direction=SoapHeaderDirection.In)]</em></strong>” along with Web Method signatures.</p>
<p style="text-align:justify;">But in WCF, we cannot use the same attribute.</p>
<p style="text-align:justify;">One way would be to pass it as an additional request parameter. But, each and every method call needs to have this parameter(s) repeatedly. Not a very clean solution. Also, if the data type of this parameter changes, all the method signatures and their calls need to be changed.</p>
<p style="text-align:justify;">A nice and easy way to pass that data is to use Message Headers.</p>
<p style="text-align:justify;">In WCF, to pass the custom header information along with method call, we need to implement custom inspector for client and service which will implement the <em><strong>BeforeSendRequest</strong> </em>and <em><strong>AfterRecieveRequest</strong> </em>methods to inject the custom header.</p>
<p>In order to do this we need following objects/classes:</p>
<ol>
<li>Soap Header</li>
<li>Message Inspector</li>
<li>Client Context and Server Context class</li>
<li>Custom Behavior</li>
</ol>
<p>Let’s start creating these classes one by one.</p>
<h2><strong>1) Soap Header:</strong></h2>
<p><strong>CustomHeader</strong> class is used to create custom header for service in which we want to pass header information along with method call. <strong>CustomHeader</strong> class contains the information that we want to pass along with method call. You can define the structure as per your needs.</p>
<p><pre class="brush: csharp;">

    [DataContract]
    public class ServiceHeader
    {

        [DataMember]
        public string EmployeeID { get; set; }

        [DataMember]
        public string WindowsLogonID { get; set; }

        [DataMember]
        public string KerberosID { get; set; }

        [DataMember]
        public string SiteminderToken { get; set; }

    }

    public class CustomHeader : MessageHeader
    {
        private const string CUSTOM_HEADER_NAME = &quot;HeaderName&quot;;
        private const string CUSTOM_HEADER_NAMESPACE = &quot;YourNameSpace&quot;;

        private ServiceHeader _customData;

        public ServiceHeader CustomData
        {
            get
            {
                return _customData;
            }
        }

        public CustomHeader()
        {
        }

        public CustomHeader(ServiceHeader customData)
        {
            _customData = customData;
        }

        public override string Name
        {
            get { return (CUSTOM_HEADER_NAME); }
        }

        public override string Namespace
        {
            get { return (CUSTOM_HEADER_NAMESPACE); }
        }

        protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ServiceHeader));
            StringWriter textWriter = new StringWriter();
            serializer.Serialize(textWriter, _customData);
            textWriter.Close();

            string text = textWriter.ToString();

            writer.WriteElementString(CUSTOM_HEADER_NAME, &quot;Key&quot;, text.Trim());
        }

        public static ServiceHeader ReadHeader(Message request)
        {
            Int32 headerPosition = request.Headers.FindHeader(CUSTOM_HEADER_NAME, CUSTOM_HEADER_NAMESPACE);
            if (headerPosition == -1)
                return null;

            MessageHeaderInfo headerInfo = request.Headers[headerPosition];

            XmlNode[] content = request.Headers.GetHeader&lt;XmlNode[]&gt;(headerPosition);

            string text = content[0].InnerText;

            XmlSerializer deserializer = new XmlSerializer(typeof(ServiceHeader));
            TextReader textReader = new StringReader(text);
            ServiceHeader customData = (ServiceHeader)deserializer.Deserialize(textReader);
            textReader.Close();

            return customData;
        }
    }

</pre></p>
<p style="text-align:justify;">As you can see it is a type inheriting from <em>MessageHeader</em> class. Notice the <em>OnWriteHeaderContents</em> override, which is invoked by WCF infrastructure to serialize the SOAP Header, and the <em>ReadHeader</em> static method that we will use later.</p>
<h2><strong>2) Message Inspector:</strong></h2>
<p>SOAP Header needs to be added by the consumer and read by the service. To do this we need a Message Inspector like the following one:</p>
<p><pre class="brush: csharp;">

    /// &lt;summary&gt;
    /// This class is used to inspect the message and headers on the server side,
    /// This class is also used to intercept the message on the client side, before/after any request is made to the server.
    /// &lt;/summary&gt;
    public class CustomMessageInspector : IClientMessageInspector, IDispatchMessageInspector
    {
        #region Message Inspector of the Service

        /// &lt;summary&gt;
        /// This method is called on the server when a request is received from the client.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;request&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;channel&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;instanceContext&quot;&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            // Create a copy of the original message so that we can mess with it.
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
            request = buffer.CreateMessage();
            Message messageCopy = buffer.CreateMessage();

            // Read the custom context data from the headers
            ServiceHeader customData = CustomHeader.ReadHeader(request);

            // Add an extension to the current operation context so that our custom context can be easily accessed anywhere.
            ServerContext customContext = new ServerContext();

            if (customData != null)
            {
                customContext.KerberosID = customData.KerberosID;
                customContext.SiteminderToken = customData.SiteminderToken;
            }
            OperationContext.Current.IncomingMessageProperties.Add(&quot;CurrentContext&quot;, customContext);
            return null;
        }

        /// &lt;summary&gt;
        /// This method is called after processing a method on the server side and just
        /// before sending the response to the client.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;reply&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;correlationState&quot;&gt;&lt;/param&gt;
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            // Do some cleanup
            OperationContext.Current.Extensions.Remove(ServerContext.Current);
        }

        #endregion

        #region Message Inspector of the Consumer

        /// &lt;summary&gt;
        /// This method will be called from the client side just before any method is called.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;request&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;channel&quot;&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            // Prepare the request message copy to be modified
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
            request = buffer.CreateMessage();

            ServiceHeader customData = new ServiceHeader();

            customData.KerberosID = ClientContext.KerberosID;
            customData.SiteminderToken = ClientContext.SiteminderToken;

            CustomHeader header = new CustomHeader(customData);

            // Add the custom header to the request.
            request.Headers.Add(header);

            return null;
        }

        /// &lt;summary&gt;
        /// This method will be called after completion of a request to the server.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;reply&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;correlationState&quot;&gt;&lt;/param&gt;
        public void AfterReceiveReply(ref Message reply, object correlationState)
        {

        }

        #endregion
    }

</pre></p>
<p style="text-align:justify;">As you can see from the code sample above, we use the <em>IClientMessageInspector</em> implementation to handle the addition of the header in the consumer-side code, while we use the <em>IDispatchMessageInspector</em> on the service side, to extract the header. It is interesting the <em>FindHeader</em> method of the <em>MessageHeaders</em> collection, as well as the method <em>GetReaderAtHeader</em>, provided by the same collection of Headers. The result of this last method is an <em>XmlDictionaryReader</em> that we use to read our custom header content, through the <em>ReadHeader</em> static method we&#8217;ve already introduced.</p>
<h2><strong>3) Client Context and Server Context class:</strong></h2>
<p style="text-align:justify;"><strong>ClientContext</strong> class is used to store the header information before calling the method, so when you want to attach the custom header data, you just need to set the values for this <strong>ClientContext</strong> class. These values get fetched inside <em>BeforeSendRequest</em> method of <em>CustomMessageInspector</em> class and send along with the request made.</p>
<p><pre class="brush: csharp;">

    /// &lt;summary&gt;
    /// This class will act as a custom context in the client side to hold the context information.
    /// &lt;/summary&gt;
    public class ClientContext
    {
        public static string EmployeeID;
        public static string WindowsLogonID;
        public static string KerberosID;
        public static string SiteminderToken;
    }

</pre></p>
<p style="text-align:justify;">At server side, once custom header is received, it will be stored inside this <strong>ServerContext</strong> class object, so that we can access it anytime once request is received.</p>
<p><pre class="brush: csharp;">

    /// &lt;summary&gt;
    /// This class will act as a custom context, an extension to the OperationContext.
    /// This class holds all context information for our application.
    /// &lt;/summary&gt;
    public class ServerContext : IExtension&lt;OperationContext&gt;
    {
        public string EmployeeID;
        public string WindowsLogonID;
        public string KerberosID;
        public string SiteminderToken;

        // Get the current one from the extensions that are added to OperationContext.
        public static ServerContext Current
        {
            get
            {
                return OperationContext.Current.Extensions.Find&lt;ServerContext&gt;();
            }
        }

        #region IExtension&lt;OperationContext&gt; Members
        public void Attach(OperationContext owner)
        {
        }

        public void Detach(OperationContext owner)
        {
        }
        #endregion
    }

</pre></p>
<h2><strong>4) Custom Behavior:</strong></h2>
<p>The service will be able to read the Key provided through the custom header simply querying the <em>IncomingMessageProperties</em> dictionary:</p>
<p><pre class="brush: csharp;">

OperationContext.Current.IncomingMessageProperties[&quot;CurrentContext&quot;];

</pre></p>
<p>Of course the Custom Message Inspector needs to be plugged into the WCF pipeline using a custom behavior like the following one.</p>
<p><pre class="brush: csharp;">

    /// &lt;summary&gt;
    /// This custom behavior class is used to add both client and server inspectors to
    /// the corresponding WCF end points.
    /// &lt;/summary&gt;
    [AttributeUsage(AttributeTargets.Class)]
    public class CustomBehavior : Attribute, IServiceBehavior, IEndpointBehavior
    {
        #region IEndpointBehavior Members

        void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
        }

        void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
            CustomMessageInspector inspector = new CustomMessageInspector();
            clientRuntime.MessageInspectors.Add(inspector);
        }

        void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            ChannelDispatcher channelDispatcher = endpointDispatcher.ChannelDispatcher;
            if (channelDispatcher != null)
            {
                foreach (EndpointDispatcher ed in channelDispatcher.Endpoints)
                {
                    CustomMessageInspector inspector = new CustomMessageInspector();
                    ed.DispatchRuntime.MessageInspectors.Add(inspector);
                }
            }
        }

        void IEndpointBehavior.Validate(ServiceEndpoint endpoint) { }

        #endregion

        #region IServiceBehavior Members

        void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection&lt;ServiceEndpoint&gt; endpoints, BindingParameterCollection bindingParameters)
        {
        }

        void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription desc, ServiceHostBase host)
        {
            foreach (ChannelDispatcher cDispatcher in host.ChannelDispatchers)
            {
                foreach (EndpointDispatcher eDispatcher in cDispatcher.Endpoints)
                {
                    eDispatcher.DispatchRuntime.MessageInspectors.Add(new CustomMessageInspector());
                }
            }
        }

        void IServiceBehavior.Validate(ServiceDescription desc, ServiceHostBase host) { }

        #endregion
    }

</pre></p>
<p style="text-align:justify;">Implement the <em><strong>IEndpointBehavior</strong> </em>interface to modify, examine, or extend some aspect of endpoint-wide execution at the application level for either client or service applications.</p>
<ul>
<li style="text-align:justify;">Use the <em>AddBindingParameters</em> method to pass custom data at runtime to enable bindings to support custom behavior.</li>
<li style="text-align:justify;">Use the <em>ApplyClientBehavior</em> method to modify, examine, or insert extensions to an endpoint in a client application.</li>
<li style="text-align:justify;">Use the <em>ApplyDispatchBehavior</em> method to modify, examine, or insert extensions to endpoint-wide execution in a service application.</li>
<li style="text-align:justify;">Use the Validate method to confirm that a <em>ServiceEndpoint</em> meets specific requirements. This can be used to ensure that an endpoint has a certain configuration setting enabled, supports a particular feature and other requirements.</li>
</ul>
<p>Implement <em><strong>IServiceBehavior</strong> </em>to modify, examine, or extend some aspect of service-wide execution at the application level:</p>
<ul>
<li style="text-align:justify;">Use the <em>ApplyDispatchBehavior</em> method to change run-time property values or insert custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects.</li>
<li style="text-align:justify;">Use the <em>Validate</em> method to examine the description before constructs the executing service to confirm that it can execute properly.</li>
<li style="text-align:justify;">Use the <em>AddBindingParameters</em> method to pass to a binding element the custom information for the service so that it can support the service correctly.</li>
</ul>
<h2><strong>Adding Behavior to the Runtime</strong></h2>
<p style="text-align:justify;">When you construct a ServiceHost or client-side ChannelFactory, the runtime reflects over the service types, reads the configuration file, and starts building an in-memory description of the service. Within ServiceHost, this description is made available to you via the Description property (of type ServiceDescription). Within ChannelFactory, it&#8217;s made available via the Endpoint property (of type ServiceEndpoint); the client-side description is limited to the target endpoint.</p>
<p style="text-align:justify;">The ServiceDescription contains a full description of the service and each endpoint (ServiceEndpoint), including contracts (ContractDescription) and operations (OperationDescription). ServiceDescription provides a Behaviors property (a collection of type IServiceBehavior) that models a collection of service behaviors. Each ServiceEndpoint also has a Behaviors property (a collection of type IEndpointBehavior) that models the individual endpoint behaviors. Likewise, ContractDescription and OperationDescription each have an appropriate Behaviors property.</p>
<p style="text-align:justify;">These behavior collections are automatically populated during the ServiceHost and ChannelFactory construction process with any behaviors that are found in your code (via attributes) or within the configuration file (more on this shortly). You can also add behaviors to these collections manually after construction. The following example shows how to add the CustomBehavior to the host as a service behavior:</p>
<p><pre class="brush: csharp;">

WCFServiceClient ws = new WCFServiceClient();
ws.ChannelFactory.Endpoint.Behaviors.Add(new CustomBehavior());

</pre></p>
<h2><strong>Adding Behavior with Attribute</strong></h2>
<p style="text-align:justify;">During the ServiceHost/ChannelFactory construction process, the runtime reflects over the service types and configuration file and automatically adds any behaviors it finds to the appropriate behavior collections in the ServiceDescription.</p>
<p><pre class="brush: csharp;">

  /// &lt;summary&gt;
    /// Summary description for WCFService
    /// &lt;/summary&gt;
    [CustomBehavior]
    public class WCFService : IWCFService
    {
    }

</pre></p>
<p><em><strong>That&#8217;s all! Enjoy your custom header passing using behavior specified.</strong></em></p>
<p>Hope this will help!!!</p>
<p>Jay Ganesh</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/1014/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=1014&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2012/03/22/add-custom-message-header-in-wcf-4-calls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>18.520430 73.856744</georss:point>
		<geo:lat>18.520430</geo:lat>
		<geo:long>73.856744</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Article of the day&#8221; @ ASP.NET Forum</title>
		<link>http://ramanisandeep.net/2011/12/16/article-of-the-day-asp-net-forum-3/</link>
		<comments>http://ramanisandeep.net/2011/12/16/article-of-the-day-asp-net-forum-3/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 14:50:59 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[Mics]]></category>

		<guid isPermaLink="false">http://ramanisandeep.net/?p=1004</guid>
		<description><![CDATA[I am happy to announce that my article entitled &#8220;Parallelism in .NET – PLINQ&#8221; has been selected as &#8220;Article of the day&#8221; @ ASP.NET Forum on Dec 15, 2011. You can check this out at : http://www.asp.net/community Thanks to all my readers/well wishers who has inspired me to post/write useful content on the blog. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=1004&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am happy to announce that my article entitled &#8220;<a title="Parallelism-in-NET-PLINQ" href="http://www.codeproject.com/Articles/156980/Parallelism-in-NET-PLINQ" target="_blank">Parallelism in .NET – PLINQ</a>&#8221; has been selected as &#8220;Article of the day&#8221; @ ASP.NET Forum on Dec 15, 2011.</p>
<p>You can check this out at : <a href="http://www.asp.net/community">http://www.asp.net/community</a></p>
<p>Thanks to all my readers/well wishers who has inspired me to post/write useful content on the blog. I will try my best to provide useful information in upcoming days as well.</p>
<p><strong>With Regards</strong><br />
Sandeep Ramani</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/1004/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=1004&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/12/16/article-of-the-day-asp-net-forum-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Article of the day&#8221; @ ASP.NET Forum</title>
		<link>http://ramanisandeep.net/2011/12/02/article-of-the-day-asp-net-forum-2/</link>
		<comments>http://ramanisandeep.net/2011/12/02/article-of-the-day-asp-net-forum-2/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 11:29:18 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[Mics]]></category>
		<category><![CDATA[Article of the Day]]></category>

		<guid isPermaLink="false">http://ramanisandeep.wordpress.com/?p=989</guid>
		<description><![CDATA[I am happy to announce that my article entitled &#8220;No more pain to configure WCF 4 Services&#8221; has been selected as &#8220;Article of the day&#8221; @ ASP.NET Forumn on Dec 1, 2011. You can check this out at : http://www.asp.net/community Thanks to all my readers/well wishers who has inspired me to post/write useful content on the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=989&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am happy to announce that my article entitled &#8220;<a href="http://ramanisandeep.wordpress.com/2011/11/18/no-more-pain-to-configure-wcf-4-services/">No more pain to configure WCF 4 Services</a>&#8221; has been selected as &#8220;Article of the day&#8221; @ ASP.NET Forumn on Dec 1, 2011.</p>
<p>You can check this out at : <a href="http://www.asp.net/community">http://www.asp.net/community</a></p>
<p>Thanks to all my readers/well wishers who has inspired me to post/write useful content on the blog. I will try my best to provide useful information in upcoming days as well.</p>
<p>With Regards<br />
<em>Sandeep Ramani</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/989/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=989&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/12/02/article-of-the-day-asp-net-forum-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>No more pain to configure WCF 4 services</title>
		<link>http://ramanisandeep.net/2011/11/18/no-more-pain-to-configure-wcf-4-services/</link>
		<comments>http://ramanisandeep.net/2011/11/18/no-more-pain-to-configure-wcf-4-services/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 12:38:08 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Default Behavior Configurations]]></category>
		<category><![CDATA[Default Binding Configurations]]></category>
		<category><![CDATA[default configuration]]></category>
		<category><![CDATA[Default Endpoints]]></category>
		<category><![CDATA[Default Protocol Mapping]]></category>
		<category><![CDATA[No more pain to configure WCF 4 services]]></category>
		<category><![CDATA[WCf 4]]></category>
		<category><![CDATA[WCF 4 - A Simplified Configuration]]></category>
		<category><![CDATA[what is new in wcf 4]]></category>

		<guid isPermaLink="false">http://ramanisandeep.wordpress.com/?p=990</guid>
		<description><![CDATA[Developer who has worked with ASP.NET Web Services (ASMX) and WCF always feels that using predecessor was much more easier. It just because WCF configuration is much more complex as compare to ASP.NET Web Service. WHY ?????? With ASMX, you were able to define a [WebMethod] operation and the runtime automatically provided a default configuration [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=990&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Developer who has worked with ASP.NET Web Services (ASMX) and WCF always feels that using predecessor was much more easier. It just because WCF configuration is much more complex as compare to ASP.NET Web Service.</p>
<p><strong>WHY ??????</strong></p>
<p style="text-align:justify;">With ASMX, you were able to define a [WebMethod] operation and the runtime automatically provided a default configuration for the underlying communications. When moving to WCF 3.x, on the other hand, developers have to know enough about the various WCF configuration options to define at least one endpoint.</p>
<p style="text-align:justify;">In an effort to make the overall WCF experience just as easy as ASMX, WCF 4 comes with a new “default configuration” model that completely removes the need for any WCF configuration. If you don’t provide any WCF configuration for a particular service, the WCF 4 runtime automatically configures your service with some standard endpoints and default binding/behavior configurations. This makes it much easier to get a WCF service up and running, especially for those who aren’t familiar with the various WCF configuration options.</p>
<p>Let&#8217;s discuss some of the standard configuration options that WCF 4 support :</p>
<p>1) Default Endpoints<br />
2) Default Protocol Mapping<br />
3) Default Binding Configurations<br />
4) Default Behavior Configurations</p>
<p><span style="color:#3366ff;"><strong>1) Default Endpoints</strong></span></p>
<p style="text-align:justify;">With WCF 3.X, if you try to host a service without configured endpoints, ServiceHost instance will throw an exception informing you that you need to configure at least one endpoint. With WCF 4, this is no longer the case because the runtime automatically adds one or more &#8216;default endpoints&#8217; for you.</p>
<p><em>Now question comes in mind, How this is done by WCF 4?</em></p>
<p style="text-align:justify;">Answer to Question is like : When Host application calls Open method on ServiceHost instance, it build internal service description from the application configuration file. Than it check the count of configured endpoints. if it is still zero than it will call &#8220;AddDefaultEndpoints&#8221; public method and method will adds one default endpoint per base address for each service contract implemented by the service.</p>
<p><strong>Clear or Confused ??</strong></p>
<p>Lets take one example to be more clear on it.</p>
<p style="text-align:justify;">If the service implements two service contracts and you configure the host with a single base address, AddDefaultEndpoints will configure the service with two default endpoints (one for each service contract). However, if the service implements two service contracts and the host is configured with two base addresses (one for HTTP and one for TCP), AddDefaultEndpoints will configure the service with four default endpoints.</p>
<p style="text-align:justify;">I Hope now its clear&#8230;.if still not&#8230;please go thru the link provided for more details on it.</p>
<p>-&gt; New Features in WCF 4 that Will Instantly Make You More Productive<br />
(<a href="http://www.code-magazine.com/Article.aspx?quickid=1006061" target="_blank">http://www.code-magazine.com/Article.aspx?quickid=1006061</a>)</p>
<p><span style="color:#3366ff;"><strong>2) Default Protocol Mapping</strong></span></p>
<p style="text-align:justify;">In .Net 4.0 framework, default protocol mapping between transport protocol schemes and the built in WCF bindings are as follows :</p>
<p><pre class="brush: xml;">

   &lt;protocolMapping&gt;
      &lt;add scheme=&quot;http&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;&quot; /&gt;
      &lt;add scheme=&quot;net.tcp&quot; binding=&quot;netTcpBinding&quot; bindingConfiguration=&quot;&quot;/&gt;
      &lt;add scheme=&quot;net.pipe&quot; binding=&quot;netNamedPipeBinding&quot; bindingConfiguration=&quot;&quot;/&gt;
      &lt;add scheme=&quot;net.msmq&quot; binding=&quot;netMsmqBinding&quot; bindingConfiguration=&quot;&quot;/&gt;
   &lt;/protocolMapping&gt;

</pre></p>
<p style="text-align:justify;">You can override these mappings at machine level by adding this section to machine.config file and modify the bindings as per your needs.</p>
<p style="text-align:justify;">If you want to override this mappings at application level than you can override the above section in application/web configfile.</p>
<p><span style="color:#3366ff;"><strong>3) Default Binding Configurations</strong></span></p>
<p>In WCF 3.x , binding can be done like this :</p>
<p><pre class="brush: xml;">

&lt;configuration&gt;
  &lt;system.serviceModel&gt;
    &lt;bindings&gt;
      &lt;basicHttpBinding&gt;
        &lt;binding name=&quot;BasicBindingMtom&quot; messageEncoding=&quot;Mtom&quot;/&gt;
      &lt;/basicHttpBinding&gt;
    &lt;/bindings&gt;
    &lt;services&gt;
      &lt;service name=&quot;HelloService&quot;&gt;
        &lt;endpoint address=&quot;mtom&quot; binding=&quot;basicHttpBinding&quot;
                  bindingConfiguration=&quot;BasicBindingMtom&quot;
                  contract=&quot;IHello&quot;/&gt;
      &lt;/service&gt;
    &lt;/services&gt;
  &lt;/system.serviceModel&gt;
&lt;/configuration&gt;

</pre></p>
<p style="text-align:justify;">Here &#8220;BasicBindingMtom&#8221; binding configuration overrides the defaults for BasicHttpBinding by changing the message encoding to &#8220;Mtom&#8221;. However this binding will effect only when you apply it to a specific endpoint thru &#8220;bindingConfiguration&#8221; attribute.</p>
<p>With WCF 4, binding can be done like this :</p>
<p><pre class="brush: xml;">

      &lt;basicHttpBinding&gt;
        &lt;binding messageEncoding=&quot;Mtom&quot;/&gt;
      &lt;/basicHttpBinding&gt;

</pre></p>
<p style="text-align:justify;">No name attribute required. This feature gives you a simple mechanism to define a standard set of binding defaults that you can use across all your services without imposing any complexities of binding configurations.</p>
<p><span style="color:#3366ff;"><strong>4) Default Behavior Configurations</strong></span></p>
<p style="text-align:justify;">With WCF 4, it is possible to define default behavior configurations for services and endpoints.</p>
<p><pre class="brush: xml;">

    &lt;behaviors&gt;
      &lt;serviceBehaviors&gt;
        &lt;behavior&gt;
          &lt;serviceMetadata httpGetEnabled=&quot;true&quot;/&gt;
        &lt;/behavior&gt;
      &lt;/serviceBehaviors&gt;
    &lt;/behaviors&gt;

</pre></p>
<p style="text-align:justify;">Above configuration turns on the metadata for any service that doesn&#8217;t come with explicit behavior configuration.</p>
<p style="text-align:justify;">In WCF 4, Behavior configuration also support inheritance model. It means that if application defines a behavior using same name as one already defined in machine.config, the application specific behavior configuration will get merged with machine configuration.</p>
<p style="text-align:justify;">With these new additions in the WCF 4, it will be easier for developers to configure the services. I am sure that many developers will feel relaxed by having these new features in WCF and also start using it. Thats all from my side for this post.</p>
<p><em><strong>Hope this will help !!!</strong></em></p>
<p><span style="color:#ff6600;"><strong>Jay Ganesh &#8230;&#8230;</strong></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/990/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=990&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/11/18/no-more-pain-to-configure-wcf-4-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>DataContract Vs MessageContract</title>
		<link>http://ramanisandeep.net/2011/10/19/datacontract-vs-messagecontract/</link>
		<comments>http://ramanisandeep.net/2011/10/19/datacontract-vs-messagecontract/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 12:32:09 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Data contract]]></category>
		<category><![CDATA[DataContract Vs MessageContract]]></category>
		<category><![CDATA[message contract]]></category>
		<category><![CDATA[message contract in wcf]]></category>
		<category><![CDATA[messagecontract vs datacontract]]></category>

		<guid isPermaLink="false">http://ramanisandeep.wordpress.com/?p=984</guid>
		<description><![CDATA[1. Comparison: Data Contracts: WCF data contracts provide a mapping function between .NET CLR types that are defined in code and XML Schemas Definitions defined by the W3C organization (www.w3c.org/) that are used for communication outside the service. you can say &#8220;Data contract is a formal agreement between a service and a client that abstractly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=984&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><strong>1. Comparison:</strong></h2>
<p><strong>Data Contracts:</strong></p>
<p style="text-align:justify;">WCF data contracts provide a mapping function between .NET CLR types that are defined in code and XML Schemas Definitions defined by the W3C organization (<a href="http://www.w3c.org/">www.w3c.org/</a>) that are used for communication outside the service.</p>
<p style="text-align:justify;">you can say &#8220;Data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged&#8221;. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts. A data contract precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged.</p>
<p><strong>Message Contracts:</strong></p>
<p style="text-align:justify;">Message contracts describe the structure of SOAP messages sent to and from a service and enable you to inspect and control most of the details in the SOAP header and body. Whereas data contracts enable interoperability through the XML Schema Definition (XSD) standard, message contracts enable you to interoperate with any system that communicates through SOAP.</p>
<p style="text-align:justify;">Using message contracts gives you complete control over the SOAP message sent to and from a service by providing access to the SOAP headers and bodies directly. This allows use of simple or complex types to define the exact content of the SOAP parts.</p>
<h2>2. Why use MessageContract when DataContract is there?</h2>
<p style="text-align:justify;">Data contracts are used to define the data structure. Messages that are simply a .NET type, lets say in form of POCO (plain old CLR object), and generate the XML for the data you want to pass.</p>
<p style="text-align:justify;">Message contracts are preferred only when there is a need to &#8220;control&#8221; the layout of your message(the SOAP message); for instance, adding specific headers/footer/etc to a message.</p>
<p style="text-align:justify;">sometimes complete control over the structure of a SOAP message is just as important as control over its contents. This is especially true when interoperability is important or to specifically control security issues at the level of the message or message part. In these cases, you can create a message contract that enables you to use a type for a parameter or return value that serializes directly into the precise SOAP message that you need.</p>
<h2>3. Why we use MessageContract to pass SOAP headers ?</h2>
<p style="text-align:justify;">Passing information in SOAP headers is useful if you want to communicate information “out of band” from the operation signature.</p>
<p style="text-align:justify;">For instance, session or correlation information can be passed in headers, rather than adding additional parameters to operations or adding this information as fields in the data itself.</p>
<p style="text-align:justify;">Another example is security, where you may want to implement a custom security protocol (bypassing WS-Security) and pass credentials or tokens in custom SOAP headers.</p>
<p style="text-align:justify;">A third example, again with security, is signing and encrypting SOAP headers, where you may want to sign and/or encrypt some or all header information. All these cases can be handled with message contracts. The downside with this technique is that the client and service must manually add and retrieve the information from the SOAP header, rather than having the serialization classes associated with data and operation contracts do it for you.</p>
<h2>4. Can&#8217;t mix datacontracts and messagecontracts.</h2>
<p style="text-align:justify;">Because message-based programming and parameter-based programming cannot be mixed, so you cannot specify a DataContract as an input argument to an operation and have it return a MessageContract, or specify a MessageContract as the input argument to an operation and have it return a DataContract. You can mix typed and untyped messages, but not messageContracts and DataContracts. Mixing message and data contracts will cause a runtime error when you generate WSDL from the service.</p>
<p><strong>Hope this will help !!!</strong></p>
<p><span style="color:#ff00ff;"><strong>@@@ Happy Diwali @@@</strong></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/984/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=984&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/10/19/datacontract-vs-messagecontract/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>ServiceContractGenerator vs ServiceDescriptionImporter</title>
		<link>http://ramanisandeep.net/2011/10/13/servicecontractgenerator-vs-servicedescriptionimporter/</link>
		<comments>http://ramanisandeep.net/2011/10/13/servicecontractgenerator-vs-servicedescriptionimporter/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 17:33:49 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[ServiceContractGenerator]]></category>
		<category><![CDATA[ServiceContractGenerator vs ServiceDescriptionImporter]]></category>
		<category><![CDATA[ServiceDescriptionImporter]]></category>

		<guid isPermaLink="false">http://ramanisandeep.wordpress.com/?p=977</guid>
		<description><![CDATA[Recently, I have worked with WCF. During this , I have developed one tool that help us to run any web service (.asmx) and wcf service (.svc) by just using URL of it. It was totally dynamic process. In this process, I have learn how to fetch method list , parameter names and how to invoke [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=977&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;"><span style="color:#000000;">Recently, I have worked with WCF. During this , I have developed one tool that help us to run any web service (.asmx) and wcf service (.svc) by just using URL of it. It was totally dynamic process. In this process, I have learn how to fetch method list , parameter names and how to invoke method dynamically. During this process I came across the terms called ServiceDescriptionImporter and ServiceContractGenerator. So I feel that I should share what these terms means and difference between them with my readers. so here it goes&#8230;</span></p>
<p style="text-align:justify;"><span style="text-decoration:underline;"><span style="color:#000080;text-decoration:underline;"><strong>ServiceDescriptionImporter :</strong></span></span></p>
<p style="text-align:justify;">The ServiceDescriptionImporter class allows you to easily import the information contained in a WSDL description into a System.CodeDom.CodeCompileUnit object.</p>
<p style="text-align:justify;">By adjusting the value of the Style parameter, you can instruct a ServiceDescriptionImporter instance either to generate a client proxy class that provides the functionality of the Web service by transparently calling it or to generate an abstract class that encapsulates the functionality of the Web service without implementing it.</p>
<p style="text-align:justify;">The code in the resulting CodeCompileUnit object can then either be called directly or exported in the language of your choice.</p>
<p><span style="text-decoration:underline;"><span style="color:#000080;text-decoration:underline;"><strong>ServiceContractGenerator: </strong></span></span></p>
<p style="text-align:justify;">The System.ServiceModel.Description.ServiceContractGenerator type generates service contract code and binding configurations from System.ServiceModel.Description.ServiceEndpoint description objects.</p>
<p style="text-align:justify;"><span style="text-decoration:underline;"><span style="color:#339966;text-decoration:underline;"><strong>ServiceContractGenerator vs ServiceDescriptionImporter:</strong></span></span></p>
<p>&#8211;&gt;ServiceDescriptionImporter is the class that is used by the &#8220;Add Web Reference&#8221; dialog in VS and the &#8220;wsdl.exe&#8221; tool in the SDK to generate &#8220;asmx&#8221; style client web service proxies.</p>
<p>ServiceContractGenerator is the WCF equivalent, for the &#8220;Add Service Reference&#8221; dialog in VS and the &#8220;svcutil.exe&#8221; tool in the SDK.</p>
<p>&#8211;&gt; ServiceDescriptionImporter uses the asmx client infrastructure (System.Web.Services.Protocols.SoapHttpClientProtocol and friends).</p>
<p>ServiceContractGenerator uses the WCF client infrastructure (System.ServiceModel.ClientBase and friends).</p>
<p><strong>Hope this will help !!!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/977/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=977&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/10/13/servicecontractgenerator-vs-servicedescriptionimporter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>Awarded by Microsoft &#8211; Microsoft Community contributor Award 2011</title>
		<link>http://ramanisandeep.net/2011/04/28/awarded-by-microsoft-microsoft-community-contributor-award-2011/</link>
		<comments>http://ramanisandeep.net/2011/04/28/awarded-by-microsoft-microsoft-community-contributor-award-2011/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 07:32:29 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[Mics]]></category>
		<category><![CDATA[Award]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Ramani Sandeep]]></category>
		<category><![CDATA[Sandeep Ramani]]></category>

		<guid isPermaLink="false">http://ramanisandeep.wordpress.com/?p=966</guid>
		<description><![CDATA[Awarded by Microsoft &#8211; Microsoft Community contributor Award 2011.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=966&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#ff9900;"><strong>Awarded by Microsoft &#8211; Microsoft Community contributor Award 2011.</strong></span></p>
<p><a href="http://ramanisandeep.files.wordpress.com/2010/05/mcc11_logo_horizontal_full-color.png"><img class="alignleft size-full wp-image-967" title="MCC11_Logo_Horizontal_Full-color" src="http://ramanisandeep.files.wordpress.com/2010/05/mcc11_logo_horizontal_full-color.png" alt="Microsoft Community Contributor Award" width="346" height="141" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/966/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=966&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/04/28/awarded-by-microsoft-microsoft-community-contributor-award-2011/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>

		<media:content url="http://ramanisandeep.files.wordpress.com/2010/05/mcc11_logo_horizontal_full-color.png" medium="image">
			<media:title type="html">MCC11_Logo_Horizontal_Full-color</media:title>
		</media:content>
	</item>
		<item>
		<title>Tips/Trick : Session timeout problem in IIS7</title>
		<link>http://ramanisandeep.net/2011/03/19/tipstrick-session-timeout-problem-in-iis7/</link>
		<comments>http://ramanisandeep.net/2011/03/19/tipstrick-session-timeout-problem-in-iis7/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 09:42:44 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[IIS 7]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[session timeout]]></category>
		<category><![CDATA[session timeout in asp.net]]></category>
		<category><![CDATA[session timeout in iis 7]]></category>
		<category><![CDATA[session timeout in iis or web config]]></category>

		<guid isPermaLink="false">http://ramanisandeep.wordpress.com/?p=962</guid>
		<description><![CDATA[Hi all, Recently we did release to a staging environment running IIS7.x, .NET 3.5. after few days of release users get problem of session timeout when user leave the pc for an hour or more than that. So I have started to search for the cause. Looked into the session timeout settings in web.config of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=962&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>Recently we did release to a staging environment running IIS7.x, .NET 3.5. after few days of release users get problem of session timeout when user leave the pc for an hour or more than that. So I have started to search for the cause.</p>
<p>Looked into the session timeout settings in web.config of the application. we already set timeout to 180 minutes (3 hour). So I have tested it myself &amp; came to know that user session get expires after 20 minutes (which is the default setting).</p>
<p>So I started looking into the IIS settings and came to know that i missed two things to change :</p>
<ol>
<li> <strong>Application pool&#8217;s Idle Time-out</strong>(minutes)</li>
<li><strong>Session state</strong> &#8211; State server&#8217;s Time-out (seconds)</li>
</ol>
<p>Once I have changed above settings than after Session timeout worked.</p>
<p>So after that I have made one checklist that can help us to validate Session timeout settings, here i am sharing it with you as well so that you will also get some benefits from it :</p>
<ol>
<li> <strong>Application Pool</strong> &#8211; Advanced Settings Menu &#8211; Process Model &#8211; Idle Time-out (minutes)</li>
<li> Sites &#8211; <strong>Session State</strong> &#8211; Cookie Settings &#8211; Time-out (minutes)</li>
<li> If you are using <strong>State Server</strong> or <strong>SQL Server</strong> to manage your session (instead of InProcess), Here is the steps to follow :       Sites &#8211; Session State &#8211; Session State Mode Settings &#8211; Time-out (seconds)</li>
<li> Under <strong>Web.config</strong> &#8211; system.web &#8211; authentication mode &#8211; forms &#8211; timeout (for form authentication)</li>
</ol>
<p>That is all , no more things you need to set in order to increase session timeout from its default value.</p>
<p>Simple but very useful tips.</p>
<p><em><strong>Hope this will help !!!</strong></em></p>
<p><span style="color:#ff6600;">Jay Ganesh</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/962/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/962/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/962/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/962/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/962/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/962/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/962/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/962/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/962/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/962/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/962/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/962/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/962/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/962/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=962&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/03/19/tipstrick-session-timeout-problem-in-iis7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>23.052108 72.533442</georss:point>
		<geo:lat>23.052108</geo:lat>
		<geo:long>72.533442</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
		<item>
		<title>Tips/Tricks &#8211; Hide popup when click on background part</title>
		<link>http://ramanisandeep.net/2011/03/05/tipstricks-hide-popup-when-click-on-background-part/</link>
		<comments>http://ramanisandeep.net/2011/03/05/tipstricks-hide-popup-when-click-on-background-part/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 05:26:27 +0000</pubDate>
		<dc:creator>Ramani Sandeep</dc:creator>
				<category><![CDATA[Ajax Toolkit]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ajax toolkit]]></category>
		<category><![CDATA[Hide popup when click on background]]></category>
		<category><![CDATA[modal popup window]]></category>
		<category><![CDATA[ModalPopupExtender]]></category>
		<category><![CDATA[popup window]]></category>

		<guid isPermaLink="false">http://ramanisandeep.wordpress.com/?p=957</guid>
		<description><![CDATA[Whenever we use ajax ModalPopupExtender to show popup window, we always get into the situation where we need to hide the popup based on background click. CancelControlID property helps to close popup by clicking on control specified in it. But what if we required to close it by clicking background of popup? So here is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=957&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Whenever we use ajax <strong>ModalPopupExtender</strong> to show popup window, we always get into the situation where we need to hide the popup based on background click. <em>CancelControlID </em>property helps to close popup by clicking on control specified in it. But what if we required to close it by clicking background of popup? So here is some workaround to achieve it.</p>
<p style="text-align:justify;">The modal popup extender automatically creates a div HTML element that is used for the background. so we can hide the popup by :</p>
<ol>
<li>Fetching the background div ID and</li>
<li> Add one event handler (click) to that div</li>
</ol>
<p style="text-align:justify;">Once we follow two steps , we can able to hide the popup on background click. I hope this is simple. so Lets start&#8230;</p>
<p><span style="color:#0000ff;"><strong>How to fetch div HTML element used for the background :</strong></span></p>
<p style="text-align:justify;">To get the ID of the background div, add <strong>&#8220;_backgroundElement&#8221;</strong> to the name of your ModalPopupExtender runtime ID. Why, because modal popup extender automatically creates a div HTML element with ID which contains :</p>
<blockquote><p>ModalPopupExtender ID + &#8220;_backgroundElement&#8221;</p></blockquote>
<p>i.e. <strong>&#8220;ctl00_mpeTest_backgroundElement&#8221;</strong> , here <em>mpeTest</em> is our ModalPopupExtender&#8217;s ID</p>
<p>Now our task to fetch that div ID, here is the jQuery code that can help us to achieve it :</p>
<p><pre class="brush: jscript;">
   var modalWindow = '&lt;%= mpeTest.ClientID %&gt;';
   var backgroundElement = $get(modalWindow + '_backgroundElement');
</pre></p>
<p>Here &#8216;<strong>mpeTest</strong>&#8216; is the ID of ModalPopupExtender.</p>
<p><span style="color:#0000ff;"><strong>Add event handler to the background div</strong> :</span></p>
<p>Here is the code to add click event to backgroundElement :</p>
<p><pre class="brush: jscript;">
  var modalWindow = '&lt;%= mpeTest.ClientID %&gt;';
  var backgroundElement = $get(modalWindow + '_backgroundElement');
  $addHandler(backgroundElement, 'click', hideModalPopupViaClient);
</pre></p>
<p style="text-align:justify;">&#8216;<strong>hideModalPopupViaClient</strong>&#8216; is the javascript function name which will be called when we click on background of the popup window.</p>
<p><span style="color:#0000ff;"><strong>Example</strong> :</span></p>
<p style="text-align:justify;">Here is the complete listing with all part of code along with css, javascript and ASPX page code with controls used in it.</p>
<p><span style="color:#008000;"><strong>Listing #1 :</strong></span> <em>style sheet classes used for modalpopup and its background </em></p>
<p><pre class="brush: css;">

 &lt;style&gt;
        .modalBackground
        {
            background-color: gray;
            filter: alpha(opacity=70);
            -moz-opacity: 0.70;
            opacity: 0.70;
        }
        .modalPopup
        {
            background-color: #fff;
            border-width: 1px;
            border-style: solid;
            border-color: #000;
            width: auto;
            height: auto;
            text-align: center;
        }
    &lt;/style&gt;

</pre></p>
<p><span style="color:#008000;"><strong>Listing #2 :</strong></span> <em>jQuery script specify how we can show/hide modalpopup</em></p>
<p><pre class="brush: jscript;">

 &lt;script src=&quot;js/jquery-1.4.2.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot;&gt;
        function ShowPopup() {

            //show modal popup window
            var modalWindow = '&lt;%= mpeTest.ClientID %&gt;';
            $find(modalWindow).show();

            //add event handler to hide the modal popup when user click background of the popup window
            var backgroundElement = $get(modalWindow + '_backgroundElement');
            if (backgroundElement) $addHandler(backgroundElement, 'click', hideModalPopupViaClient);

            return false;
        }

        function hideModalPopupViaClient() {

            //hide modal popup window
            var modalPopupBehavior = $find('&lt;%= mpeTest.ClientID %&gt;');

            if (modalPopupBehavior) {
                modalPopupBehavior.hide();
            }
        }
    &lt;/script&gt;

</pre></p>
<p>I have given enough explaination in above section , so no need to describe it again.</p>
<p><span style="color:#008000;"><strong>Listing #3 :</strong></span> <em>ASPX page content , where I have taken ModalPopupExtender and set few property of it to let it work.</em></p>
<p><pre class="brush: xml;">

&lt;ajaxtoolkit:ToolkitScriptManager ID=&quot;scriptManager&quot; runat=&quot;server&quot;&gt;&lt;/ajaxtoolkit:ToolkitScriptManager&gt;

&lt;asp:ImageButton ID=&quot;imgBtnTour&quot; runat=&quot;server&quot; ImageUrl=&quot;~/Images/movie_icon.jpg&quot;
            Width=&quot;80&quot; OnClientClick=&quot;return ShowPopup();&quot; /&gt;

&lt;asp:Button runat=&quot;server&quot; ID=&quot;btnHiddenPopUp&quot; Style=&quot;display: none&quot; /&gt;

&lt;ajaxtoolkit:ModalPopupExtender ID=&quot;mpeTest&quot; runat=&quot;server&quot; TargetControlID=&quot;btnHiddenPopUp&quot;
            PopupControlID=&quot;panSaving&quot; BackgroundCssClass=&quot;modalBackground&quot; DropShadow=&quot;true&quot;
            RepositionMode=&quot;RepositionOnWindowResize&quot; CancelControlID=&quot;imgClose&quot; /&gt;

&lt;asp:Panel runat=&quot;server&quot; CssClass=&quot;modalPopup&quot; ID=&quot;panSaving&quot; Style=&quot;display: none&quot;&gt;
    	&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot;&gt;
         	&lt;tr&gt;
                    &lt;td style=&quot;padding: 5px 5px 0px 0px&quot; align=&quot;right&quot;&gt;
                        &lt;asp:Image ID=&quot;imgClose&quot; runat=&quot;server&quot; ImageUrl=&quot;~/Images/close.png&quot; /&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;h1&gt;
                            This is modal popup message&lt;/h1&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
&lt;/asp:Panel&gt;

</pre></p>
<p><strong><em>Thats it !!! </em></strong></p>
<p><strong><em>Hope this will help !!!</em></strong></p>
<p><span style="color:#ff6600;"><em>Jay Ganesh</em></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramanisandeep.wordpress.com/957/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramanisandeep.wordpress.com/957/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramanisandeep.wordpress.com/957/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramanisandeep.wordpress.com/957/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramanisandeep.wordpress.com/957/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramanisandeep.wordpress.com/957/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramanisandeep.wordpress.com/957/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramanisandeep.wordpress.com/957/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramanisandeep.wordpress.com/957/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramanisandeep.wordpress.com/957/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramanisandeep.wordpress.com/957/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramanisandeep.wordpress.com/957/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramanisandeep.wordpress.com/957/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramanisandeep.wordpress.com/957/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramanisandeep.net&#038;blog=4219553&#038;post=957&#038;subd=ramanisandeep&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramanisandeep.net/2011/03/05/tipstricks-hide-popup-when-click-on-background-part/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>23.019702 72.536750</georss:point>
		<geo:lat>23.019702</geo:lat>
		<geo:long>72.536750</geo:long>
		<media:content url="http://0.gravatar.com/avatar/6d269205ff05eb290eed22b7d422b7ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sandy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
