本文整理汇总了C#中ChannelFactory.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# ChannelFactory.Abort方法的具体用法?C# ChannelFactory.Abort怎么用?C# ChannelFactory.Abort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChannelFactory
的用法示例。
在下文中一共展示了ChannelFactory.Abort方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsAliveHttp
public static bool IsAliveHttp(string endpointUrl) {
bool response = false;
ChannelFactory <ISoaService> channelFactory = null;
try {
channelFactory = new ChannelFactory <ISoaService> (new BasicHttpBinding(BasicHttpSecurityMode.None), new EndpointAddress(endpointUrl));
ISoaService soaService = channelFactory.CreateChannel();
if (soaService != null) {
response = soaService.IsAlive();
}
channelFactory.Close();
} catch (Exception exception) {
//TODO:
} finally {
if (channelFactory != null) channelFactory.Abort();
}
return response;
}
示例2: DefaultSettings_Echo_RoundTrips_String_StreamedRequest
[ActiveIssue(4077)]//CoreFX
public static void DefaultSettings_Echo_RoundTrips_String_StreamedRequest()
{
string testString = "Hello";
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.TransferMode = TransferMode.StreamedRequest;
ChannelFactory<IWcfService> factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
IWcfService serviceProxy = factory.CreateChannel();
try
{
Stream stream = StringToStream(testString);
var result = serviceProxy.GetStringFromStream(stream);
Assert.Equal(testString, result);
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{
factory.Abort();
}
}
}
示例3: DefaultSettings_Echo_RoundTrips_String_Streamed
[ActiveIssue(4077)]//CoreFX
public static void DefaultSettings_Echo_RoundTrips_String_Streamed()
{
string testString = "Hello";
StringBuilder errorBuilder = new StringBuilder();
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.TransferMode = TransferMode.Streamed;
ChannelFactory<IWcfService> factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
IWcfService serviceProxy = factory.CreateChannel();
try
{
Stream stream = StringToStream(testString);
var returnStream = serviceProxy.EchoStream(stream);
var result = StreamToString(returnStream);
Assert.Equal(testString, result);
}
catch (System.ServiceModel.CommunicationException e)
{
errorBuilder.AppendLine(string.Format("Unexpected exception thrown: '{0}'", e.ToString()));
PrintInnerExceptionsHresult(e, errorBuilder);
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{
factory.Abort();
}
}
Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: DefaultSettings_Echo_RoundTrips_String_Streamed FAILED with the following errors: {0}", errorBuilder));
}
示例4: BasicHttp_Abort_ChannelFactory_Operations_Active
public static void BasicHttp_Abort_ChannelFactory_Operations_Active()
{
// Test creates 2 channels from a single channel factory and
// aborts the channel factory while both channels are executing
// operations. This verifies the operations are cancelled and
// the channel factory is in the correct state.
BasicHttpBinding binding = null;
TimeSpan delayOperation = TimeSpan.FromSeconds(3);
ChannelFactory<IWcfService> factory = null;
IWcfService serviceProxy1 = null;
IWcfService serviceProxy2 = null;
string expectedEcho1 = "first";
string expectedEcho2 = "second";
try
{
// *** SETUP *** \\
binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.CloseTimeout = ScenarioTestHelpers.TestTimeout;
binding.SendTimeout = ScenarioTestHelpers.TestTimeout;
factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
serviceProxy1 = factory.CreateChannel();
serviceProxy2 = factory.CreateChannel();
// *** EXECUTE *** \\
Task<string> t1 = serviceProxy1.EchoWithTimeoutAsync("first", delayOperation);
Task<string> t2 = serviceProxy2.EchoWithTimeoutAsync("second", delayOperation);
factory.Abort();
// *** VALIDATE *** \\
Assert.True(factory.State == CommunicationState.Closed,
String.Format("Expected factory state 'Closed', actual was '{0}'", factory.State));
Exception exception1 = null;
Exception exception2 = null;
string actualEcho1 = null;
string actualEcho2 = null;
// Verification is slightly more complex for the close with active operations because
// we don't know which might have completed first and whether the channel factory
// was able to close and dispose either channel before it completed. So we just
// ensure the Tasks complete with an exception or a successful return and have
// been closed by the factory.
try
{
actualEcho1 = t1.GetAwaiter().GetResult();
}
catch (Exception e)
{
exception1 = e;
}
try
{
actualEcho2 = t2.GetAwaiter().GetResult();
}
catch (Exception e)
{
exception2 = e;
}
Assert.True(exception1 != null || actualEcho1 != null, "First operation should have thrown Exception or returned an echo");
Assert.True(exception2 != null || actualEcho2 != null, "Second operation should have thrown Exception or returned an echo");
Assert.True(actualEcho1 == null || String.Equals(expectedEcho1, actualEcho1),
String.Format("First operation returned '{0}' but expected '{1}'.", expectedEcho1, actualEcho1));
Assert.True(actualEcho2 == null || String.Equals(expectedEcho2, actualEcho2),
String.Format("Second operation returned '{0}' but expected '{1}'.", expectedEcho2, actualEcho2));
Assert.True(((ICommunicationObject)serviceProxy1).State == CommunicationState.Closed,
String.Format("Expected channel 1 state 'Closed', actual was '{0}'", ((ICommunicationObject)serviceProxy1).State));
Assert.True(((ICommunicationObject)serviceProxy2).State == CommunicationState.Closed,
String.Format("Expected channel 2 state 'Closed', actual was '{0}'", ((ICommunicationObject)serviceProxy2).State));
// *** CLEANUP *** \\
((ICommunicationObject)serviceProxy1).Abort();
((ICommunicationObject)serviceProxy2).Abort();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy1,
(ICommunicationObject)serviceProxy2,
factory);
}
}
示例5: ChannelFactory_Verify_CommunicationStates
public static void ChannelFactory_Verify_CommunicationStates()
{
ChannelFactory<IRequestChannel> factory = null;
IRequestChannel channel = null;
try
{
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress(BaseAddress.HttpBaseAddress);
// Create the channel factory for the request-reply message exchange pattern.
factory = new ChannelFactory<IRequestChannel>(binding, endpointAddress);
Assert.Equal(CommunicationState.Created, factory.State);
// Create the channel.
channel = factory.CreateChannel();
Assert.True(typeof(IRequestChannel).GetTypeInfo().IsAssignableFrom(channel.GetType().GetTypeInfo()),
String.Format("Channel type '{0}' was not assignable to '{1}'", channel.GetType(), typeof(IRequestChannel)));
Assert.Equal(CommunicationState.Opened, factory.State);
// Validate ToString()
string toStringResult = channel.ToString();
string toStringExpected = "System.ServiceModel.Channels.IRequestChannel";
Assert.Equal<string>(toStringExpected, toStringResult);
factory.Close();
Assert.Equal(CommunicationState.Closed, factory.State);
}
finally
{
if (factory != null)
{
// check that there are no effects after calling Abort after Close
factory.Abort();
Assert.Equal(CommunicationState.Closed, factory.State);
// check that there are no effects after calling Close again
factory.Close();
Assert.Equal(CommunicationState.Closed, factory.State);
}
}
}
示例6: ChannelFactory_Async_Open_Close
public static void ChannelFactory_Async_Open_Close()
{
ChannelFactory<IRequestChannel> factory = null;
try
{
BasicHttpBinding binding = new BasicHttpBinding();
// Create the channel factory
factory = new ChannelFactory<IRequestChannel>(binding, new EndpointAddress(FakeAddress.HttpAddress));
Assert.True(CommunicationState.Created == factory.State,
string.Format("factory.State - Expected: {0}, Actual: {1}.", CommunicationState.Created, factory.State));
Task.Factory.FromAsync(factory.BeginOpen(null, null), factory.EndOpen).GetAwaiter().GetResult();
Assert.True(CommunicationState.Opened == factory.State,
string.Format("factory.State - Expected: {0}, Actual: {1}.", CommunicationState.Opened, factory.State));
Task.Factory.FromAsync(factory.BeginClose(null, null), factory.EndClose).GetAwaiter().GetResult();
Assert.True(CommunicationState.Closed == factory.State,
string.Format("factory.State - Expected: {0}, Actual: {1}.", CommunicationState.Closed, factory.State));
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{
factory.Abort();
}
}
}
示例7: CustomChannel_Factory_Abort_Aborts_Channel
public static void CustomChannel_Factory_Abort_Aborts_Channel()
{
MockChannelFactory<IRequestChannel> mockChannelFactory = null;
MockRequestChannel mockRequestChannel = null;
List<string> channelOpenMethodsCalled = new List<string>();
List<string> channelCloseMethodsCalled = new List<string>();
List<string> factoryOpenMethodsCalled = new List<string>();
List<string> factoryCloseMethodsCalled = new List<string>();
string testMessageBody = "CustomChannelTest_Sync";
Message inputMessage = Message.CreateMessage(MessageVersion.Default, action: "Test", body: testMessageBody);
// *** SETUP *** \\
// Intercept the creation of the factory so we can intercept creation of the channel
Func<Type, BindingContext, IChannelFactory> buildFactoryAction = (Type type, BindingContext context) =>
{
// Create the channel factory and intercept all open and close method calls
mockChannelFactory = new MockChannelFactory<IRequestChannel>(context, new TextMessageEncodingBindingElement().CreateMessageEncoderFactory());
MockCommunicationObject.InterceptAllOpenMethods(mockChannelFactory, factoryOpenMethodsCalled);
MockCommunicationObject.InterceptAllCloseMethods(mockChannelFactory, factoryCloseMethodsCalled);
// Override the OnCreateChannel call so we get the mock channel created by the factory
mockChannelFactory.OnCreateChannelOverride = (EndpointAddress endpoint, Uri via) =>
{
// Create the mock channel and intercept all its open and close method calls
mockRequestChannel = (MockRequestChannel)mockChannelFactory.DefaultOnCreateChannel(endpoint, via);
MockCommunicationObject.InterceptAllOpenMethods(mockRequestChannel, channelOpenMethodsCalled);
MockCommunicationObject.InterceptAllCloseMethods(mockRequestChannel, channelCloseMethodsCalled);
return mockRequestChannel;
};
return mockChannelFactory;
};
MockTransportBindingElement mockBindingElement = new MockTransportBindingElement();
mockBindingElement.BuildChannelFactoryOverride = buildFactoryAction;
CustomBinding binding = new CustomBinding(mockBindingElement);
EndpointAddress address = new EndpointAddress("myprotocol://localhost:5000");
var factory = new ChannelFactory<ICustomChannelServiceInterface>(binding, address);
// We rely on the implicit open of the channel to be synchronous.
// This is true for both the full framework and this NET Core version.
ICustomChannelServiceInterface channel = factory.CreateChannel();
// *** EXECUTE *** \\
Message outputMessage = channel.Process(inputMessage);
// The mock's default behavior is just to loopback what we sent.
var result = outputMessage.GetBody<string>();
// Abort the factory and expect both factory and channel to be aborted.
factory.Abort();
// *** VALIDATE *** \\
Assert.True(String.Equals(testMessageBody, result),
String.Format("Expected body to be '{0}' but actual was '{1}'", testMessageBody, result));
string expectedOpens = "OnOpening,OnOpen,OnOpened";
string expectedCloses = "OnClosing,OnAbort,OnClosed";
string actualOpens = String.Join(",", channelOpenMethodsCalled);
Assert.True(String.Equals(expectedOpens, actualOpens, StringComparison.Ordinal),
String.Format("Expected channel open methods to be '{0}' but actual was '{1}'.",
expectedOpens, actualOpens));
string actualCloses = String.Join(",", channelCloseMethodsCalled);
Assert.True(String.Equals(expectedCloses, actualCloses, StringComparison.Ordinal),
String.Format("Expected channel close methods to be '{0}' but actual was '{1}'.",
expectedCloses, actualCloses));
actualOpens = String.Join(",", factoryOpenMethodsCalled);
Assert.True(String.Equals(expectedOpens, actualOpens, StringComparison.Ordinal),
String.Format("Expected factory open methods to be '{0}' but actual was '{1}'.",
expectedOpens, actualOpens));
actualCloses = String.Join(",", factoryCloseMethodsCalled);
Assert.True(String.Equals(expectedCloses, actualCloses, StringComparison.Ordinal),
String.Format("Expected factory close methods to be '{0}' but actual was '{1}'.",
expectedCloses, actualCloses));
Assert.True(factory.State == CommunicationState.Closed,
String.Format("Expected factory's final state to be Closed but was '{0}'", factory.State));
Assert.True(((ICommunicationObject)channel).State == CommunicationState.Closed,
String.Format("Expected channel's final state to be Closed but was '{0}'", ((ICommunicationObject)channel).State));
}