17,740
社区成员
发帖
与我相关
我的任务
分享
namespace Service
{
[ServiceContract]
public interface IService
{
[OperationContract]
void DoSomething();
}
public class MyServcie:IService
{
#region IService Members
public void DoSomething()
{
Console.WriteLine("hello world");
}
#endregion
}
}
namespace Host
{
public partial class MyHost : Form
{
ServiceHost host = null;
NetTcpBinding binding = null;
public MyHost()
{
InitializeComponent();
host = new ServiceHost(typeof(Service.MyServcie));
binding = new NetTcpBinding();
host.AddServiceEndpoint(typeof(Service.IService), binding, "net.tcp://127.0.0.1/myService");
}
private void startButton_Click(object sender, EventArgs e)
{
host.Open();
}
private void stopButton_Click(object sender, EventArgs e)
{
host.Close();
host = null;
}
}
}
客户端的代码就不粘了.
楼主看看是不是可以解决问题