<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Jan Schepens</title>
        <link>http://geekswithblogs.net/JanS/Default.aspx</link>
        <description> CODit Product Developer</description>
        <language>nl-BE</language>
        <copyright>Jan Schepens</copyright>
        <managingEditor>jan.schepens@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Jan Schepens</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/JanS/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Never underestimate the power of parameter order</title>
            <link>http://geekswithblogs.net/JanS/archive/2008/09/29/never-underestimate-the-power-of-parameter-order.aspx</link>
            <description>Recently, I ran into an interesting situation&lt;br /&gt;
the client caller of a WCF service method had adjusted his proxy class and for some reason the order of two parameters were switched.&lt;br /&gt;
So let's say I have a method with a boolean parameter and an integer parameter as in X(bool b, int i)&lt;br /&gt;
In this case the proxy was changed to X(int i, bool b)&lt;br /&gt;
&lt;br /&gt;
Now this is where it gets interesting. There is no error whatsoever on execution of the method. When debugging, the method was entered and executed without any trouble. But the boolean did get it's default value false, even when sending a true. &lt;br /&gt;
But the amazing thing was that the int parameter retained value, instead of a default 0, what I would expect.&lt;br /&gt;
&lt;br /&gt;
Conclusion: never underestimate the power of order of parameters&lt;br /&gt;
&lt;br /&gt;
Any WCF experts willing to clear some things up on this matter, don't hesitate to mail me :)&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125517"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125517" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JanS/aggbug/125517.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jan Schepens</dc:creator>
            <guid>http://geekswithblogs.net/JanS/archive/2008/09/29/never-underestimate-the-power-of-parameter-order.aspx</guid>
            <pubDate>Mon, 29 Sep 2008 11:05:10 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JanS/comments/125517.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JanS/archive/2008/09/29/never-underestimate-the-power-of-parameter-order.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/JanS/comments/commentRss/125517.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Adding zip files in a jpg</title>
            <link>http://geekswithblogs.net/JanS/archive/2008/08/19/adding-zip-files-in-a-jpg.aspx</link>
            <description>I don't know how many people already know this, but I just stumbled upon this through another site and I just had to share :)&lt;br /&gt;
&lt;br /&gt;
So I already did some experimenting about 2 years ago with hiding messages in an image file. But I had no idea it was&lt;br /&gt;
this easy to hide a zip in there as well :)&lt;br /&gt;
&lt;br /&gt;
the way to do this just seems to be&lt;br /&gt;
1) create a new folder&lt;br /&gt;
2) place your jpg file and zip file in there&lt;br /&gt;
3) open a command prompt and navigate to your new folder&lt;br /&gt;
4) type COPY /B &amp;lt;picturename&amp;gt;.jpg + &amp;lt;zipname&amp;gt;.zip &amp;lt;resultpicture&amp;gt;.jpg &lt;br /&gt;
&lt;br /&gt;
that will create the result picture in the same folder and if you change the extension of that picture back to .zip, you'll be&lt;br /&gt;
able to extract everything back from the original zip file.&lt;br /&gt;
&lt;br /&gt;
I think that's fun :)&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124539"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124539" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JanS/aggbug/124539.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jan Schepens</dc:creator>
            <guid>http://geekswithblogs.net/JanS/archive/2008/08/19/adding-zip-files-in-a-jpg.aspx</guid>
            <pubDate>Tue, 19 Aug 2008 11:51:14 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JanS/comments/124539.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JanS/archive/2008/08/19/adding-zip-files-in-a-jpg.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JanS/comments/commentRss/124539.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Easily retrieving message body AND context from BizTalk tracking database</title>
            <link>http://geekswithblogs.net/JanS/archive/2008/04/03/easily-retrieving-message-body-and-context-from-biztalk-tracking-database.aspx</link>
            <description>I've been searching for a while now on a way to retrieve message body and context from BizTalk without having to use WMI,&lt;br /&gt;
simply because I didn't want to write my messages to file, read them back in, parse the context and then delete the generated&lt;br /&gt;
files again.&lt;br /&gt;
&lt;br /&gt;
Interesting blog post I stumbled upon was this: &lt;a id="Blogpost" name="Blogpost" title="Post" href="http://connectedthoughts.wordpress.com/2008/04/02/3-ways-of-programatically-extracting-a-message-body-from-the-biztalk-tracking-database/" target="_blank"&gt;View post&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
But this was not sufficient, because no one managed to get the FULL message context from this method. However, there is a very easy way to do this.&lt;br /&gt;
&lt;br /&gt;
First of all, I defined two strings representing a property name, and a property namespace. They will be the out values for our method.&lt;br /&gt;
Now the Context object we get from the tracked message out of the BizTalk Operations dll, implements the Microsoft.BizTalk.Message.Interop.IBaseMessageContext interface. When you look closely at it's methods, you will see a "ReadAt" method. That's the one we need to use.&lt;br /&gt;
The Context object also contains a CountProperties variable, which doesn't need any further explanation I think.&lt;br /&gt;
So the next part is pretty straight-forward right? &lt;br /&gt;
Loop through the CountProperties values, use them as indexes, and call the ReadAt(index, name, namespace) method &lt;br /&gt;
for every loop passage, and hold the property value in another string variable.&lt;br /&gt;
&lt;br /&gt;
                string sname = "";&lt;br /&gt;
                string snamespace = "";&lt;br /&gt;
&lt;br /&gt;
                for (int i = 0; i &amp;lt; imsg.Context.CountProperties; i++)&lt;br /&gt;
                {&lt;br /&gt;
                    string value = imsg.Context.ReadAt(i, out sname, out snamespace).ToString();&lt;br /&gt;
                    Console.WriteLine(sname + " (" + snamespace + ") = " + value);&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
And there you have it! Full message context!&lt;br /&gt;
Enjoy experimenting with this very cool way of getting body and context of a BizTalk message! IMHO, this is a much better&lt;br /&gt;
approach than the WMI way.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120989"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120989" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JanS/aggbug/120989.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jan Schepens</dc:creator>
            <guid>http://geekswithblogs.net/JanS/archive/2008/04/03/easily-retrieving-message-body-and-context-from-biztalk-tracking-database.aspx</guid>
            <pubDate>Thu, 03 Apr 2008 12:01:41 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JanS/comments/120989.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JanS/archive/2008/04/03/easily-retrieving-message-body-and-context-from-biztalk-tracking-database.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JanS/comments/commentRss/120989.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Processing custom WCF header values at server-side</title>
            <link>http://geekswithblogs.net/JanS/archive/2008/03/17/processing-custom-wcf-header-values-at-server-side.aspx</link>
            <description>Well since my previous post was about passing information from client to server in a WCF header, this post is about processing&lt;br /&gt;
the incoming header to retrieve the original username.&lt;br /&gt;
&lt;br /&gt;
If you read my previous post, I used a class RequestAuth and ProcessAuth. This post will explain the ProcessAuth class.&lt;br /&gt;
&lt;br /&gt;
This time I need to FETCH something from the message, so instead of implementing IClientMessageInspector, I need to implement the IDispatchMessageInspector interface,&lt;br /&gt;
together with the IEndpointBehavior interface again, and I need to inherit from BehaviorExtensionElement again, so I can add this&lt;br /&gt;
functionality to my endpoint behavior.&lt;br /&gt;
&lt;br /&gt;
In the previous post, I explained that it can be convenient to override BehaviorType and CreateBehavior, so I'll do this again:&lt;br /&gt;
        public override Type BehaviorType&lt;br /&gt;
        {&lt;br /&gt;
            get { return typeof(ProcessAuth); }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        protected override object CreateBehavior()&lt;br /&gt;
        {&lt;br /&gt;
            return new ProcessAuth();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Also, to store the current user to send to the server, I'll hold a private field userName:&lt;br /&gt;
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)] &lt;br /&gt;
private string userName;&lt;br /&gt;
&lt;br /&gt;
Now, for the IDispatchMessageInspector implementation, it's fairly simple when you think about it. At client-side, I implemented the&lt;br /&gt;
BeforeSendRequest of the IClientMessageInspector interface. Now I am at server-side level, so I need to implement AfterReceiveRequest of&lt;br /&gt;
the IDispatchMessageInspector interface.&lt;br /&gt;
&lt;br /&gt;
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)&lt;br /&gt;
        {&lt;br /&gt;
            sUser = request.Headers.GetHeader&amp;lt;string&amp;gt;("SomeName", "http://SomeNameSpace", "Anyone");&lt;br /&gt;
            return CheckSecurity();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
NOTE: I'm using the same name and namespace for the header as I did at client-side level. This is of course very logically that those two&lt;br /&gt;
need to be the same :) otherwise you would never get the right values.&lt;br /&gt;
At the end of the method I return CheckSecurity(). This is a boolean method which you can implement at your own needs, it just returns true&lt;br /&gt;
or false depending of the access-allowed level of the requesting user. &lt;br /&gt;
&lt;br /&gt;
And that's it for the MessageInspector part! Of course, we also need to add this inspector to every incoming request. This is where theIEndpointBehavior interface comes in again. However, instead of implementing the ApplyClientBehavior method (client-side), we need&lt;br /&gt;
to implement the ApplyDispatchBehavior this time, for server-side.&lt;br /&gt;
&lt;br /&gt;
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)&lt;br /&gt;
        {&lt;br /&gt;
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
THAT'S IT FOR THE SERVER SIDE!!! &lt;br /&gt;
Adding this to your server endpoints can be done in the same way I did it in the client configurations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TO SUMMARIZE: Well, we actually did a lot of work in here with very little code writing. But in my opinion, this shows a nice feature of&lt;br /&gt;
customizing WCF.&lt;br /&gt;
With this example, you can use your own WCF headers to send some information to the server, and process it there. And not only that, but&lt;br /&gt;
you can do this completely automatically by using custom endpoint behaviors.&lt;br /&gt;
&lt;br /&gt;
So that's it concerning my first blogpost :) hope you enjoyed, and feel free to give some feedback!&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120596"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120596" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JanS/aggbug/120596.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jan Schepens</dc:creator>
            <guid>http://geekswithblogs.net/JanS/archive/2008/03/17/processing-custom-wcf-header-values-at-server-side.aspx</guid>
            <pubDate>Mon, 17 Mar 2008 15:41:14 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JanS/comments/120596.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JanS/archive/2008/03/17/processing-custom-wcf-header-values-at-server-side.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JanS/comments/commentRss/120596.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Automate passing valuable information in WCF headers</title>
            <link>http://geekswithblogs.net/JanS/archive/2008/03/17/automate-passing-valuable-information-in-wcf-headers.aspx</link>
            <description>OK so this is my first blogpost (EVER) so I hope it'll be of value to some people.&lt;br /&gt;
&lt;br /&gt;
This post is about passing through some information at the client to the server, and how to automate this using the WCF configuration.&lt;br /&gt;
&lt;br /&gt;
Case study:&lt;br /&gt;
I was with a client, developing WCF services which are hosted on IIS. Since they already have a wide range of security settings stored in databases, it would be a shame to let go of those configurations and force a whole new security model on them instead of trying to integrate their configs into the services.&lt;br /&gt;
We have several end users surfing to an intranet site (which is our WCF client), while the site communicates with several servers running WCF services on IIS. The site runs under a simple network service so the Windows Authentication is guaranteed server-side.&lt;br /&gt;
But to ensure security for several users (not everyone is allowed to view the same information) we want to pass the current username to the WCF service, and perform a security check with the client configurations, before returning any results.&lt;br /&gt;
&lt;br /&gt;
How do we do this? Well there are probably tons of solutions available, but the way that worked the easiest for me (and my client) is working with custom behaviors on the endpoints, where the username will be passed in a WCF header.&lt;br /&gt;
&lt;br /&gt;
So we need two classes: one to add the header client-side, and one to process the username server-side. In my example, I call them RequestAuth and ProcessAuth. Let's start out with RequestAuth.&lt;br /&gt;
&lt;br /&gt;
Since I want to add something to the message at the endpoint level, I'll need to implement the IClientMessageInspector interface, which is found in the System.ServiceModel.Dispatcher namespace, and the IEndpointBehavior interface, in the System.ServiceModel.Description namespace. BUT, since we are going to add this to a behavior, we need to inherit from the BehaviorExtensionElement class, in the System.ServiceModel.Configuration namespace.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now before we start implementing, bare in mind that it might come in handy to override the BehaviorType property of BehaviorExtensionElement, as well as the CreateBehavior() method. This is done easily by doing: &lt;br /&gt;
    public override Type BehaviorType&lt;br /&gt;
    {&lt;br /&gt;
            get { return typeof(RequestAuth); }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    protected override object CreateBehavior()&lt;br /&gt;
    {&lt;br /&gt;
            return new RequestAuth();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Also, to store the current user to send to the server, I'll hold a property UserName:&lt;br /&gt;
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)] &lt;br /&gt;
private string userName;&lt;br /&gt;
&lt;br /&gt;
    public string UserName&lt;br /&gt;
    {&lt;br /&gt;
            get { return userName; }&lt;br /&gt;
            set { userName = value; }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Note: by using the System.Diagnostics.DebuggerBrowsable attribute and setting it to never, no client will ever get to see the private fields in your code. Not only is this safer, but it also gives a better debugger view when debugging.&lt;br /&gt;
Now, while it is not necessary anymore in .NET 3.5 to link a property to a private field, this example was written in .NET 2.0, so if you are redoing this in 3.5 you won't need the username field.&lt;br /&gt;
&lt;br /&gt;
On to the implementations then! At first, I have to implement the IClientMessageInspector members.&lt;br /&gt;
Keeping in mind that I am SENDING something to the server, I only need to implement the BeforeSendRequest method.&lt;br /&gt;
&lt;br /&gt;
So we need to make a MessageHeader object of string to send the username. After that, I try to retrieve the current logged on user.&lt;br /&gt;
In here I needed to make a difference between web applications and desktop applications. But if you are certain that you will ALWAYS&lt;br /&gt;
run in one environment (web or desktop) you can drop the check and keep the right username&lt;br /&gt;
Now, before I did the actual implementation, I keep a name and a namespace for my header in two private fields, so I can easily find&lt;br /&gt;
them back server side.&lt;br /&gt;
    [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)] &lt;br /&gt;
        private string hName = "SomeName"; //use your own name for the header in here&lt;br /&gt;
        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)] &lt;br /&gt;
        private string hNameSpace = "http://SomeNameSpace"; //use own namespace here&lt;br /&gt;
&lt;br /&gt;
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)&lt;br /&gt;
        {&lt;br /&gt;
            MessageHeader&amp;lt;string&amp;gt; header = new MessageHeader&amp;lt;string&amp;gt;();&lt;br /&gt;
            header.Actor = "Anyone";&lt;br /&gt;
            &lt;br /&gt;
            //Keep the difference between web environments and desktop environments&lt;br /&gt;
            if (System.Web.Hosting.HostingEnvironment.IsHosted)&lt;br /&gt;
            {&lt;br /&gt;
                if (OperationContext.Current != null)&lt;br /&gt;
                    UserName = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    if(System.Web.HttpContext.Current != null)&lt;br /&gt;
                        UserName = System.Web.HttpContext.Current.User.Identity.Name;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
                UserName = System.Threading.Thread.CurrentPrincipal.Identity.Name;&lt;br /&gt;
&lt;br /&gt;
            //Add the username to the header&lt;br /&gt;
            header.Content = UserName;&lt;br /&gt;
&lt;br /&gt;
            //Creating an untyped header to add to the WCF context&lt;br /&gt;
            System.ServiceModel.Channels.MessageHeader unTypedHeader = header.GetUntypedHeader(hName, hNameSpace);&lt;br /&gt;
&lt;br /&gt;
            //Add the header to the current request&lt;br /&gt;
            request.Headers.Add(unTypedHeader);&lt;br /&gt;
&lt;br /&gt;
            return null;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
So the previous code snippet will add a string containing the username to the WCF request. But to do this for every request, we still&lt;br /&gt;
need to add the MessageInspector we just implemented to the behavior. So on to the implementation of the IEndpointBehavior interface!&lt;br /&gt;
Well there's nothing much to it in this part, but to use the current clientbehavior and add the inspector:&lt;br /&gt;
        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)&lt;br /&gt;
        {&lt;br /&gt;
            clientRuntime.MessageInspectors.Add(this);&lt;br /&gt;
        }&lt;br /&gt;
NOTE: I use &amp;lt;this&amp;gt; as parameter, because the class we are working in IS a message inspector, thanks to the IClientMessageInspector interface&lt;br /&gt;
we implemented.&lt;br /&gt;
&lt;br /&gt;
THAT'S IT FOR THE CLIENT SIDE!!! If you build this in an assembly and sign it, you will be able to add this in your WCF config file.&lt;br /&gt;
HOW? Simple: Open your WCF config file with the WCF Config Editor tool (SvcConfig.exe). Under the "Advanced" node, within "Extensions", you have&lt;br /&gt;
a node "behavior element extensions". That's where you click New, give your extension a name, and browse to your newly created assembly, and select&lt;br /&gt;
the correct behavior element to add (if you have multiple in one assembly). In this case, you need to select the RequestAuth item.&lt;br /&gt;
Once this is done, you can navigate to your Endpoint Behaviors, and in your behavior, if you click Add, you will see the new extension in the&lt;br /&gt;
list of available extensions. From now on, every service that uses this endpoint behavior will add the new username header to every outgoing request&lt;br /&gt;
it makes.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120595"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120595" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JanS/aggbug/120595.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jan Schepens</dc:creator>
            <guid>http://geekswithblogs.net/JanS/archive/2008/03/17/automate-passing-valuable-information-in-wcf-headers.aspx</guid>
            <pubDate>Mon, 17 Mar 2008 15:25:10 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JanS/comments/120595.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JanS/archive/2008/03/17/automate-passing-valuable-information-in-wcf-headers.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/JanS/comments/commentRss/120595.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>