當前位置: 首頁>>代碼示例>>C#>>正文


C# ServiceModel.InstanceContext類代碼示例

本文整理匯總了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;
        }
開發者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


注:本文中的System.ServiceModel.InstanceContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。