本文整理汇总了C#中System.ServiceModel.ChannelFactory类的典型用法代码示例。如果您正苦于以下问题:C# ChannelFactory类的具体用法?C# ChannelFactory怎么用?C# ChannelFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChannelFactory类属于System.ServiceModel命名空间,在下文中一共展示了ChannelFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Submit
public void Submit(Order order)
{
Console.WriteLine("Begin to process the order of the order No.: {0}", order.OrderNo);
FaultException exception = null;
if (order.OrderDate < DateTime.Now) {
exception = new FaultException(new FaultReason("The order has expried"), new FaultCode("sender"));
Console.WriteLine("It's fail to process the order.\n\tOrder No.: {0}\n\tReason:{1}", order.OrderNo, "The order has expried");
} else {
Console.WriteLine("It's successful to process the order.\n\tOrder No.: {0}", order.OrderNo);
}
NetMsmqBinding binding = new NetMsmqBinding();
binding.ExactlyOnce = false;
binding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
binding.Security.Transport.MsmqProtectionLevel = ProtectionLevel.None;
ChannelFactory<IOrderRessponse> channelFactory = new ChannelFactory<IOrderRessponse>(binding);
OrderResponseContext responseContext = OrderResponseContext.Current;
IOrderRessponse channel = channelFactory.CreateChannel(new EndpointAddress(responseContext.ResponseAddress));
using (OperationContextScope contextScope = new OperationContextScope(channel as IContextChannel)) {
channel.SubmitOrderResponse(order.OrderNo, exception);
}
Console.Read();
}
示例2: InvokeThenTerminateSession
public static void InvokeThenTerminateSession()
{
ChannelFactory<ICalculator> calculatorChannelFactory = new ChannelFactory<ICalculator>("httpEndpoint");
Console.WriteLine("Create a calculator proxy: proxy1");
ICalculator proxy1 = calculatorChannelFactory.CreateChannel();
Console.WriteLine("Invocate proxy1.Adds(1)");
proxy1.Adds(1);
Console.WriteLine("Invocate proxy1.Adds(2)");
proxy1.Adds(2);
Console.WriteLine("The result return via proxy1.GetResult() is : {0}", proxy1.GetResult());
Console.WriteLine("Invocate proxy1.Adds(1)");
try
{
proxy1.Adds(1);
}
catch (Exception ex)
{
Console.WriteLine("It is fail to invocate the Add after terminating session because \"{0}\"", ex.Message);
}
Console.WriteLine("Create a calculator proxy: proxy2");
ICalculator proxy2= calculatorChannelFactory.CreateChannel();
Console.WriteLine("Invocate proxy2.Adds(1)");
proxy2.Adds(1);
Console.WriteLine("Invocate proxy2.Adds(2)");
proxy2.Adds(2);
Console.WriteLine("The result return via proxy2.GetResult() is : {0}", proxy2.GetResult());
Console.Read();
}
示例3: RegisterAsServer
public static ITestRunner RegisterAsServer(ITestOutput output, Options options)
{
var host = new ServiceHost(output);
int i;
for (i = 0; i < 50; i += 10) {
try {
host.AddServiceEndpoint(typeof(ITestOutput), BindingFactory(), "http://localhost:" + (StartPort + i) + "/");
break;
} catch (AddressAlreadyInUseException) {
}
}
host.Open();
var start = DateTime.Now;
Exception final = null;
var res = new ChannelFactory<ITestRunner>(BindingFactory(), "http://localhost:" + (StartPort + i + 1) + "/").CreateChannel();
while (DateTime.Now - start < TimeSpan.FromSeconds(5)) {
try {
res.Ping();
return res;
} catch (Exception e) {
final = e;
}
}
throw final;
}
示例4: GetRepositoryInformation
public IEnumerable<RepositoryInformation> GetRepositoryInformation(string queryString)
{
if(_repositoryNames != null)
return _repositoryNames; //for now, there's no way to get an updated list except by making a new client
const string genericUrl = "scheme://path?";
var finalUrl = string.IsNullOrEmpty(queryString)
? queryString
: genericUrl + queryString;
var binding = new NetTcpBinding
{
Security = {Mode = SecurityMode.None}
};
var factory = new ChannelFactory<IChorusHubService>(binding, _chorusHubServerInfo.ServiceUri);
var channel = factory.CreateChannel();
try
{
var jsonStrings = channel.GetRepositoryInformation(finalUrl);
_repositoryNames = ImitationHubJSONService.ParseJsonStringsToChorusHubRepoInfos(jsonStrings);
}
finally
{
var comChannel = (ICommunicationObject)channel;
if (comChannel.State != CommunicationState.Faulted)
{
comChannel.Close();
}
}
return _repositoryNames;
}
示例5: Main
static void Main(string[] args)
{
Console.Title = "CLIENT";
// Указание, где ожидать входящие сообщения.
Uri address = new Uri("http://localhost:4000/IContract");
// Указание, как обмениваться сообщениями.
BasicHttpBinding binding = new BasicHttpBinding();
// Создание Конечной Точки.
EndpointAddress endpoint = new EndpointAddress(address);
// Создание фабрики каналов.
ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint);
// Использование factory для создания канала (прокси).
IContract channel = factory.CreateChannel();
// Использование канала для отправки сообщения получателю и приема ответа.
string response = channel.Say("Hello WCF!");
Console.WriteLine(response);
// Задержка.
Console.ReadKey();
}
示例6: Abort
private static void Abort(IChannel channel, ChannelFactory channelFactory)
{
if (channel != null)
channel.Abort();
if (channelFactory != null)
channelFactory.Abort();
}
示例7: Send
public static void Send(Pager model)
{
if (model.To == null || string.IsNullOrWhiteSpace(model.Message)) return;
using (model.Modifier(x => x.Message))
{
Message message = new Message
{
CreatedTime = DateTime.Now,
From = From,
To = model.To,
ContentAsText = model.Message
};
model.Message = string.Empty;
model.History.Add(message) ;
m_history.Add(message);
using (var factory = new ChannelFactory<IMessageHost>(new BasicHttpBinding(), message.To.Uri))
{
factory.Open();
factory.CreateChannel().Send(new Request<Message>(message));
}
}
}
示例8: Client
public Client(string serverAddress)
{
if (EventManager.Instance.Protocol == EventManager.XML_RPC)
{
address = serverAddress;
Uri eventManagerAddress;
if (EventManager.singleMachineDebug)
//For test on a single machine
eventManagerAddress = new Uri("http://" + serverAddress + "/EventManager");
else
eventManagerAddress = new Uri("http://" + serverAddress + ":8000/xmlrpc/EventManager");
ChannelFactory<IEMServiceWCF_XML_RPC> eventManagerFactory =
new ChannelFactory<IEMServiceWCF_XML_RPC>(
new WebHttpBinding(WebHttpSecurityMode.None),
new EndpointAddress(eventManagerAddress));
eventManagerFactory.Endpoint.EndpointBehaviors.Add(new Microsoft.Samples.XmlRpc.XmlRpcEndpointBehavior());
eManagerWCF_XML_RPC = eventManagerFactory.CreateChannel();
}
else if (EventManager.Instance.Protocol == EventManager.REMOTING)
{
eManagerREMOTING = (EMServiceRemoting)Activator.GetObject(typeof(EMServiceRemoting), "http://" + serverAddress + ":8080/EventManager/RemotingService");
}
}
示例9: MainPageLoaded
void MainPageLoaded(object sender, RoutedEventArgs e)
{
// Simple Version
var basicHttpBinding = new BasicHttpBinding();
var endpointAddress = new EndpointAddress("http://localhost:50738/UserGroupEvent.svc");
var userGroupEventService = new ChannelFactory<IAsyncUserGroupEventService>(basicHttpBinding, endpointAddress).CreateChannel();
AsyncCallback asyncCallBack = delegate(IAsyncResult result)
{
var response = ((IAsyncUserGroupEventService)result.AsyncState).EndGetUserGroupEvent(result);
Dispatcher.BeginInvoke(() => SetUserGroupEventData(response));
};
userGroupEventService.BeginGetUserGroupEvent("123", asyncCallBack, userGroupEventService);
// Deluxe Variante mit eigenem Proxy
var channel = new UserGroupEventServiceProxy("BasicHttpBinding_IAsyncUserGroupEventService").Channel;
channel.BeginGetUserGroupEvent("123", ProcessResult, channel);
// Variante mit Faulthandler
using (var scope = new OperationContextScope((IContextChannel)channel))
{
var messageHeadersElement = OperationContext.Current.OutgoingMessageHeaders;
messageHeadersElement.Add(MessageHeader.CreateHeader("DoesNotHandleFault", "", true));
channel.BeginGetUserGroupEventWithFault("123", ProcessResultWithFault, channel);
}
}
示例10: Main
static void Main(string[] args)
{
try
{
using (var cf = new ChannelFactory<IRestService>(new WebHttpBinding(), RestUri))
{
cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
var channel = cf.CreateChannel();
Console.WriteLine("Calling Multiply: ");
var result = channel.Multiply(6, 23);
Console.WriteLine("6*23 = {0}", result);
Console.WriteLine("");
Console.WriteLine("Calling CreateNewUser (POST): ");
var result1 = channel.CreateNewUser("foobar", "verystrongpasswortnot");
Console.WriteLine("User created? {0}", result1);
Console.WriteLine("");
}
Console.WriteLine("Press <ENTER> to terminate");
Console.ReadLine();
}
catch (CommunicationException e)
{
Console.WriteLine("An exception occurred: {0}", e.Message);
}
}
示例11: Main
static void Main(string[] args)
{
Console.Title = "CLIENT";
// Указание, где ожидать входящие сообщения.
Uri address = new Uri("http://localhost:4000/IContract"); // ADDRESS. (A)
// Указание, как обмениваться сообщениями.
BasicHttpBinding binding = new BasicHttpBinding(); // BINDING. (B)
// Создание Конечной Точки.
EndpointAddress endpoint = new EndpointAddress(address);
// Создание фабрики каналов.
ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint); // CONTRACT. (C)
// Использование factory для создания канала (прокси).
IContract channel = factory.CreateChannel();
// Использование канала для отправки сообщения получателю.
channel.Say("Hello WCF!");// сложный механизм
// Задержка.
Console.ReadKey();
}
示例12: GetCustomersOrders
public IEnumerable<Order> GetCustomersOrders(CrmService.Contracts.Customer customer)
{
var channelFactory = new ChannelFactory<CrmService.Contracts.ICrmService>("CrmEP");
CrmService.Contracts.ICrmService proxy = channelFactory.CreateChannel();
return proxy.GetCustomerOrders(customer.ID, null, null);
}
示例13: ImitatorServiceFactory
public ImitatorServiceFactory()
{
var binding = BindingHelper.CreateBindingFromAddress("net.pipe://127.0.0.1/GKImitator/");
var endpointAddress = new EndpointAddress(new Uri("net.pipe://127.0.0.1/GKImitator/"));
_channelFactory = new ChannelFactory<IImitatorService>(binding, endpointAddress);
_channelFactory.Open();
}
示例14: ServerAncClientExceptionsEndpointBehavior
public void ServerAncClientExceptionsEndpointBehavior()
{
var hook = new ExceptionsEndpointBehaviour();
var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
var serv = new ExceptionService();
using (var host = new ServiceHost(serv, new Uri[] { new Uri(address), }))
{
var b = new NetNamedPipeBinding();
var serverEndpoint = host.AddServiceEndpoint(typeof(IExceptionService), b, address);
serverEndpoint.Behaviors.Add(hook);
host.Open();
var f = new ChannelFactory<IExceptionService>(b);
f.Endpoint.Behaviors.Add(hook);
var c = f.CreateChannel(new EndpointAddress(address));
try
{
c.DoException("message");
}
catch (InvalidOperationException ex)
{
StringAssert.AreEqualIgnoringCase("message", ex.Message);
}
host.Abort();
}
}
示例15: Connect
public void Connect(string endPointAddress)
{
if (this._lucidServer != null)
{
Disconnect();
}
EndpointAddress serverEndpointAddress;
try
{
serverEndpointAddress = new EndpointAddress(endPointAddress);
}
catch
{
// bad url
throw new Exception("Bad server URL: " + endPointAddress);
}
Binding binding = new NetTcpBinding(SecurityMode.None, true);
binding.ReceiveTimeout = TimeSpan.FromSeconds(10);
binding.SendTimeout = TimeSpan.FromSeconds(10);
binding.OpenTimeout = TimeSpan.FromSeconds(10);
var factory = new ChannelFactory<ILucidService>(binding, serverEndpointAddress);
this._lucidServer = factory.CreateChannel();
// let server know we are available
this._lucidServer.RegisterClient();
Inv.Log.Log.WriteMessage("Connected to server " + endPointAddress);
}