服务端
建立第一个接口ISrevice1:
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetIService1();
}
实现IService1:
public class Service1 : IService1
{
public string GetIService1()
{
return string.Format("You Called: IService1");
}
}
建立第二个接口IService2:
[ServiceContract]
public interface IService2
{
[OperationContract]
string GetIService2();
实现IService2:
public class Service2 : IService2
{
public string GetIService2()
{
return string.Format("You Called: IService2");
}
}
新建一个WinForm项目,作为宿住,并引用WCF服务,并打开两个接口
private ServiceHost host1 = null;
private ServiceHost host2 = null;
private void button1_Click(object sender, EventArgs e)
{
host1 = new ServiceHost(typeof(WcfServiceLibrary1.Service1));
host2 = new ServiceHost(typeof(WcfServiceLibrary1.Service2));
host1.Open();
host2.Open();
label1.Text = "服务已启动";
}
主要是配置App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true" />
</runtime>
<system.serviceModel>
<bindings>
<bas