class Program
{
static void Main(string[] args)
{
using (ServiceHost sh=new ServiceHost(typeof(MyService)))
{
sh.Open();
Console.WriteLine("serivce is ready...");
Console.ReadLine();
sh.Close();
}
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
string SayHello();
}
public class MyService : IService
{
public string SayHello()
{
return "Hello, I am a Clown";
}
1 回答
WCF服务可以将特定 endpoints 作为发现 endpoints 暴露给所有客户端,以便客户端可以找到服务所在的位置 . 您甚至可以使用UDP多播来启用客户端发现的服务 .
你可以查看官方文件 .
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/wcf-discovery
我做了一个演示,希望它对你有用 .
Server.
}
Server app.config
Client.
}
Client.config