这是我用来调用方法:修改现有的WCF通信对象
SvcHelper.Using<SomeWebServiceClient>(proxy =>
{
proxy.SomeMethod();
}
public class SvcHelper
{
public static void Using<TClient>(Action<TClient> action) where TClient : ICommunicationObject, IDisposable, new()
{
}
}
这是我如何调用方法:
ChannelFactory<ISomethingWebService> cnFactory = new ChannelFactory<ISomethingWebService>("SomethingWebService");
ISomethingWebService client = cnFactory.CreateChannel();
using (new OperationContextScope((IContextChannel)client))
{
client.SomeMethod();
}
我的问题是:如果不更换的每个实例我原来的方法调用方法;是否有修改我SvcHelper
,做在SvcHelper
构造通道的创建方式,然后简单地通过类似如下的界面:
SvcHelper.Using<ISomethingWebService>(client =>
{
client.SomeMethod();
}
希望这是有道理的,并在此先感谢。
嗯不知道为什么你必须删除该...除非你已经使这些方法非静态?在我粘贴之前,我正在编译该示例代码。为了清晰起见,我更喜欢带前缀的方法调用,所以我总是以此为前缀。或ClassName。在静态调用的情况下。 – 2012-03-30 01:21:40
我是否还需要实现缓存以及此方法? – fuzz 2012-04-01 07:52:51
那么我有channelFactory实例缓存在那里通道类型,但我忘了我们实际上需要缓存Type + endpointConfiguration名称是一个完整的实现。我会更新实施以完成。 – 2012-04-01 16:41:12