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 987233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:26:49+00:00 2026-05-16T05:26:49+00:00

I have a class that implements a plugin for an existing application. I also

  • 0

I have a class that implements a plugin for an existing application.

I also have exposed that class as a WCF service. That part is working so far. The problem I am running into is that the application I am plugging into creates the instance of my class that I want to use.

Is there a way to pass an existing class instance to the WCF service host, to expose as a service endpoint?

I know (or can figure out) how to make a singleton instance of a WCF service, but that still won’t help me. From what I can tell, the singleton instance will still be created and provided by WCF.

I have thought of other approaches, but I’d rather take this one if it is available to me.

Some code. This is in the constructor of my plugin:

// Setup the service host
var baseAddress = new Uri("http://localhost:8080/MyService/");
this.serviceHost = new ServiceHost(this.GetType(), baseAddress);

// Add our service endpoint
// Todo: Is there somewhere around here that I can provide an instance?
//   Maybe in behavior somewhere?
this.serviceHost.AddServiceEndpoint(
    typeof(ITheInterfaceMyClassDerivesFrom),
    new BasicHttpBinding(),
    ""
    );

// Add metadata exchange (so we see something when we go to that URL)
var serviceMetadataBehavior = this.serviceHost.Description.Behaviors
    .Find<ServiceMetadataBehavior>();
if (serviceMetadataBehavior == null)
    this.serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior());

this.serviceHost.AddServiceEndpoint(
    typeof(IMetadataExchange),
    new CustomBinding(new HttpTransportBindingElement()),
    "MEX"
    );

This is in the plugin’s OnStartedUp method (called by the application I am plugging into):

serviceHost.Open();
  • 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-16T05:26:49+00:00Added an answer on May 16, 2026 at 5:26 am

    You need to use the other constructor for ServiceHost if you want to do this – check out the MSDN docs at http://msdn.microsoft.com/en-us/library/ms585487.aspx

    public ServiceHost(
        Object singletonInstance,
        params Uri[] baseAddresses
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.