本文整理匯總了C#中System.ServiceModel.ChannelFactory.Abort方法的典型用法代碼示例。如果您正苦於以下問題:C# ChannelFactory.Abort方法的具體用法?C# ChannelFactory.Abort怎麽用?C# ChannelFactory.Abort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ServiceModel.ChannelFactory
的用法示例。
在下文中一共展示了ChannelFactory.Abort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Abort
private static void Abort(IChannel channel, ChannelFactory channelFactory)
{
if (channel != null)
channel.Abort();
if (channelFactory != null)
channelFactory.Abort();
}
示例2: Abort
static void Abort(IChannel channel, ChannelFactory cf)
{
if (channel != null)
channel.Abort();
if (cf != null)
cf.Abort();
}
示例3: VerifyServiceIdentityMatchDnsEndpointIdentity
// The product code will check the Dns identity from the server and throw if it does not match what is specified in DnsEndpointIdentity
public static void VerifyServiceIdentityMatchDnsEndpointIdentity()
{
string testString = "Hello";
NetTcpBinding binding = new NetTcpBinding();
//SecurityMode.Transport is not supported yet, we will get an exception here, tracked by issue #81
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
EndpointAddress endpointAddress = new EndpointAddress(new Uri(Endpoints.Tcp_VerifyDNS_Address),new DnsEndpointIdentity("localhost"));
ChannelFactory<IWcfService> factory = new ChannelFactory<IWcfService>(binding, endpointAddress);
// factory.Credentials.ServiceCertificate is not availabe currently, tracked by issue 243
// We need to change the validation mode as we use a test certificate. It does not affect the purpose of this test
// factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
IWcfService serviceProxy = factory.CreateChannel();
try
{
var result = serviceProxy.Echo(testString);
Assert.Equal(testString, result);
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{factory.Abort();
}
}
}
示例4: bPipe_Click
private void bPipe_Click(object sender, EventArgs e)
{
//ChannelFactory<IDesktopService> httpFactory = new ChannelFactory<IDesktopService>(new WebHttpBinding(),
// new EndpointAddress("http://localhost:8000/Desk"));
//IDesktopService httpProxy =
// httpFactory.CreateChannel();
ChannelFactory<IDesktopService> pipeFactory = null;
try
{
var b = new NetNamedPipeBinding();
b.MaxReceivedMessageSize = int.MaxValue;
b.MaxBufferSize = int.MaxValue;
pipeFactory =
new ChannelFactory<IDesktopService>(b,
new EndpointAddress("net.pipe://localhost/DeskPipe"));
IDesktopService pipeProxy =
pipeFactory.CreateChannel();
sw.Start();
var d = pipeProxy.C("par");
sw.Stop();
box.Text += "GetData returned {0} bytes and costed {1} ms\r\n".Fmt(d.Result.ToString().Length, sw.ElapsedMilliseconds);
var s = d.Result.ToString();
if (!string.IsNullOrEmpty(s))
{
var bytes = Convert.FromBase64String(s);
using (var ms = new MemoryStream())
{
ms.Write(bytes, 0, bytes.Length);
var bmp = Image.FromStream(ms);
pic.Image = bmp;
}
}
//var img = d.Result as Bitmap;
//pic.Image = img;
}
catch (Exception ex)
{
Error.Handle(ex);
}
finally
{
sw.Reset();
if (pipeFactory != null && pipeFactory.State != CommunicationState.Closed)
{
if (pipeFactory.State == CommunicationState.Faulted)
{
pipeFactory.Abort();
}
else
{
pipeFactory.Close();
}
}
}
}
示例5: CallSyncService
private string CallSyncService()
{
string lResult = string.Empty;
if (mut.WaitOne(0))
{
try
{
var lServiceHostAddress = new Uri(Properties.Settings.Default.ServiceHostAddress);
var lServiceEndPointAddress = Properties.Settings.Default.ServiceEndPointAddress;
var lEndPointAddress =
new EndpointAddress(new Uri(String.Format("{0}/{1}", lServiceHostAddress, lServiceEndPointAddress)));
this.WriteLog(USLogLevel.Trace, "SyncServiceProperties.CallSyncService: lEndPointAddress = {0}", lEndPointAddress);
var lBinding = new TcpChunkingBinding();
lBinding.OpenTimeout = Properties.Settings.Default.OpenTimeout;
lBinding.ReceiveTimeout = Properties.Settings.Default.ReceiveTimeout;
lBinding.SendTimeout = Properties.Settings.Default.SendTimeout;
lBinding.CloseTimeout = Properties.Settings.Default.CloseTimeout;
this.WriteLog(USLogLevel.Trace, "lBinding params lBinding.OpenTimeout = {0}; lBinding.ReceiveTimeout = {1}; lBinding.SendTimeout = {2}; lBinding.CloseTimeout = {3}", lBinding.OpenTimeout, lBinding.ReceiveTimeout, lBinding.SendTimeout, lBinding.CloseTimeout);
using (var factory = new ChannelFactory<IUSInService>(lBinding, lEndPointAddress))
{
try
{
this.WriteLog(USLogLevel.Trace, "SyncServiceProperties.CallSyncService: ChannelFactory created");
var service = factory.CreateChannel();
this.WriteLog(USLogLevel.Trace, "SyncServiceProperties.CallSyncService: IUSExService service = factory.CreateChannel created");
lResult = service.EntitySync(LinkSyncServiceEntitiesId);
this.WriteLog(USLogLevel.Trace, "SyncServiceProperties.CallSyncService: service.EntitySync выполнен");
factory.Close();
}
finally
{
factory.Abort();
}
}
this.WriteLog(USLogLevel.Trace, "SyncServiceProperties.CallSyncService: ChannelFactory Closed");
}
catch (Exception e)
{
this.WriteLog(USLogLevel.Trace|USLogLevel.Debug, string.Format("SyncServiceProperties.CallSyncService: Ошибка синхронизации LinkSyncServiceEntitiesId = {0}. Ошибка: {1}", LinkSyncServiceEntitiesId, e));
this.WriteLogException(string.Format("SyncServiceProperties.CallSyncService: Ошибка синхронизации LinkSyncServiceEntitiesId = {0}. Ошибка: {1}", LinkSyncServiceEntitiesId, e), e);
lResult = string.Empty;
}
finally
{
mut.ReleaseMutex();
}
}
return lResult;
}
示例6: CreateDashboardPipe
private void CreateDashboardPipe()
{
try{
//Connect to the master channel
m_DasboardComFactory = new ChannelFactory<ICTMComR2D>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/Dashboard/CTMComR2D"));
m_DashboardPipe = m_DasboardComFactory.CreateChannel();
}
catch
{
m_DasboardComFactory.Abort();
}
}
示例7: Authenticate
public AuthenticationResponse Authenticate(AuthenticationRequest request)
{
ChannelFactory<IAuthenticationService> channelFactory = null;
AuthenticationResponse response = null;
try
{
channelFactory = new ChannelFactory<IAuthenticationService>("authentication");
channelFactory.Open();
var service = channelFactory.CreateChannel();
response = service.Authenticate(request);
channelFactory.Close();
}
catch (CommunicationException)
{
if (channelFactory != null)
{
channelFactory.Abort();
}
}
catch (TimeoutException)
{
if (channelFactory != null)
{
channelFactory.Abort();
}
}
catch (Exception)
{
if (channelFactory != null)
{
channelFactory.Abort();
}
throw;
}
return response;
}
示例8: bError_Click
private void bError_Click(object sender, EventArgs e)
{
using (ChannelFactory<ITestService> cf = new ChannelFactory<ITestService>(new NetTcpBinding(), TestService.NetTcpAddress))
{
try
{
ITestService ts = cf.CreateChannel();
ts.TestError();
}
catch(FaultException ex)
{
MessageBox.Show(ex.ToString());
cf.Abort();
}
}
}
示例9: Dispose
public void Dispose()
{
try
{
_remoteFactory.Close();
_remoteFactory = null;
}
catch
{
if (_remoteFactory != null)
{
_remoteFactory.Abort();
_remoteFactory = null;
}
}
}
示例10: GETTest
public void GETTest()
{
GeoLocation output = null;
var factory = new ChannelFactory<IService<GeoLocation>>("GeoLocationService");
if (factory.State != CommunicationState.Faulted)
{
var proxy = factory.CreateChannel();
output = proxy.Read("werwtw4hej3u");
Console.WriteLine(output.Identifier);
if (factory.State == CommunicationState.Faulted)
{
factory.Abort();
}
((IDisposable)proxy).Dispose();
}
Assert.IsNotNull(output);
}
示例11: Address
/// <summary>
/// 此靜態構造函數用來檢測存活的Search個數
/// </summary>
static Address()
{
Timer timer = new Timer();
timer.Interval = 6000;
timer.Elapsed += (sender, e) =>
{
Console.WriteLine("\n***************************************************************************");
Console.WriteLine("當前存活的Search為:");
lock (obj)
{
//遍曆當前存活的Search
foreach (var single in search)
{
ChannelFactory<IProduct> factory = null;
try
{
//當Search存在的話,心跳服務就要定時檢測Search是否死掉,也就是定時的連接Search來檢測。
factory = new ChannelFactory<IProduct>(new NetTcpBinding(SecurityMode.None), new EndpointAddress(single));
factory.CreateChannel().TestSearch();
factory.Close();
Console.WriteLine(single);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//如果拋出異常,則說明此search已經掛掉
search.Remove(single);
factory.Abort();
Console.WriteLine("\n當前時間:" + DateTime.Now + " ,存活的Search有:" + search.Count() + "個");
}
}
}
//最後統計下存活的search有多少個
Console.WriteLine("\n當前時間:" + DateTime.Now + " ,存活的Search有:" + search.Count() + "個");
};
timer.Start();
}
示例12: bTest_Click
private void bTest_Click(object sender, EventArgs e)
{
var binding = new NetTcpBinding(SecurityMode.Transport);
using (ChannelFactory<ITestService> cf = new ChannelFactory<ITestService>(binding, TestService.NetTcpAddress))
{
ITestService ts = cf.CreateChannel();
for (int i = 0; i < 10; i++)
{
try
{
var rlt = ts.Test();
Log(rlt);
}
catch (Exception ex)
{
Log(ex.Message);
cf.Abort();
}
}
}
}
示例13: Main
static void Main(string[] args)
{
using (ChannelFactory<ITestService> cf = new ChannelFactory<ITestService>(new NetTcpBinding(), TestService.NetTcpAddress))
{
ITestService ts = cf.CreateChannel();
for (int i = 0; i < 10; i++)
{
try
{
var rlt = ts.Test();
Log(rlt);
}
catch (Exception ex)
{
Log(ex.Message);
cf.Abort();
}
}
}
//using (ChannelFactory<ITestService> cf = new ChannelFactory<ITestService>(new NetTcpBinding(), TestService.Address))
//{
// ITestService ts = cf.CreateChannel();
// for (int i = 0; i < 10; i++)
// {
// try
// {
// var rlt = ts.Test();
// Log(rlt);
// }
// catch (Exception ex)
// {
// Log(ex.Message);
// cf.Abort();
// }
// }
//}
Console.ReadKey();
}
示例14: POSTTest
public void POSTTest()
{
var input = new GeoLocation
{
Accuracy = 1.26743233E+14,
Altitude = 1.26743233E+14,
AltitudeAccuracy = 1.26743233E+14,
Heading = 1.26743233E+14,
Latitude = 1.26743233E+14,
Longitude = 1.26743233E+14,
Speed = 1.26743233E+14,
Timestamp = DateTime.Parse("1999-05-31T11:20:00")
};
GeoLocation output = null;
var factory = new ChannelFactory<IService<GeoLocation>>("GeoLocationService");
if (factory.State != CommunicationState.Faulted)
{
var proxy = factory.CreateChannel();
try
{
output = proxy.Create(input);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.InnerException.StackTrace);
}
Console.WriteLine(output.Identifier);
if (factory.State == CommunicationState.Faulted)
{
factory.Abort();
}
((IDisposable)proxy).Dispose();
}
Assert.IsNotNull(output);
}
示例15: worker
internal static void worker(int loop, string name)
{
//ThreadPool.QueueUserWorkItem(delegate
//{
ChannelFactory<ITest> factory = null;
try
{
factory = new ChannelFactory<ITest>(name);
var channel = factory.CreateChannel();
using (var ts = new TransactionScope(TransactionScopeOption.Required))
{
var response = string.Empty;
response = channel.Ping2(loop);
//channel.Ping(loop);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(string.Format("[{0}, {1}]: {2}, tid={3}\n", loop, name, response, Thread.CurrentThread.GetHashCode()));
Console.ResetColor();
//Thread.Sleep(1000);
Console.WriteLine("\n+++ Press 'a' to abort or any key to finish a transaction. Timeout = 60sec. +++\n");
var ki = Console.ReadKey();
if (ki.Key == ConsoleKey.A)
{
throw new Exception("M A N U A L Y A B O R T E D");
}
ts.Complete();
}
((IChannel)channel).Close();
factory.Close();
}
catch (Exception ex)
{
if (factory != null) factory.Abort();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\n" + ex.Message);
Console.ResetColor();
}
//});
}