Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6590939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:21:45+00:00 2026-05-25T17:21:45+00:00

I have a client-server application, which intercommunicate via WCF. They also both use Castle

  • 0

I have a client-server application, which intercommunicate via WCF. They also both use Castle Windsor for resolving dependencies.

My goal, is to completely avoid having to explicitly register server, or client WCF endpoints.
I have achieved the server-side by ‘convention’ using the following code

// registers all services which implement exactly 1 [ServiceContract]
_windsorContainer.Register(
AllTypes.FromThisAssembly().IncludeNonPublicTypes().Where(
    t => 1 == (from i in t.GetInterfaces() where i.IsDefined(typeof(ServiceContractAttribute), true) select i).Count())
    .Configure(c => c.LifeStyle.PerWcfSession()
    .ActAs(new DefaultServiceModel().AddEndpoints(
         WcfEndpoint.BoundTo(new NetTcpBinding())
             .At("net.tcp://" + LocalAddress.ToString() + ":7601/" + c.ServiceType.Name),
         WcfEndpoint.FromEndpoint(new UdpDiscoveryEndpoint())
            ))

    ).WithService.Select(
    (Type type, Type[] baseTypes) => from i in type.GetInterfaces() where i.IsDefined(typeof(ServiceContractAttribute), true) select i
    )
);

This code will find all classes in the current assembly, and any which implement a service-contract interface (identified by the ServiceContract attribute) will be registered (with UDP discovery) at the address “net.tcp://localhost:7601/[service-contract-interface-name]”.

Now, I just want the client-side of the equation.

Typically, to use castle to generate client-proxies for WCF contracts, the following code will work:

var model = new DefaultClientModel
{
    Endpoint = WcfEndpoint.ForContract<IServiceContract>().BoundTo(new NetTcpBinding()).Discover(typeof(IServiceContract))
};

container.Register(
    Component.For<ChannelReconnectPolicy>(),
    Castle.Facilities.WcfIntegration.WcfClient.ForChannels(model),
);

What I want, is for Castle to do this kind of registration for all ‘service-contract’ interfaces in a given assembly – however the AllTypes helper seems to return only classes, not interfaces (which I guess makes it an ‘AllClasses’, not ‘AllTypes’!)… Can Castle do this, and what is the syntax? Krzysztof? (help!)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:21:46+00:00Added an answer on May 25, 2026 at 5:21 pm

    Apologies for such a late reply – a developer’s life is never a quiet one!

    I dug out the code, and its not as ‘succinct’ as I would have liked, perhaps someone can look at integrating something like this in to Castle… but here goes…

    // these are all the namespaces that will be scanned for WCF service contracts
    string[] remoteServiceNamespaces 
        = new string[] { "MyContracts.Services", "Interlinq" };
    
    // everything from here on is in the Castle DLLs (all the types)
    List<IRegistration> clientContractRegistrations = new List<IRegistration>();
    foreach (
        var interfaceContract in
        (from s in remoteServiceNamespaces
        select (from i in Assembly.LoadWithPartialName(s).GetTypes()
            where i.IsInterface
            && 
            i.IsDefined(typeof(ServiceContractAttribute), false)
            select i)).SelectMany( x => x )
        )
    {
        ServiceContractAttribute attr 
            = Attribute.GetCustomAttribute(
                        interfaceContract, 
                        typeof(ServiceContractAttribute)) 
                        as ServiceContractAttribute;
        if (null != attr)
        {
        WcfClientModelBase model = null;
    
        // here we handle the case of the service being duplex...
        if (null != attr.CallbackContract)
        {
            model = new DuplexClientModel
            {
            // All the automatically registered services will use NetTcp, 
            // and will discover their addresses (you could use binding 
            // inference aswell if you liked)
            // here I have a method called 'CreateNetTcpBinding' which 
            // creates my custom binding that ALL my services use.
            Endpoint = 
                     WcfEndpoint.ForContract(interfaceContract)
                     .BoundTo(CreateNetTcpBinding())
                     .Discover(interfaceContract)
                     .PreferEndpoint(list => list[0])
            }.Callback(_windsor.Resolve(attr.CallbackContract));
        }
        else
        {
            model = new DefaultClientModel
            {
            Endpoint = WcfEndpoint.ForContract(interfaceContract)
                        .BoundTo(new NetTcpBinding())
                        .Discover(interfaceContract)
                        .PreferEndpoint(list => list[0])
            };
        }
        clientContractRegistrations.Add(WcfClient.ForChannels(model));
        }
    }
    
    // now that we've built our registration list, let's actually register 
    // them all with Windsor
    _windsor.Register(
        clientContractRegistrations.ToArray()
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client-server Silverlight application, which is use Socets. I have server appliaction
i have a client & server application which communicate using WCF. To add some
I have a client-server application, which communicates using WCF, and uses NetDataContractSerializer to serialize
I have a client/server style application which communicates using WCF which all works great.
Need to create a client server application, both have to communicate with Database. Which
I have a client server application in which the server and the client need
I have a client server application in which I need to transmit a user
I want to create an application which will have a client and server components.
We have a Server/Client cybercafe management application which used to work fine on Windows
I am developing an application in C# WPF which will have Client-Server architecture (Client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.