本文整理匯總了C#中System.ServiceModel.ChannelFactory.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# ChannelFactory.Close方法的具體用法?C# ChannelFactory.Close怎麽用?C# ChannelFactory.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ServiceModel.ChannelFactory
的用法示例。
在下文中一共展示了ChannelFactory.Close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
internal static void Main(string[] args)
{
Thread.Sleep(2000);
var binding = ReadOnly.GetBinding();
var endpoint = new EndpointAddress(string.Concat(ReadOnly.GetProtocol(), "localhost:8080/people"));
var factory = new ChannelFactory<IPersonService>(binding, endpoint);
var service = factory.CreateChannel();
var message = default(Message);
try {
message = service.GetPeople();
foreach (var person in Parse(message)) {
Console.WriteLine(person);
}
((ICommunicationObject)service).Close();
} catch (Exception ex) {
Trace.WriteLine(ex.Message);
((ICommunicationObject)service).Abort();
} finally {
factory.Close();
}
Console.ReadKey();
}
示例2: Run
public async Task Run(string httpAddress, string sendToken)
{
var channelFactory =
new ChannelFactory<IEchoChannel>("ServiceBusEndpoint", new EndpointAddress(httpAddress));
channelFactory.Endpoint.Behaviors.Add(
new TransportClientEndpointBehavior(TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken)));
using (IEchoChannel channel = channelFactory.CreateChannel())
{
Console.WriteLine("Enter text to echo (or [Enter] to exit):");
string input = Console.ReadLine();
while (input != string.Empty)
{
try
{
Console.WriteLine("Server echoed: {0}", channel.Echo(input));
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
input = Console.ReadLine();
}
channel.Close();
}
channelFactory.Close();
}
示例3: Main
static void Main(string[] args)
{
ChannelFactory<IService> channelFactory = null;
try
{
channelFactory = new ChannelFactory<IService>("Endpoint1");
ThreadPool.QueueUserWorkItem((o) =>
{
for (int i = 1; i <= 1000; i++)
{
Console.WriteLine("{0}: invocate service! thread 1", i);
Console.WriteLine(channelFactory.CreateChannel().DoReturn());
//Thread.Sleep(1000);
}
});
ThreadPool.QueueUserWorkItem((o) =>
{
for (int i = 1; i <= 1000; i++)
{
Console.WriteLine("{0}: invocate service! thread 2", i);
Console.WriteLine(channelFactory.CreateChannel().DoReturn());
//Thread.Sleep(1000);
}
});
}
catch (Exception ex)
{
Console.WriteLine(ex);
channelFactory.Close();
}
Console.ReadKey();
}
示例4: Main
static void Main(string[] args)
{
Uri uri = new Uri("serial://localhost/com1");
Console.WriteLine("Creating factory...");
SerialTransportBinding binding = new SerialTransportBinding("COM1");
ChannelFactory<ISerialTrasportDemo> factory =
new ChannelFactory<ISerialTrasportDemo>(binding);
ISerialTrasportDemo channel =
factory.CreateChannel(new EndpointAddress(uri));
Console.Write("Enter Text or x to quit: ");
string message;
while ((message = Console.ReadLine()) != "x")
{
string result = channel.Reflect(message);
Console.WriteLine(
"\nReceived for ProcessReflectRequest: " + result + "\n");
Console.Write("Enter Text or x to quit: ");
}
factory.Close();
}
示例5: Main
static void Main(string[] args)
{
try
{
ChannelFactory<IMyMath> factory = new ChannelFactory<IMyMath>(
new WSHttpBinding(),
new EndpointAddress("http://localhost/MyMath/Ep1")
);
IMyMath channel = factory.CreateChannel();
int a;
string c;
int b;
a = Convert.ToInt32(Console.ReadLine());
c = Console.ReadLine();
b = Convert.ToInt32(Console.ReadLine());
Console.ReadLine();
int result = channel.Add(a, c, b);
if(result == -2)
{
Console.WriteLine("На нуль ділити не можна ****!!!");
}
Console.WriteLine("result: {0}", result);
Console.WriteLine("Для завершения нажмите <ENTER>\n");
Console.ReadLine();
factory.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
示例6: Main
static void Main(string[] args)
{
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(CalculatorService), new Uri(baseAddress));
Dictionary<string, string> namespaceToPrefixMapping = new Dictionary<string, string>
{
{ "http://www.w3.org/2003/05/soap-envelope", "SOAP12-ENV" },
{ "http://www.w3.org/2005/08/addressing", "SOAP12-ADDR" },
};
Binding binding = ReplacePrefixMessageEncodingBindingElement.ReplaceEncodingBindingElement(
new WSHttpBinding(SecurityMode.None),
namespaceToPrefixMapping);
host.AddServiceEndpoint(typeof(ICalculator), binding, "");
host.Open();
Binding clientBinding = LoggingMessageEncodingBindingElement.ReplaceEncodingBindingElement(
new WSHttpBinding(SecurityMode.None));
ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(clientBinding, new EndpointAddress(baseAddress));
ICalculator proxy = factory.CreateChannel();
Console.WriteLine(proxy.Add(234, 456));
((IClientChannel)proxy).Close();
factory.Close();
host.Close();
}
示例7: Start
internal void Start()
{
//Create a proxy to the event service
EndpointAddress remoteAddress = new EndpointAddress(Config.Communincation.ServiceURI);
NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
IChannelFactory<IEventService> channelFactory = new ChannelFactory<IEventService>(netNamedPipeBinding, remoteAddress);
IEventService eventService = channelFactory.CreateChannel(remoteAddress);
//Signal ready and wait for other threads to join.
_syncStartBarrier.SignalAndWait();
EventSource eventSource = new EventSource() { ID = Guid.NewGuid(), Name = string.Format("Publisher:{0}", _Id) };
Console.WriteLine("{0} Running...", eventSource);
Event @event = new Event() { Source = eventSource, Info = String.Format("EVENT PUBLISHED AT[{0}]", DateTime.Now.ToLongTimeString()), RecordedAt = DateTime.Now };
Byte[] bytes = ProtoBufSerializer.Serialize<Event>(@event);
//Start publishing events
for (Int64 i = 0; i < _iterations; i++)
{
eventService.Handle(bytes);
}
channelFactory.Close();
}
示例8: test_DoctorService_As_Service
public void test_DoctorService_As_Service()
{
var channelFactory = new ChannelFactory<IDoctorService>("");
var proxy = channelFactory.CreateChannel();
(proxy as ICommunicationObject).Open();
channelFactory.Close();
}
示例9: Main
static void Main(string[] args)
{
Console.Write("Enter the name of the user you want to connect with: ");
string serviceUserName = Console.ReadLine();
Uri serviceUri = new Uri(String.Format("sb://{0}/services/{1}/EchoService/", ServiceBusEnvironment.DefaultRelayHostName, serviceUserName));
EndpointAddress address = new EndpointAddress(serviceUri);
ChannelFactory<IEchoChannel> channelFactory = new ChannelFactory<IEchoChannel>("RelayEndpoint", address);
IEchoChannel channel = channelFactory.CreateChannel();
channel.Open();
Console.WriteLine("Enter text to echo (or [Enter] to exit):");
string input = Console.ReadLine();
while (!String.IsNullOrEmpty(input))
{
try
{
Console.WriteLine("Server echoed: {0}", channel.Echo(input));
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
input = Console.ReadLine();
}
channel.Close();
channelFactory.Close();
}
示例10: Run
static void Run()
{
MsmqIntegrationBinding binding = new MsmqIntegrationBinding();
binding.Security.Mode = MsmqIntegrationSecurityMode.None;
EndpointAddress address = new EndpointAddress("msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);
ChannelFactory<ClassLib.IOrderProcessor> channelFactory = new ChannelFactory<ClassLib.IOrderProcessor>(binding, address);
try
{
ClassLib.IOrderProcessor channel = channelFactory.CreateChannel();
MyOrder order = new MyOrder();
order.ID = DateTime.Now.Ticks.ToString();
order.Name = "Order_" + order.ID;
MsmqMessage<MyOrder> ordermsg = new MsmqMessage<MyOrder>(order);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
channel.SubmitPurchaseOrderInMessage(ordermsg);
scope.Complete();
}
Console.WriteLine("Order has been submitted:{0}", ordermsg);
}
finally
{
channelFactory.Close();
}
}
示例11: Execute
public CommandResult Execute(Command command)
{
try
{
using (ChannelFactory<IIncinerateService> clientFactory = new ChannelFactory<IIncinerateService>())
{
NamedPipeTransportBindingElement transport = new NamedPipeTransportBindingElement();
CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), transport);
clientFactory.Endpoint.Binding = binding;
clientFactory.Endpoint.Address = new EndpointAddress("net.pipe://IncinerateService/incinerate");
IIncinerateService incinerateProxy = clientFactory.CreateChannel();
CommandResult result = command.Execute(incinerateProxy);
clientFactory.Close();
return result;
}
}
catch (FormatException ex)
{
Console.WriteLine("Illegal agruments");
}
catch (CommunicationObjectFaultedException ex)
{
throw new ServiceException("Service is not working", ex);
}
catch (EndpointNotFoundException ex)
{
throw new ServiceException("Service is not running", ex);
}
catch (CommunicationException ex)
{
throw new ServiceException("Can not connect to service", ex);
}
return null;
}
示例12: GetUsers
public List<User> GetUsers(bool onlineOnly)
{
if (onlineOnly)
{
var cf = new ChannelFactory<IContactsStatusService>("contactsservice");
var channel = cf.CreateChannel();
var users = channel.GetOnlineContacts();
if (cf.State == CommunicationState.Opened)
{
cf.Close();
}
return users;
}
else
{
var cf = new ChannelFactory<IDataService>("dataservice");
var channel = cf.CreateChannel();
var users = channel.GetUsers(appKey);
if (cf.State == CommunicationState.Opened)
{
cf.Close();
}
return users;
}
}
示例13: Main
static void Main(string[] args)
{
ChannelFactory<ISampleContract> channelFactory = new ChannelFactory<ISampleContract>("sampleProxy");
ISampleContract proxy = channelFactory.CreateChannel();
int[] windSpeeds = new int[] { 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 };
Console.WriteLine("Reporting the next 10 wind speeds.");
for (int i = 0; i < 10; i++)
{
Console.WriteLine(windSpeeds[i] + " kph");
try
{
proxy.ReportWindSpeed(windSpeeds[i]);
}
catch (CommunicationException)
{
Console.WriteLine("Server dropped a message.");
}
}
Console.WriteLine("Press ENTER to shut down client");
Console.ReadLine();
((IChannel)proxy).Close();
channelFactory.Close();
}
示例14: Run
public static void Run(int numberOfMessage)
{
try
{
int Iteration = numberOfMessage;
string address = "net.msmq://localhost/private/ReceiveTx";
NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None)
{
ExactlyOnce = true,
Durable = true
};
ChannelFactory<IPurchaseOrderService> channelFactory = new ChannelFactory<IPurchaseOrderService>(binding, address);
IPurchaseOrderService channel = channelFactory.CreateChannel();
for (int i = 0; i < Iteration; i++)
{
PurchaseOrder po = new PurchaseOrder()
{
PONumber = Guid.NewGuid().ToString(),
CustomerId = string.Format("CustomerId: {0}", i)
};
Console.WriteLine("Submitting an PO ...");
channel.SubmitPurchaseOrder(po);
}
channelFactory.Close();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
示例15: test_account_manager_as_service
public void test_account_manager_as_service()
{
ChannelFactory<IAccountService> channelFactory = new ChannelFactory<IAccountService>("");
IAccountService proxy = channelFactory.CreateChannel();
(proxy as ICommunicationObject).Open();
channelFactory.Close();
}
開發者ID:cohs88,項目名稱:ps-building-end-to-end-multi-client-service-oriented-applicatins,代碼行數:7,代碼來源:ServiceAccessTests.cs