|
/*************************************************************************
*
* Copyright 2009 Richard (Rick) Marvin Wycoff, All Rights Reserved
* DO NOT ALTER OR REMOVE THIS COPYRIGHT NOTICE.
*
* NOTICE: You are permitted to use, modify, and distribute this file in
* accordance with the terms of the license agreement accompanying it.
* Any existing copyright or authorship information in any given source
* file must remain intact.
*
**************************************************************************/
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using Wycoff.Shared;
namespace WcfHttpHost
{
/// <summary>
/// ITheService implementation that will be served by this process.
/// </summary>
public class WcfRemoteService : ITheService
{
/// <summary>
/// Default constructor
/// </summary>
public WcfRemoteService() { }
#region ITheClass Members
/// <summary>
/// ITheService implementation method.
/// </summary>
/// <param name="name">
/// Name of person to which the salutation should be addressed
/// </param>
/// <returns>
/// Personalized salutation
/// </returns>
public string Hello(string name)
{
return string.Format("Saying hello to {0} from the WCF server", name);
}
#endregion
}
/// <summary>
/// Main class for the Server Activated Object host application
/// </summary>
class Program
{
/// <summary>
/// Static main for the SOA host application
/// </summary>
/// <param name="args">
/// Not used
/// </param>
static void Main(string[] args)
{
// We did not separate contract from implementation.
// Therefore service and contract are the same in this example.
Type serviceType = typeof(WcfRemoteService);
ServiceHost host = new ServiceHost(serviceType,
new Uri[] { new Uri("http://localhost:8080/") } );
// Add behavior for our MEX endpoint
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(behavior);
// Create basicHttpBinding endpoint at http://localhost:8080/RemoteTheService/
host.AddServiceEndpoint(typeof(ITheService), new BasicHttpBinding(), "RemoteTheService");
// Add MEX endpoint at http://localhost:8080/MEX/
host.AddServiceEndpoint(typeof(IMetadataExchange),
new BasicHttpBinding(), "MEX");
// open the host
host.Open();
// Keep running until we are done
Console.WriteLine("WCF Service is ready, press any key to terminate.");
Console.ReadKey();
// close the host.
host.Close();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Rick's software passion is developing "invisible” software components, the kind that no one ever thinks about because they just do what they are supposed to do. He believes in standards, design patterns, and designing components for extensibility and reuse.