23. November 2010 15:48
/
Vitaly Zayko
/
/
Comments (0)
I was looking for a snippet to add a custom header to WCF service request. Why? For example, to add authentication header to add Basic Authentication support. (Yes – WCF supports Basic Authorization by itself but didn’t find how to use it without SSL).
Here is the shortest way.
Use this snippet on your client side:
using (MyServ.ServiceClient proxy = new MyServ.ServiceClient ())
{
using (new System.ServiceModel.OperationContextScope (proxy.InnerChannel))
{
MessageHeader head = MessageHeader .CreateHeader("Authorization" , "http://mynamespace.com/v1" , data);
OperationContext .Current.OutgoingMessageHeaders.Add(head);
}
}
And just in case, here is how to retrieve this information from Http header on the server side:
string auth = OperationContext .Current.
IncomingMessageHeaders.
GetHeader<string >("Authorization" , "http://mynamespace.com/v1" );
More about OperationContextScope Class here.
7d745302-c6c7-471e-a8b0-1b2a0adb569b|1|5.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04
5. November 2010 08:48
/
Vitaly Zayko
/
/
Comments (0)
For a reason .NET lacks FlushWindowEx function so glad we can PInvoke it.
Declare FlushWindowEx and its dependencies:
[StructLayout (LayoutKind .Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public Int32 dwFlags;
public UInt32 uCount;
public Int32 dwTimeout;
}
[Flags ]
public enum FlashMode
{
FLASHW_STOP = 0,
FLASHW_CAPTION = 1,
FLASHW_TRAY = 2,
FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY),
FLASHW_TIMER = 4,
FLASHW_TIMERNOFG = 12
}
[DllImport ("user32.dll" )]
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);
then just call it like this:
FLASHWINFO fw = new FLASHWINFO ();
fw.cbSize = Convert .ToUInt32(Marshal .SizeOf(typeof (FLASHWINFO )));
fw.hwnd = this .Handle;
fw.dwFlags = (Int32 )FlashMode .FLASHW_ALL;
fw.uCount = 5;
FlashWindowEx(ref fw);
57c3d67b-815d-4666-8464-b2d1aa8246b4|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04