Created
October 3, 2014 11:56
-
-
Save aalinat/f9351f5dd66eae2eb18e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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