本文整理汇总了C#中System.ServiceModel.InstanceContext类的典型用法代码示例。如果您正苦于以下问题:C# InstanceContext类的具体用法?C# InstanceContext怎么用?C# InstanceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstanceContext类属于System.ServiceModel命名空间,在下文中一共展示了InstanceContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request,
IClientChannel channel,
InstanceContext instanceContext)
{
// Extract Cookie (name=value) from messageproperty
var messageProperty = (HttpRequestMessageProperty)
OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name];
string cookie = messageProperty.Headers.Get("Set-Cookie");
if (string.IsNullOrWhiteSpace(cookie))
return null;
string[] nameValue = cookie.Split('=', ',');
string userName = string.Empty;
// Set User Name from cookie
int pos = nameValue.ToList().IndexOf(".ASPXAUTH");
if (pos == -1)
return null;
userName = nameValue[pos + 1];
// Set Thread Principal to User Name
EnterpriseIdentity enterpriseIdentity = new EnterpriseIdentity();
GenericPrincipal threadCurrentPrincipal =
new GenericPrincipal(enterpriseIdentity, new string[] { });
enterpriseIdentity.IsAuthenticated = true;
enterpriseIdentity.Name = userName;
System.Threading.Thread.CurrentPrincipal = threadCurrentPrincipal;
return null;
}
开发者ID:asdlvs,项目名称:MinStat,代码行数:31,代码来源:IdentityMessageInspector.cs
示例2: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
var reply = request.Headers.ReplyTo;
OperationContext.Current.OutgoingMessageHeaders.To = reply.Uri;
OperationContext.Current.OutgoingMessageHeaders.RelatesTo = request.Headers.MessageId;
return null;
}
开发者ID:ronybot,项目名称:MessageBus,代码行数:7,代码来源:ReplyToBehavior.cs
示例3: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
bool shouldCompressResponse = false;
object propObj;
if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out propObj))
{
var prop = (HttpRequestMessageProperty)propObj;
var accept = prop.Headers[HttpRequestHeader.Accept];
if (accept != null)
{
if (jsonContentTypes.IsMatch(accept))
{
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
}
else if (xmlContentTypes.IsMatch(accept))
{
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml;
}
}
var acceptEncoding = prop.Headers[HttpRequestHeader.AcceptEncoding];
if (acceptEncoding != null && acceptEncoding.Contains("gzip"))
{
shouldCompressResponse = true;
}
}
return shouldCompressResponse;
}
开发者ID:carlosfigueira,项目名称:WCFSamples,代码行数:30,代码来源:CompressionAndFormatSelectionMessageInspector.cs
示例4: Main
static void Main()
{
// Construct InstanceContext to handle messages on callback interface
InstanceContext instanceContext = new InstanceContext(new CallbackHandler());
// Create a client with given client endpoint configuration
CalculatorDuplexClient client = new CalculatorDuplexClient(instanceContext);
Console.WriteLine("Press <ENTER> to terminate client once the output is displayed.");
Console.WriteLine();
// Call the AddTo service operation.
double value = 100.00D;
client.AddTo(value);
// Call the SubtractFrom service operation.
value = 50.00D;
client.SubtractFrom(value);
// Call the MultiplyBy service operation.
value = 17.65D;
client.MultiplyBy(value);
// Call the DivideBy service operation.
value = 2.00D;
client.DivideBy(value);
// Complete equation
client.Clear();
Console.ReadLine();
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
}
开发者ID:ssickles,项目名称:archive,代码行数:35,代码来源:client.cs
示例5: Main
static void Main(string[] args)
{
NameCallBackHandler nameHandler = new NameCallBackHandler();
InstanceContext instanceContextName = new InstanceContext(nameHandler);
DualNameServiceClient nameClient = new DualNameServiceClient(instanceContextName);
Console.WriteLine("Displaying name ");
nameClient.ShowName();
WaitHandle.WaitAll(new AutoResetEvent[]{nameHandler.ResetEvent});
Console.WriteLine("Exiting main....");
//InstanceContext instanceContext = new InstanceContext(new CallbackHandler());
//DualCalculatorServiceClient client = new DualCalculatorServiceClient(instanceContext);
//Console.WriteLine("Press <ENTER> to terminate client once the output is displayed.");
//Console.WriteLine();
//double value = 100.00D;
//client.AddTo(value);
//value = 50.00D;
//client.SubtractFrom(value);
//client.Clear();
//Console.ReadLine();
//client.Close();
}
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:31,代码来源:Program.cs
示例6: ReleaseInstance
public void ReleaseInstance(InstanceContext instanceContext, object instance)
{
if (instance is IDisposable)
{
(instance as IDisposable).Dispose();
}
}
开发者ID:huanlin,项目名称:di-book-support,代码行数:7,代码来源:MyInstanceProvider.cs
示例7: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
CorsState state = null;
HttpRequestMessageProperty responseProperty = null;
if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
{
responseProperty = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
}
if (responseProperty != null)
{
//Handle cors requests
var origin = responseProperty.Headers["Origin"];
if (!string.IsNullOrEmpty(origin))
{
state = new CorsState();
//if a cors options request (preflight) is detected, we create our own reply message and don't invoke any operation at all.
if (responseProperty.Method == "OPTIONS")
{
state.Message = Message.CreateMessage(request.Version, FindReplyAction(request.Headers.Action), new EmptyBodyWriter());
}
request.Properties.Add(CrossOriginResourceSharingPropertyName, state);
}
}
return state;
}
开发者ID:nescalante,项目名称:taxbillerservice,代码行数:27,代码来源:CorsDispatchMessageInspector.cs
示例8: MonitorForm_Load
//其他成员
private void MonitorForm_Load(object sender, EventArgs e)
{
string header = string.Format("{0, -13}{1, -22}{2}", "Client", "Time", "Event");
this.listBoxExecutionProgress.Items.Add(header);
_syncContext = SynchronizationContext.Current;
_callbackInstance = new InstanceContext(new CalculatorCallbackService());
_channelFactory = new DuplexChannelFactory<ICalculator>(_callbackInstance, "calculatorservice");
EventMonitor.MonitoringNotificationSended += ReceiveMonitoringNotification;
this.Disposed += delegate
{
EventMonitor.MonitoringNotificationSended -= ReceiveMonitoringNotification;
_channelFactory.Close();
};
for (int i = 0; i < 2; i++)
{
ThreadPool.QueueUserWorkItem(state =>
{
int clientId = Interlocked.Increment(ref _clientId);
EventMonitor.Send(clientId, EventType.StartCall);
ICalculator proxy = _channelFactory.CreateChannel();
using (OperationContextScope contextScope = new OperationContextScope(proxy as IContextChannel))
{
MessageHeader<int> messageHeader = new MessageHeader<int>(clientId);
OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader.GetUntypedHeader(EventMonitor.CientIdHeaderLocalName, EventMonitor.CientIdHeaderNamespace));
proxy.Add(1, 2);
}
EventMonitor.Send(clientId, EventType.EndCall);
}, null);
}
}
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:33,代码来源:MonitorForm.cs
示例9: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request,
IClientChannel channel,
InstanceContext instanceContext)
{
OperationContext.Current.Extensions.Add(new WorkerContext());
return request.Headers.MessageId;
}
开发者ID:GulinSS,项目名称:LargePrimes-Sample,代码行数:7,代码来源:WorkerContextMessageInspector.cs
示例10: SupplierServiceInvoker
static SupplierServiceInvoker()
{
CallbackContext = new SupplierCallback();
InstanceContext context = new InstanceContext(CallbackContext);
client = new CentralSupplierServiceClient(context);
}
开发者ID:driverpt,项目名称:SD-1213SI,代码行数:7,代码来源:SupplierServiceInvoker.cs
示例11: Connect
public bool Connect(ClientCrawlerInfo clientCrawlerInfo)
{
try
{
var site = new InstanceContext(this);
var binding = new NetTcpBinding(SecurityMode.None);
//var address = new EndpointAddress("net.tcp://localhost:22222/chatservice/");
var address = new EndpointAddress("net.tcp://193.124.113.235:22222/chatservice/");
var factory = new DuplexChannelFactory<IRemoteCrawler>(site, binding, address);
proxy = factory.CreateChannel();
((IContextChannel)proxy).OperationTimeout = new TimeSpan(1, 0, 10);
clientCrawlerInfo.ClientIdentifier = _singletoneId;
proxy.Join(clientCrawlerInfo);
return true;
}
catch (Exception ex)
{
MessageBox.Show("Error happened" + ex.Message);
return false;
}
}
开发者ID:8ezhikov,项目名称:Git4Life,代码行数:27,代码来源:ProxySingletone.cs
示例12: ConnectIpc
public static void ConnectIpc(IServiceRemotingCallback serviceRemotingCallback)
{
InstanceContext instanceContext = new InstanceContext(serviceRemotingCallback);
PipeFactory = new DuplexChannelFactory<IServiceRemoting>(instanceContext, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/BitCollectors.PlinkService/PlinkService"));
RemotingObject = PipeFactory.CreateChannel();
}
开发者ID:tk-s,项目名称:BitCollectors.PlinkService,代码行数:7,代码来源:WcfClientHelper.cs
示例13: Main
static void Main(string[] args)
{
Console.WriteLine("create service...");
var instanceContext = new InstanceContext(new callback());
var service = new ServiceReference1.SimulationInformationServiceClient(instanceContext);
service.Open();
Console.WriteLine("ping server boolean");
var result = service.PingServerBoolean();
Console.WriteLine("done: "+result);
Console.WriteLine("ping server void");
service.PingServerVoid();
Console.WriteLine("done");
//Console.WriteLine("ping server void and ping back");
//result = service.PingServerBooleanAndPingBack();
//Console.WriteLine("done: "+result);
Console.WriteLine("subscribe to sensor data");
result = service.SubscribeSensorData();
Console.WriteLine("done: " + result);
Console.ReadLine();
}
开发者ID:debuglevel,项目名称:NEsper-CEP-Example,代码行数:25,代码来源:Program.cs
示例14: Main
static void Main(string[] args)
{
InstanceContext site = new InstanceContext(null, new Client());
SampleContractClient client = new SampleContractClient(site);
//create a unique callback address so multiple clients can run on one machine
WSDualHttpBinding binding = (WSDualHttpBinding)client.Endpoint.Binding;
string clientcallbackaddress = binding.ClientBaseAddress.AbsoluteUri;
clientcallbackaddress += Guid.NewGuid().ToString();
binding.ClientBaseAddress = new Uri(clientcallbackaddress);
//Subscribe.
Console.WriteLine("Subscribing");
client.Subscribe();
Console.WriteLine();
Console.WriteLine("Press ENTER to unsubscribe and shut down client");
Console.ReadLine();
Console.WriteLine("Unsubscribing");
client.Unsubscribe();
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
}
开发者ID:ssickles,项目名称:archive,代码行数:26,代码来源:client.cs
示例15: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
if (request.Properties.ContainsKey("UriTemplateMatchResults"))
{
HttpRequestMessageProperty httpmsg = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
UriTemplateMatch match = (UriTemplateMatch)request.Properties["UriTemplateMatchResults"];
string format = match.QueryParameters["$format"];
if ("json".Equals(format, StringComparison.InvariantCultureIgnoreCase))
{
// strip out $format from the query options to avoid an error
// due to use of a reserved option (starts with "$")
match.QueryParameters.Remove("$format");
// replace the Accept header so that the Data Services runtime
// assumes the client asked for a JSON representation
httpmsg.Headers["Accept"] = "application/json, text/plain;q=0.5";
httpmsg.Headers["Accept-Charset"] = "utf-8";
string callback = match.QueryParameters["$callback"];
if (!string.IsNullOrEmpty(callback))
{
match.QueryParameters.Remove("$callback");
return callback;
}
}
}
return null;
}
开发者ID:gabla5,项目名称:LearningProjects,代码行数:30,代码来源:JsonPSupportBehaviorAttribute.cs
示例16: CreateSession
internal void CreateSession()
{
Uri serviceAddress = new Uri("net.pipe://localhost/Multitouch.Service/ApplicationInterface");
EndpointAddress remoteAddress = new EndpointAddress(serviceAddress);
NetNamedPipeBinding namedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
namedPipeBinding.MaxReceivedMessageSize = int.MaxValue;
namedPipeBinding.MaxBufferSize = int.MaxValue;
namedPipeBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
namedPipeBinding.ReceiveTimeout = TimeSpan.MaxValue;
IApplicationInterfaceCallback dispatcher = new MultitouchServiceContactDispatcher(logic);
InstanceContext instanceContext = new InstanceContext(dispatcher);
service = new ApplicationInterfaceClient(instanceContext, namedPipeBinding, remoteAddress);
try
{
service.CreateSession();
MouseHelper.SingleMouseFallback = false;
}
catch (EndpointNotFoundException)
{
//throw new MultitouchException("Could not connect to Multitouch service, please start Multitouch input server before running this application.", e);
Trace.TraceWarning("Could not connect to Multitouch service. Enabling single mouse input.");
SingleMouseClientAndDispatcher client = new SingleMouseClientAndDispatcher(logic);
service = client;
dispatcher = client;
MouseHelper.SingleMouseFallback = true;
}
contactDispatcher = dispatcher;
}
开发者ID:zhuangfangwang,项目名称:ise,代码行数:30,代码来源:ServiceCommunicator.cs
示例17: InitializeProxy
private void InitializeProxy(string IpAddress, CallBackFunctionSignature callback)
{
try
{
Url = string.Format("net.tcp://{0}:8001/KryptonService", IpAddress);
_callback = callback;
InstanceContext context = new InstanceContext(this);
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxDepth= 2147483647;
binding.ReaderQuotas.MaxStringContentLength=2147483647;
binding.ReaderQuotas.MaxArrayLength= 2147483647;
binding.ReaderQuotas.MaxBytesPerRead= 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
binding.OpenTimeout = TimeSpan.FromMinutes(10);
binding.SendTimeout = TimeSpan.FromMinutes(20);
binding.ReceiveTimeout = TimeSpan.FromMinutes(20);
binding.MaxBufferPoolSize = 2147483647;
_proxy = new KryptonServiceProxy(context, binding, Url);
_proxy.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
_proxy = null;
}
}
开发者ID:jhamadhukar,项目名称:KryptonService,代码行数:29,代码来源:ServiceAgent.cs
示例18: GetInstance
public object GetInstance(InstanceContext instanceContext, Message message)
{
//if (_container == null)
// CreateBehavior();
return _container.GetInstance(_serviceType);
//return ObjectFactory.GetInstance(_serviceType);
}
开发者ID:gtmorais,项目名称:wcf_structuremap,代码行数:7,代码来源:StructureMapInstanceProvider.cs
示例19: ServiceAgent
public ServiceAgent(string Url)
{
try
{
InstanceContext context = new InstanceContext(this);
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxDepth= 2147483647;
binding.ReaderQuotas.MaxStringContentLength=2147483647;
binding.ReaderQuotas.MaxArrayLength= 2147483647;
binding.ReaderQuotas.MaxBytesPerRead= 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
binding.OpenTimeout = TimeSpan.FromMinutes(10);
binding.SendTimeout = TimeSpan.FromMinutes(20);
binding.ReceiveTimeout = TimeSpan.FromMinutes(20);
binding.MaxBufferPoolSize = 2147483647;
_proxy = new KryptonServiceProxy(context, binding, Url);
_proxy.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
_proxy = null;
}
}
开发者ID:jhamadhukar,项目名称:KryptonService,代码行数:26,代码来源:ServiceAgent.cs
示例20: AddItem
void AddItem(InstanceContext instanceContext)
{
int index = this.firstFreeIndex;
this.firstFreeIndex = this.items[index].nextFreeIndex;
this.items[index].instanceContext = instanceContext;
instanceContext.InstanceContextManagerIndex = index;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:InstanceContextManager.cs
注:本文中的System.ServiceModel.InstanceContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论