你好,
是的,至少在我这边,非双工通信的模式下,在服务端关闭了情况下,重启服务端,客户端仍然可以正常调用服务端的服务。
我这里写一个例子,你可以参看下。
Server(Console application)
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 DateTime.Now.ToShortTimeString();
}
}
Appconfig(Server).
Client(Console application,invoke the service by adding service reference).
static void Main(string[] args)
{
ServiceReference2.ServiceClient client = new ServiceReference2.ServiceClient();
Console.WriteLine(client.SayHello());
Console.WriteLine(client.State);
Console.WriteLine("请关闭服务端");
Console.ReadLine();
try
{
Console.WriteLine(client.SayHello());
}
catch (Exception)
{
Console.WriteLine("调用失败");
}
Console.WriteLine("请重启服务端");
Console.ReadLine();
Console.WriteLine(client.SayHello());
Console.ReadLine();
}
客户端Appconfig(auto-generated),需要根据实际情况修改终结点为服务器地址,同一台机器上,Localhost就可以了。
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference2.IService"
name="BasicHttpBinding_IService1" />
Abraham