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

  • SEARCH
  • Home
  • 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 7765057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:04:45+00:00 2026-06-01T15:04:45+00:00

I have a WCF environment hosted on a windows service. I have two hosts

  • 0

I have a WCF environment hosted on a windows service. I have two hosts (one on TCP and another on NamedPipes). Don’t be alarmed about the multiple hosts – this is a messaging engine and hosts are mounted dynamically based on the configuration. No matter how many types of hosts I have, there is only one service implementation. Now the problem is, when my service implementation is invoked by an incoming call, how do I identify whether it was from host A or host B? While hosting each type, can I specify some metadata which identifies the host information so that I can access it from the implementation? Please help.

Thanks,
James

  • 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-06-01T15:04:47+00:00Added an answer on June 1, 2026 at 3:04 pm

    I found a nice solution for the issue I was facing. Normally when we host a WCF endpoint this is the code we follow.

    ServiceHost serviceHost = new ServiceHost(typeof(IService))
    

    Here you pass in the type of the interface you expose to the ServiceHost instance. Instead of this approach, you can make use of the second overload of the ServiceHost constructor which takes in an instantiated object! Now the code looks like this

    ServiceImplementation implementation1 = new ServiceImplementation();
    ServiceHost serviceHost = new ServiceHost(implementation1);
    

    Only thing to note here is that you need to mark your implementation instance mode as a ‘InstanceContextMode.Single‘, effectively making it a Singlreton.

    Now the way it solves my problem is that I use my implementation class to pass any metadata from the host to the implementation. My code now looks like this.

    // Create a metadata class just to hold your data.
    public class MetaData   
    {   
        public MetaData(string data1,int data2) 
        {   
            Data1 = data1;  
            Data2 = data2;  
        }
    
        public string Data1 { get; set; }   
        public int Data2 { get; set; }  
    }
    

    // Just pass in the instance to the host.

    MetaData metaData = new MetaData("D1", 100);
    ServiceImplementation implementation1 = new ServiceImplementation(metaData);
    ServiceHost serviceHost = new ServiceHost(implementation1);
    

    // My Implementation looks like this

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    internal class ServiceImplementation : IService 
    {   
        private MetaData m_MetaData;    
        public ServiceImplementation(MetaData metaData) 
        {   
            m_MetaData = metaData;  
        }   
    
        public string Ping(string name) 
        {   
            return m_MetaData.Data1;    
        }   
    }
    

    See that you have all your meta data in the member ‘m_MetaData’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF self-hosted service in a Windows Forms application. I am going
I have a WCF service which accepts a string as a paramter for one
I have a WCF service that is returning a block of xml. One element
I have a WCF Windows service with an endpoint specified in the config file
I have WCF service that is IIS-hosted and I have to send binary data
here's the setup for the project. I have a WCF Service that is hosted
I have a simple WCF service hosted in a console app and what I
Environment: Windows XP, Visual Studio 2010, IIS NOT installed. I've developed a WCF service
We have a WCF (Windows Communication Foundation) client and service application. We're using Windows
I have an interesting problem with WCF in a Windows 7 environment... it's slooooooow.

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.