0
hiii 我是WCF的新手,我在控制台应用程序中编写了代码。 我创建这样的Windows窗体应用程序中的WCF主机
[ServiceContract]
public interface IHelloService
{
[OperationContract]
void SayHello(string msg);
}
服务和定义函数
public class HelloService: IHelloService
{
public void SayHello(string msg)
{
Console.WriteLine("I rec message : " + msg);
}
}
,我开始从主程序文件服务
static void Main(string[] args)
{
Console.WriteLine("******* Service Console *******");
using(ServiceHost host = new ServiceHost(typeof(HelloWcfServiceLibrary.HelloService)))
{
host.AddServiceEndpoint(typeof(IHelloService), new NetTcpBinding(), "net.tcp://localhost:9000/HelloWcfService");
host.Open();
Console.Read();
}
}
,并在客户端的代码是
static void Main(string[] args)
{
IHelloService proxy = ChannelFactory<IHelloService>.CreateChannel(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:9000/HelloWcfService"));
string msg;
while (true)
{
msg = Console.ReadLine();
msg = proxy.SayHello(msg);
Console.WriteLine("Server returned " + msg);
}
}
它工作正常,但我想在Windows窗体应用程序中做同样的事情,并显示接收到的数据我richtextbox,但我不知道如何做到这一点。 请有人帮我