How do I start the WCF Service Host in Visual Studio 2010 SP1 in the .NET 3.5 Runtime?
When I create a WCF Service Library to target the .NET 3.5 framework in Visual Studio 2010 SP1, the WCF Service Host loads the .NET 3.5 assembly in the .NET framework 4.0.30319.237 runtime when debugging.
Since I'm referencing the SharePoint 2010 Server Object Model, I cannot have my code loaded into the .NET 4 runtime, SharePoint assemblies chec开发者_JAVA技巧k the runtime version and throw an exception in this case.
The WCF Service Host must be started in the .NET runtime version 2.0.50727.5446 (which is the same runtime for .NET 3.5). Has anyone resolved this?
You can change some of the configuration of the WcfSvcHost to be able to run your assemlies, without the exception:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
You need to add this to the config file located at: C:\Program Files (x86)\Microsoft Visual Studio \10.0\Common7\IDE\WcfSvcHost.exe.config.
For a full detail of this solution, browse to: http://blogs.claritycon.com/bryandougherty/2011/05/24/handling-mixed-mode-assembly-error-in-wcf-service-host/
Please, let me know if this works for you.
Faced with the same problem here, the answer for us was to write a separate ConsoleHost application with the .NET 3.5 framework targeted:
using System;
using System.ServiceModel;
namespace Project.Services.ConsoleHost
{
class Program
{
static void Main(string[] args)
{
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(ProjectServiceManager)))
{
// Open the ServiceHost to start listening for messages. Since
// no endpoints are explicitly configured, the runtime will create
// one endpoint per base address for each service contract implemented
// by the service.
host.Open();
Console.WriteLine("The Project WCF Services are hosted at:");
Console.WriteLine();
foreach (var address in host.BaseAddresses)
Console.WriteLine(string.Format("\t{0}", address.ToString()));
Console.WriteLine();
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
}
}
}
精彩评论