ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

View: New views
10 Messages — Rating Filter:   Alert me  

ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Khash Sajadi :: Rate this Message:

| View Threaded | Show Only this Message

I'm trying to use WCF Integration Facility with Castle. So far I have the server and the client working fine. The server is hosted in IIS 7 (with a SVC file with no code behind).

Now I need to know the username of the client. For this I'm doing:

OperationContext oc = OperationContext.Current;
ServiceSecurityContext ssc = oc.ServiceSecurityContext;

But the ssc is null. I guess it has something to do with enabling TransportCredentialOnly on binding, but I don't have any bindings (using .NET 4 Default Bindings - through the Facility).

So the question boils down to:

How can I get the client username in a WCF Integration Facility hosted service on the server side.

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/ym4Pmr4aptkJ.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Valeriu Caraulean :: Rate this Message:

| View Threaded | Show Only this Message

Very rough code snippets, adjust them appropriately...

You should first set your bindings to work properly with Transport credentials:

public static Binding DefaultBinding
{
    get
    {
      return new BasicHttpBinding
      {
         // other binding config

         Security =
         {
           Mode = BasicHttpSecurityMode.TransportCredentialOnly,
           Transport = {ClientCredentialType = HttpClientCredentialType.Windows}
         }

Then you can register explicitly your services in container:

Component
   .For<TService>()
   .ImplementedBy<TServiceImpl>()
   .Named(typeof (TService).Name)
   .LifeStyle.Is(lifestyleType)
   .AsWcfService(CreateServiceModel(typeof(TService), binding));

private static DefaultServiceModel CreateServiceModel (Type serviceType, Binding binding)
{
   return new DefaultServiceModel()
    .Hosted()
    .AddEndpoints(WcfEndpoint
      .ForContract(serviceType)
      .BoundTo(binding));
}

Hope this helps...

On Mon, Nov 14, 2011 at 12:41 PM, Khash Sajadi <khash.sajadi@...> wrote:

I'm trying to use WCF Integration Facility with Castle. So far I have the server and the client working fine. The server is hosted in IIS 7 (with a SVC file with no code behind).

Now I need to know the username of the client. For this I'm doing:

OperationContext oc = OperationContext.Current;
ServiceSecurityContext ssc = oc.ServiceSecurityContext;

But the ssc is null. I guess it has something to do with enabling TransportCredentialOnly on binding, but I don't have any bindings (using .NET 4 Default Bindings - through the Facility).

So the question boils down to:

How can I get the client username in a WCF Integration Facility hosted service on the server side.

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/ym4Pmr4aptkJ.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel%2Bunsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Khash Sajadi :: Rate this Message:

| View Threaded | Show Only this Message

Tried that and other varieties. Doesn't make a difference I'm afraid. This is what it looks like now:

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/QIBKEfSmMP0J.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Valeriu Caraulean :: Rate this Message:

| View Threaded | Show Only this Message

Hmm, looks OK for me...

Just to be sure, all configuration is done in code? No WCF sections in web.config?


On Mon, Nov 14, 2011 at 4:27 PM, Khash Sajadi <khash.sajadi@...> wrote:
Tried that and other varieties. Doesn't make a difference I'm afraid. This is what it looks like now:

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/QIBKEfSmMP0J.

To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel%2Bunsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Khash Sajadi :: Rate this Message:

| View Threaded | Show Only this Message

That's right. It's all code based. Anything specific should be done in the client?

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/6bf7pwjbzVsJ.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Valeriu Caraulean :: Rate this Message:

| View Threaded | Show Only this Message

Nothing fancy in our client code:
  var basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly)

That's enough for us to have windows identity of the user on the server.


On Mon, Nov 14, 2011 at 6:12 PM, Khash Sajadi <khash.sajadi@...> wrote:
That's right. It's all code based. Anything specific should be done in the client?
--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/6bf7pwjbzVsJ.

To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel%2Bunsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Valeriu Caraulean :: Rate this Message:

| View Threaded | Show Only this Message

I have a project on GitHub with few examples on how to use WCF without config files.

I've added two projects to it - WebHost.Castle and a simple client project. Check it at:

And the service code is making use of Service's SecurityContext...

Be sure that:
 - WcfWithoutConfigFile.WebHost.Castle is hosted in IIS Express
 - Windows Authentication is enabled for that project

Hope this helps...


On Mon, Nov 14, 2011 at 6:12 PM, Khash Sajadi <khash.sajadi@...> wrote:
That's right. It's all code based. Anything specific should be done in the client?
--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/6bf7pwjbzVsJ.

To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel%2Bunsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Khash Sajadi :: Rate this Message:

| View Threaded | Show Only this Message

Awesome! It worked. I did this to get the client to be config-free as well:


            container
                .AddFacility<WcfFacility>()
                .Register(Types.FromAssemblyContaining<IMyService>()
                              .Where(t => t.Name.EndsWith("Service"))
                              .Configure(c => c.AsWcfClient(
                                  WcfEndpoint
                                      .BoundTo(new BasicHttpBinding() { 
                                          Security = 
                                          {
                                              Mode = BasicHttpSecurityMode.TransportCredentialOnly, 
                                              Transport = { ClientCredentialType = HttpClientCredentialType.Windows }
                                          } 
                                      })
                                      .At(ServiceNameHelper.GetServiceEndpoint(c.Implementation)))));

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/_wNyVkPH9-gJ.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Krzysztof Kozmic-2 :: Rate this Message:

| View Threaded | Show Only this Message

Would you guys care to add that to the documentation wiki for the next guy?

K

On 16/11/2011 8:43 PM, Khash Sajadi wrote:

> Awesome! It worked. I did this to get the client to be config-free as
> well:
>
>
>             container
>                 .AddFacility<WcfFacility>()
>                 .Register(Types.FromAssemblyContaining<IMyService>()
>                               .Where(t => t.Name.EndsWith("Service"))
>                               .Configure(c => c.AsWcfClient(
>                                   WcfEndpoint
>                                       .BoundTo(new BasicHttpBinding() {
>                                           Security =
>                                           {
>                                               Mode =
> BasicHttpSecurityMode.TransportCredentialOnly,
>                                               Transport = {
> ClientCredentialType = HttpClientCredentialType.Windows }
>                                           }
>                                       })
>                                      
> .At(ServiceNameHelper.GetServiceEndpoint(c.Implementation)))));
>
> --
> You received this message because you are subscribed to the Google
> Groups "Castle Project Development List" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/castle-project-devel/-/_wNyVkPH9-gJ.
> To post to this group, send email to
> castle-project-devel@....
> To unsubscribe from this group, send email to
> castle-project-devel+unsubscribe@....
> For more options, visit this group at
> http://groups.google.com/group/castle-project-devel?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.


Re: ServiceSecurityContext is null with Castle Windsor WCF Integration Facility

by Benny Hung :: Rate this Message:

| View Threaded | Show Only this Message

The suggested workaround does work.  But is there a way to make this work with doing the configuration in config files?  Is this actually a bug in the wcf integration facility?

On a somewhat related note, what is the advantage of making things config-less?

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-devel/-/SrGcCdgBwmIJ.
To post to this group, send email to castle-project-devel@....
To unsubscribe from this group, send email to castle-project-devel+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.