Though WCF routing features for content-based routing, protocol bridging, and error handling seem to be very exciting, I have faced some issues while defining their security context in Routing service environment. In this article, we will discuss custom authentication and security for routing services.
- Routing_Service_POC.zip
- Routing_Service_POC
- POC
- library
- ICSharpCode.SharpZipLib.dll
- Ionic.Zip.dll
- RoutingServicePOC
- _ReSharper.RoutingServicePOC
- BuildScriptCache
- .crc
- .version
- 5
- 9
- 6ecd42b4.dat
- DecompilerCache
- ModuleIds.xml
- NamedArguments
- .crc
- .version
- 1
- 8
- 64bd7be7.dat
- PdbInfo
- ProjectModel
- ProjectModel.dat
- Resources
- .crc
- .version
- SymbolCache.bin
- TagPrefixes
- .crc
- .version
- 0
- 1
- 2
- 5
- 5402198f.dat
- 6
- TodoCache
- .crc
- .version
- 5
- 5402198f.dat
- 7
- WebsiteFileReferences
- .crc
- .version
- WordIndex
- .crc
- .version
- 1
- 3da9581c.dat
- 3
- Client
- ClientCommonLib
- GlobalCommonLib
- RoutingServicePOC.5.1.ReSharper.user
- RoutingServicePOC.sln
- RoutingServicePOC.suo
- RoutingServicePOC
- ServiceA.Contract
- ServiceA
- ServiceB.Contract
- ServiceB
- ServiceCommonLib
- Routing_Service_POC-noexe.zip
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.ServiceModel;
using GlobalCommonLib;
namespace ClientCommonLib
{
public class CentralSessionEndpointBehavior : IEndpointBehavior
{
public CentralSessionEndpointBehavior()
{
}
public CentralSessionEndpointBehavior(string user, string password)
{
this.User = user;
this.Password = password;
}
public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{ }
public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.ClientRuntime behavior)
{
//Add the inspector
behavior.MessageInspectors.Add(new CentralSessionClientMessageInspector(this.User, this.Password));
}
public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{ }
public void Validate(ServiceEndpoint serviceEndpoint)
{ }
public string User { get; set; }
public string Password { get; set; }
}
public class CentralSessionClientMessageInspector : BehaviorExtensionElement, IClientMessageInspector
{
public CentralSessionClientMessageInspector()
{
}
public CentralSessionClientMessageInspector(string user, string password)
{
this.User = user;
this.Password = password;
}
public static event EventHandler<CentralSessionDataEventArgs<System.ServiceModel.Channels.Message>> PreRequestingService;
private void InvokePreRequestingService(CentralSessionDataEventArgs<System.ServiceModel.Channels.Message> e)
{
EventHandler<CentralSessionDataEventArgs<System.ServiceModel.Channels.Message>> handler = PreRequestingService;
if (handler != null) handler(this, e);
}
public static event EventHandler<CentralSessionDataEventArgs<System.ServiceModel.Channels.Message>> PostRequestingService;
private void InvokePostRequestingService(CentralSessionDataEventArgs<System.ServiceModel.Channels.Message> e)
{
EventHandler<CentralSessionDataEventArgs<System.ServiceModel.Channels.Message>> handler = PostRequestingService;
if (handler != null) handler(this, e);
}
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string _user;
public string User
{
get { return _user; }
set { _user = value; }
}
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string _password;
public string Password
{
get { return _password; }
set { _password = value; }
}
public override Type BehaviorType
{
get { return typeof(CentralSessionEndpointBehavior); }
}
protected override object CreateBehavior()
{
return new CentralSessionEndpointBehavior();
}
#region IClientMessageInspector Members
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
InvokePostRequestingService(new CentralSessionDataEventArgs<Message>(reply));
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
CredentialHelper.SetSessionData(_user, _password, ref request);
InvokePreRequestingService(new CentralSessionDataEventArgs<Message>(request));
return null;
}
#endregion
}
public class CentralSessionDataEventArgs<TData> : EventArgs where TData : class
{
readonly TData _data;
public CentralSessionDataEventArgs(TData data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
this._data = data;
}
public TData Data
{
get { return _data; }
}
public override string ToString()
{
return _data.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
In my childhood, my uncle has shown me how to see the cloud in a close look and I understand that one can draw some elements of the Earth in the sky-canvas if he/she wants to. After that the cloud becomes closer to me and It teaches me one thing that, a deeper-look to something will give you some clues to draw your imagination. You can able to see that one which you have build-up in your mind.
Years past, I have started my career as a software engineer and has been looking for passion in my coding and development which I should be to enjoy my profession and has started asking myself- 'am I doing any engineering here?!' Is my code becoming that thing which I have designed in my mind? So to find that answer I have tried that old solution here... I have decided to come closer to my code and start analyzing them. And it is really working for me and at least it gives me the confidence that I can build something that I really want to. I can draw my thinking there through my code and can build-up my vision that I have designed in my mind. It also helps me to think out of the box, solve each problems by making blocks and make me careful on each steps.
• Morshed's Technical Blog site: http://morshedanwar.wordpress.com/
• Morshed's Technical articles those are published in Codeproject site: http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=2992452
• Morshed's Linkedin profile: http://www.linkedin.com/in/morshedanwar
• Morshed's Facebook Profile : http://www.facebook.com/morshed.pulok
Beside all these I like to do - photography and music. Here is my Flickr photos : http://www.flickr.com/photos/morshed_anwar/