hiii 我是 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 中显示接收到的数据,但我不知道该怎么做。请有人帮助我