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,但我不知道如何做到這一點。 請有人幫我