Project: Wcf.SelfHosting


Self hosting WCF service as on MSDN (http://msdn.microsoft.com/en-us/library/ms731758.aspx) and enable exception details for debugging:
var baseAddress = new Uri("http://localhost:9000/hello");

// Create the ServiceHost
using (var host = new ServiceHost(typeof(HelloWorldService), baseAddress))
{
// Enable metadata publishing
var serviceMetadataBehavior =
	new ServiceMetadataBehavior
		{
			HttpGetEnabled = true,
			MetadataExporter = { PolicyVersion = PolicyVersion.Policy15 }
		};
host.Description.Behaviors.Add(serviceMetadataBehavior);

// Retrieve the ServiceDebugBehavior to include exception
// details raised from the service
var serviceDebugBehavior = (ServiceDebugBehavior)host.Description.Behaviors[typeof(ServiceDebugBehavior)];
serviceDebugBehavior.IncludeExceptionDetailInFaults = true;

// 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.
try
{
	host.Open();
}
catch (AddressAccessDeniedException exception)
{
	ShowHowToFixAndRethrow(exception);
}

Console.WriteLine("The service is ready at {0}", baseAddress);

var client = new HelloWorldClient(new BasicHttpBinding(), new EndpointAddress(baseAddress));
var proxy = client.ChannelFactory.CreateChannel(new EndpointAddress(baseAddress));

Console.WriteLine(proxy.SayHello("Bill"));
client.Close();

Last edited Mar 29, 2012 at 2:47 PM by teoarch, version 1

Comments

No comments yet.