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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:26:54+00:00 2026-05-27T02:26:54+00:00

I have a WCF solution that consists of the following class libraries: Exercise.Services: Contains

  • 0

I have a WCF solution that consists of the following class libraries:

  1. Exercise.Services: Contains the implementation classes for the services.
  2. Exercise.ServiceProxy: Contains the classes that are instantiated in the client.
  3. Exercise.HttpHost: Contains the services (*.svc files).

I’m calling the service from a console application and the “first version” works really well so I took the next step which is to create a custom ServiceHostFactory, ServiceHost, and InstanceProvider so I can use constructor injection in my services as it is explained in this article.

These classes are implemented in yet another class library:
4. Exercise.StructureMapWcfExtension

Now even though I’ve modified my service this:

<%@ ServiceHost Language="C#" Debug="true" Factory="Exercise.StructureMapWcfExtension.StructureMapServiceHostFactory" Service="Exercise.Services.PurchaseOrderService" %>

I always get the following exception:

System.ServiceModel.CommunicationException Security negotiation failed
because the remote party did not send back a reply in a timely manner.
This may be because the underlying transport connection was aborted.

It fails in this line of code:

    public class PurchaseOrderProxy : ClientBase<IPurchaseOrderService>, IPurchaseOrderService
    {
        public PurchaseOrderResponse CreatePurchaseOrder(PurchaseOrderRequest purchaseOrderRequest)
        {
            return base.Channel.CreatePurchaseOrder(purchaseOrderRequest); //Fails here
        }
}

But that is not all, I added a trace to the web.config file and this is the error that appears in the log file:

System.InvalidOperationException The service type provided could not
be loaded as a service because it does not have a default
(parameter-less) constructor. To fix the problem, add a default
constructor to the type, or pass an instance of the type to the host.

So this means that my ServiceHostFactory is never being hit, I even set a breakpoint in both its constructor and its method and they never get hit.

I’ve added a reference of the StructureMapWcfExtension library to all the other ones (even the console client), one by one to no avail.

I also tried to use the option in the host’s web.config file to configure the factory like so:

<serviceHostingEnvironment>
  <serviceActivations>
    <add service="Exercise.Services.PurchaseOrderService" relativeAddress="PurchaseOrderService.svc" factory="Exercise.StructureMapWcfExtension.StructureMapServiceHostFactory"/>
  </serviceActivations>
</serviceHostingEnvironment>

That didn’t work either.

Please I need help in getting this to work so I can incorporate it to our project.

Thank you.

UPDATE: Here’s the service host factory’s code:

namespace Exercise.StructureMapWcfExtension
{
    public class StructureMapServiceHostFactory : ServiceHostFactory
    {
        private readonly Container Container;

        public StructureMapServiceHostFactory()
        {
            Container = new Container();

            new ContainerConfigurer().Configure(Container);
        }

        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            return new StructureMapServiceHost(Container, serviceType, baseAddresses);
        }
    }


    public class ContainerConfigurer
    {
        public void Configure(Container container)
        {
            container.Configure(r => r.For<IPurchaseOrderFacade>().Use<PurchaseOrderFacade>());
        }        
    }


   public class StructureMapServiceHost : ServiceHost
   {
       public StructureMapServiceHost(Container container, Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
       {
           if (container == null) throw new ArgumentNullException("container");

           var contracts = ImplementedContracts.Values;

           foreach (var c in contracts)
           {
               var instanceProvider = new StructureMapInstanceProvider(container, serviceType);

               c.Behaviors.Add(instanceProvider);
           }
       }
   }


   public class StructureMapInstanceProvider : IInstanceProvider, IContractBehavior
   {
       private readonly Container Container;
       private readonly Type ServiceType;

       public StructureMapInstanceProvider(Container container, Type serviceType)
       {
           if (container == null) throw new ArgumentNullException("container");
           if (serviceType == null) throw new ArgumentNullException("serviceType");

           Container = container;
           ServiceType = serviceType;
       }

       public object GetInstance(InstanceContext instanceContext)
       {
           return GetInstance(instanceContext, null);
       }

       public object GetInstance(InstanceContext instanceContext, Message message)
       {
           return Container.GetInstance(ServiceType);
       }
   }
}
  • 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-27T02:26:54+00:00Added an answer on May 27, 2026 at 2:26 am

    Looking at the code for StructureMapInstanceProvider, it looks like it is missing the setting of the dispatchRuntime.InstanceProvider. I copied the Listing 5 from your linked web page. It is part of the IContractBehavior interface.

    public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
    {
    dispatchRuntime.InstanceProvider = this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a solution that contains a WCF service project. In Solution Explorer only
I have a Visual Studio 2010 solution that contains a WCF service project. When
I have Asp.Net solution that contains few WCF Service projects. Every time i run
Following the walkthrough at http://msdn.microsoft.com/en-us/library/ee707351(v=VS.91).aspx I have a working Silverlight solution that employs a
I have a solution (WCF service) that has many Entity Framework modules in it.
I have a solution that contains two projects. One project is an ASP.NET Web
We have a large Silverlight, WCF RIA based solution that builds just fine with
Background info: I have some WCF services that are hosted on an internal server
Started using Visual Studio 2012 RC since yesterday, We have one WCF solution. Whenever
I am creating solution and inside I have three projects: A WCF Service Library

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.