WCF .NET 4.0 Support

Sep 14, 2012 at 1:51 PM
Edited Sep 14, 2012 at 1:52 PM

Hi,

Does it work with .NET Framework 4.0? I'm getting the following exception:

Unhandled Exception: System.ArgumentException: ServiceHost only supports class service types.
   at System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType)
   at System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts)
   at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
   at Unity.Wcf.UnityServiceHost..ctor(IUnityContainer container, Type serviceType, Uri[] baseAddresses)

Thanks,

-Mihai

PS: It's a Windows Service hosting situation.

Coordinator
Sep 14, 2012 at 2:05 PM

Yes, it works with .NET 4. Looks like the second argument you are passing to UnityServiceHost is not correct. Are you passing the type of the implementation rather than the type of the interface/contract?

Sep 14, 2012 at 6:58 PM
Edited Sep 14, 2012 at 7:31 PM

>Yes, it works with .NET 4.

Cool!

> Looks like the second argument you are passing to UnityServiceHost is not correct. Are you passing the type of the implementation rather than the type of the interface/contract?

I'm passing the type of the contract interface. That's part of the plan, to let Unity figure out the concrete implementation, right?

Coordinator
Sep 14, 2012 at 7:05 PM

ServiceHost and thus UnityServiceHost require the contract implementation type, not the interface. eg. typeof(Service1) not typeof(IService)

Sep 14, 2012 at 7:36 PM
Edited Sep 18, 2012 at 8:28 PM

Understood. Since I have the container reference at hand, I can certainly use it to obtain the concrete type.

However, where does Unity come into play then? I feel like I'm missing the big picture. For example, for a singleton type of service that needs some dependencies injected, the ServiceHost constructor calls into creating the implementation and thus complains about the need for a parameterless constructor.

What am I missing?

Apr 30, 2013 at 9:41 AM
I have the same issue as mihaicodrean.

I only have a constructor with an interface.
public MyService(IDoSomething doSomething)
I get an 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.

Any ideas?
Coordinator
Apr 30, 2013 at 12:00 PM
The parameterless constructor error comes about if Unity.Wcf is not hooked into the pipeline. I am guessing that you have forgotten to update the svc file to use the unity service factory?

Take a look at http://www.devtrends.co.uk/blog/introducing-unity.wcf-providing-easy-ioc-integration-for-your-wcf-services for more help, particularly the section on WAS / IIS hosted services.