diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs
index 7b45aba8bd..31360754ff 100644
--- a/TGServiceInterface/Server.cs
+++ b/TGServiceInterface/Server.cs
@@ -62,15 +62,23 @@ namespace TGServiceInterface
/// Returns the requested server component interface. This does not guarantee a successful connection
///
/// The type of the component to retrieve
- ///
+ /// The correct component
public static T GetComponent()
+ {
+ return GetComponentAndChannel(out ChannelFactory ignored);
+ }
+
+ public static T GetComponentAndChannel(out ChannelFactory outChannel)
{
var ToT = typeof(T);
if (!ValidInterfaces.Contains(ToT))
throw new Exception("Invalid type!");
var InterfaceName = typeof(T).Name;
if (HTTPSURL == null)
- return new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))).CreateChannel();
+ {
+ outChannel = new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName)));
+ return outChannel.CreateChannel();
+ }
//okay we're going over
var binding = new WSHttpBinding();
@@ -78,17 +86,17 @@ namespace TGServiceInterface
binding.Security.Mode = requireAuth ? SecurityMode.TransportWithMessageCredential : SecurityMode.Transport; //do not require auth for a connectivity check
binding.Security.Message.ClientCredentialType = requireAuth ? MessageCredentialType.UserName : MessageCredentialType.None;
var address = new EndpointAddress(String.Format("https://{0}:{1}/{2}/{3}", HTTPSURL, HTTPSPort, MasterInterfaceName, InterfaceName));
- var cf = new ChannelFactory(binding, address);
+ outChannel = new ChannelFactory(binding, address);
if (requireAuth)
{
- cf.Credentials.UserName.UserName = HTTPSUsername;
- cf.Credentials.UserName.Password = HTTPSPassword;
+ outChannel.Credentials.UserName.UserName = HTTPSUsername;
+ outChannel.Credentials.UserName.Password = HTTPSPassword;
}
#if DEBUG
//allow self signed certs in debug mode
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true;
#endif
- return cf.CreateChannel();
+ return outChannel.CreateChannel();
}
///
diff --git a/TGServiceInterface/ServiceBridge.cs b/TGServiceInterface/ServiceBridge.cs
index 0a785b24fc..15e5eab7de 100644
--- a/TGServiceInterface/ServiceBridge.cs
+++ b/TGServiceInterface/ServiceBridge.cs
@@ -36,7 +36,17 @@ namespace TGServiceInterface
{
try
{
- Server.GetComponent().InteropMessage(String.Join(" ", args));
+ ChannelFactory channel = null;
+ try
+ {
+ Server.GetComponentAndChannel(out channel).InteropMessage(String.Join(" ", args));
+ channel.Close();
+ }
+ catch
+ {
+ if(channel != null)
+ channel.Abort();
+ }
}
catch { }
return 0;