Skip to content

Instantly share code, notes, and snippets.

@aalinat
Created October 3, 2014 11:56
Show Gist options
  • Save aalinat/f9351f5dd66eae2eb18e to your computer and use it in GitHub Desktop.
Save aalinat/f9351f5dd66eae2eb18e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.Text;
using System.Threading.Tasks;
namespace WCFServer
{
[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
string SayHello(string name);
}
public class HelloWorldService : IHelloWorldService
{
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
public string SayHello(string name)
{
return string.Format("Hello, {0}", name);
}
}
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8080/hello");
// Create the ServiceHost.
using (WebServiceHost host = new WebServiceHost(typeof(HelloWorldService), baseAddress))
{
ServiceEndpoint ep2 = host.AddServiceEndpoint(typeof(IHelloWorldService), new WebHttpBinding(), "");
ServiceDebugBehavior stp = host.Description.Behaviors.Find<ServiceDebugBehavior>();
stp.HttpHelpPageEnabled = true;
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();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment