日期:2014-05-17 浏览次数:20867 次
/// <summary>
/// 链接服务器 发送消息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
string address = "net.tcp://localhost:6666/hello";
ChannelFactory<WindowsServer.Client.IHello> myChannelFactory = new ChannelFactory<WindowsServer.Client.IHello>(new NetTcpBinding(SecurityMode.None), new EndpointAddress(address));
WindowsServer.Client.IHello wcfClient = myChannelFactory.CreateChannel();
using (wcfClient as IDisposable)
{
wcfClient.Say(messText.Text);
}
}
public ServiceHost StartTCPServer()
{
try
{
Uri baseAddress = new Uri("http://localhost:8889");
string address = "net.tcp://localhost:6666/hello";
ServiceHost serviceHost = new ServiceHost(typeof(HelloService), baseAddress);
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
serviceHost.AddServiceEndpoint(typeof(WindowsServer.Services.IHello), binding, address);
serviceHost.Open();
return serviceHost;
}
catch (Exception ex)
{
}
&nb