在两进程间设置一个为服务端,一个为客户端
服务端:
使用代码
string baseAddress = @"http://localhost:8000/ServiceModelSamples11/service";
WSHttpBinding binding1 = new WSHttpBinding();
binding1.CloseTimeout = new TimeSpan(0, 2, 0);
serviceHost = new ServiceHost(typeof(CalculatorService));
serviceHost.AddServiceEndpoint(typeof(ICalculator), binding1, baseAddress);
serviceHost.Open();
客户端:
使用代码
System.ServiceModel.Channels.Binding httpBinding = new BasicHttpBinding();
ChannelFactory<IGeneralCalculator> factory = new ChannelFactory<IGeneralCalculator>(httpBinding);
IGeneralCalculator proxy = factory.CreateChannel(new EndpointAddress("http://localhost/wcfservice/GeneralCalculatorService.svc"));
double iRst = proxy.Add(100,100);