标签:
添加System.ServiceModel 引用
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(GreetService), new Uri("http://localhost:20000"));
host.AddServiceEndpoint(typeof (IGreetService), new BasicHttpBinding(), "GreetService");
host.Description.Behaviors.Add(new ServiceMetadataBehavior(){HttpGetEnabled = true});
host.Open();
Console.WriteLine("服务已开启");
Console.Read();
}
}
[ServiceContract]
public interface IGreetService
{
[OperationContract]
string Greet(string name);
}
public class GreetService : IGreetService
{
public string Greet(string name)
{
Console.WriteLine(("Hello:"+name));
return "Welcome:" + name;
}
}
标签:
原文地址:http://www.cnblogs.com/zhshlimi/p/5594240.html