先看下面的代码:
代码
代码
BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress(endAddress);
ChannelFactory<IMyService> myChannelFactory = new ChannelFactory<IMyService>(myBinding,myEndpoint);
IMyService wcfClient = myChannelFactory.CreateChannel();
try
{
IDisposable chanel = wcfClient as IDisposable;
ICommunicationObject o = chanel as ICommunicationObject;
o.Opened += delegate { Console.WriteLine("OK") };
o.Close();
}
catch (Exception _ex)
{
}
BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress(endAddress);
ChannelFactory<IMyService> myChannelFactory = new ChannelFactory<IMyService>(myBinding,myEndpoint);
IMyService wcfClient = myChannelFactory.CreateChannel();
try
{
IDisposable chanel = wcfClient as IDisposable;
ICommunicationObject o = chanel as ICommunicationObject;
o.Opened += delegate { Console.WriteLine("OK") };
o.Close();
}
catch (Exception _ex)
{
}
此代码在添加服务引用,传入服务链接地址、绑定方式,即可实现对一个WCF服务的连接测试。
现在我的问题来了,如果我有多个WCF服务呢,要引用每个服务吗?
那么我如何能对多个WCF服务的连接测试采用统一的方法?希望各位多多指教----
曾参考如下链接:
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/d62117d7-1f52-4102-aaf1-fd831387e61b/
希望能抛砖引玉。