Last active
May 11, 2016 12:14
-
-
Save petermorlion/150afe3104baab83af69eb4c0e508594 to your computer and use it in GitHub Desktop.
Simple WCF Proxy
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
public static class Proxy<T> | |
{ | |
private static readonly ChannelFactory<T> ChannelFactory = new ChannelFactory<T>("*"); | |
public static void Execute(Action<T> serviceAction) | |
{ | |
var proxy = (IClientChannel) ChannelFactory.CreateChannel(); | |
var success = false; | |
try | |
{ | |
serviceAction((T) proxy); | |
proxy.Close(); | |
success = true; | |
} | |
finally | |
{ | |
if (!success) | |
{ | |
proxy.Abort(); | |
} | |
} | |
} | |
public static TResponse Execute<TResponse>(Func<T, TResponse> serviceAction) | |
{ | |
var response = default(TResponse); | |
Execute(new Action<T>(service => response = serviceAction(service))); | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The most simple way of creating a WCF proxy I've seen so far.
Usage:
Remarks