Search code examples
c#wcf

WCF equivalent for OWIN/Katana in-memory integration testing


For OWIN/KATANA in-memory hosting solution is available: Microsoft.AspNet.WebApi.OwinSelfHost. I'd like to find similar way for WCF services - integration tests which can be run in-memory.


Solution

  • Is it just selfhosting the services?

    There are pretty good documentation for this.

    // Create the ServiceHost.
    using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
    {
        // Enable metadata publishing.
        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        smb.HttpGetEnabled = true;
        smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
        host.Description.Behaviors.Add(smb);
    
        // 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 service is ready at {0}", baseAddress);
        Console.WriteLine("Press <Enter> to stop the service.");
        Console.ReadLine();
    
        // Close the ServiceHost.
        host.Close();
    }