using System;
using System.ServiceModel; //添加System.ServiceModel引用
using System.ServiceModel.Channels;
namespace ConsoleApplication1
{
[ServiceContract]
public interface IHelloWCF
{
[OperationContract]
void Say(string input);
}
public sealed class HelloService : IHelloWCF
{
public void Say(string input)
{
Console.WriteLine("Hello {0}", input);
}
}
class Program
{
static void Main(string[] args)
{
Uri address = new Uri("http://127.0.0.1:8733/IHelloWCF");
BasicHttpBinding binding = new BasicHttpBinding();
ServiceHost svc = new ServiceHost(typeof(HelloService));
svc.AddServiceEndpoint(typeof(IHelloWCF), binding, address);
svc.Opened += delegate {
Console.WriteLine("The HelloWCF receiving application is ready");
};
svc.Open();
ChannelFactory<IHelloWCF> factory = new ChannelFactory<IHelloWCF>(binding,new EndpointAddress(address));
IHelloWCF proxy = factory.CreateChannel();
proxy.Say("张三");
proxy.Say("李四");
proxy.Say("王二麻子");
Console.ReadLine();
svc.Close();
}
}
}