本文整理汇总了C#中System.ServiceModel.InstanceContext类的典型用法代码示例。如果您正苦于以下问题:C# InstanceContext类的具体用法?C# InstanceContext怎么用?C# InstanceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstanceContext类属于System.ServiceModel命名空间,在下文中一共展示了InstanceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例6: ReleaseInstance
public void ReleaseInstance(InstanceContext instanceContext, object instance)
{
if (instance is IDisposable)
{
(instance as IDisposable).Dispose();
}
}
示例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;
}
示例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);
}
}
示例9: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request,
IClientChannel channel,
InstanceContext instanceContext)
{
OperationContext.Current.Extensions.Add(new WorkerContext());
return request.Headers.MessageId;
}
示例10: SupplierServiceInvoker
static SupplierServiceInvoker()
{
CallbackContext = new SupplierCallback();
InstanceContext context = new InstanceContext(CallbackContext);
client = new CentralSupplierServiceClient(context);
}
示例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;
}
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}