Last active
January 10, 2019 10:45
-
-
Save brandedoutcast/a359e2c655f0bcf17e8546e5a9c5c86d to your computer and use it in GitHub Desktop.
Generic Service Util Client Proxy to consume WCF services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ServiceModel; | |
public class Proxy<T> | |
{ | |
public ChannelFactory<T> Factory { get; set; } | |
public Proxy() | |
{ | |
Factory = new ChannelFactory<T>("endpoint"); | |
} | |
public T CreateChannel() | |
{ | |
return Factory.CreateChannel(); | |
} | |
public void Execute(Action<T> action) | |
{ | |
T proxy = CreateChannel(); | |
action(proxy); | |
((ICommunicationObject)proxy).Close(); | |
} | |
public TResult Execute<TResult>(Func<T, TResult> function) | |
{ | |
T proxy = CreateChannel(); | |
var result = function(proxy); | |
((ICommunicationObject)proxy).Close(); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment