当前位置: 首页>>代码示例>>C#>>正文


C# ServiceModel.OperationContextScope类代码示例

本文整理汇总了C#中System.ServiceModel.OperationContextScope的典型用法代码示例。如果您正苦于以下问题:C# OperationContextScope类的具体用法?C# OperationContextScope怎么用?C# OperationContextScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OperationContextScope类属于System.ServiceModel命名空间,在下文中一共展示了OperationContextScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeWithSameProxy

        static void InvokeWithSameProxy()
        {
            ChannelFactory<IAdd> factory=new ChannelFactory<IAdd>("AddService");
            IAdd proxy = factory.CreateChannel();
            if (null != proxy as ICommunicationObject)
            {
                (proxy as ICommunicationObject).Open();
            }
            var datatime = DateTime.Now;
            Console.WriteLine(datatime);
            int num = 100;
            for (int i = 0; i < num; i++)
            {

                ThreadPool.QueueUserWorkItem(delegate
                                             	{
                                                    int clientId = Interlocked.Increment(ref index);
                                             		using (
                                             			OperationContextScope contextScope =
                                             				new OperationContextScope(proxy as IContextChannel))
                                             		{
                                                         Console.WriteLine(i);
                                                         MessageHeader<int> header = new MessageHeader<int>(clientId);
                                             			System.ServiceModel.Channels.MessageHeader messageHeader =
                                             				header.GetUntypedHeader(MessageWrapper.headerClientId,
                                             				                        MessageWrapper.headerNamespace);
                                             			OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);
                                             			proxy.Add(1, 2);
                                             		    if (i == num-1) {
                                                             Console.WriteLine((DateTime.Now - datatime).Seconds);
                                                         }
                                             		}
                                             	});
            }
        }
开发者ID:tengwei,项目名称:TwApplication,代码行数:35,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            try
            {
                var aqAquisitionServiceClient = new AQAcquisitionServiceClient("BasicHttpBinding_IAQAcquisitionService", "http://sooke/AQUARIUS/AqAcquisitionService.svc/Basic");
                //var aqAquisitionServiceClient = new AQAcquisitionServiceClient("WSHttpBinding_IAQAcquisitionService", "http://sooke/AQUARIUS/AqAcquisitionService.svc");
                var authToken = aqAquisitionServiceClient.GetAuthToken("admin", "admin");
                Console.WriteLine("Token: " + authToken);

                using (var contextScope = new OperationContextScope(aqAquisitionServiceClient.InnerChannel))
                {
                    var runtimeHeader = MessageHeader.CreateHeader("AQAuthToken", "", authToken, false);
                    OperationContext.Current.OutgoingMessageHeaders.Add(runtimeHeader);
                    var allLocations = aqAquisitionServiceClient.GetAllLocations();
                    Console.WriteLine("There are " + allLocations.Length + " Locations:");
                    foreach (var location in allLocations)
                    {
                        Console.WriteLine("\t" + location.Identifier);
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Error occurred: " + ex.ToString());
            }
            Console.WriteLine("Enter to quit...");
            Console.ReadLine();
        }
开发者ID:AlanLiu-AI,项目名称:AqDemos,代码行数:28,代码来源:Program.cs

示例3: GetOSVersionsProcess

		public OperatingSystemList GetOSVersionsProcess(out Operation operation)
		{
			Func<string, OperatingSystemList> func = null;
			OperatingSystemList operatingSystemList = null;
			operation = null;
			using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
			{
				try
				{
					GetAzureOSVersionCommand getAzureOSVersionCommand = this;
					if (func == null)
					{
						func = (string s) => base.Channel.ListOperatingSystems(s);
					}
					operatingSystemList = ((CmdletBase<IServiceManagement>)getAzureOSVersionCommand).RetryCall<OperatingSystemList>(func);
					operation = base.WaitForOperation(base.CommandRuntime.ToString());
				}
				catch (CommunicationException communicationException1)
				{
					CommunicationException communicationException = communicationException1;
					this.WriteErrorDetails(communicationException);
				}
			}
			return operatingSystemList;
		}
开发者ID:nickchal,项目名称:pash,代码行数:25,代码来源:GetAzureOSVersionCommand.cs

示例4: OperationContextScope

 public OperationContextScope(IContextChannel channel)
 {
     this.originalContext = OperationContext.Current;
     this.originalScope = currentScope;
     this.thread = Thread.CurrentThread;
     this.PushContext(new OperationContext(channel));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:OperationContextScope.cs

示例5: AddCertificateProcess

		internal void AddCertificateProcess()
		{
			Action<string> action = null;
			this.ValidateParameters();
			byte[] certificateData = this.GetCertificateData();
			CertificateFile certificateFile = new CertificateFile();
			certificateFile.Data = Convert.ToBase64String(certificateData);
			certificateFile.Password = this.Password;
			certificateFile.CertificateFormat = "pfx";
			CertificateFile certificateFile1 = certificateFile;
			using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
			{
				try
				{
					AddAzureCertificateCommand addAzureCertificateCommand = this;
					if (action == null)
					{
						action = (string s) => base.Channel.AddCertificates(s, this.ServiceName, certificateFile1);
					}
					((CmdletBase<IServiceManagement>)addAzureCertificateCommand).RetryCall(action);
					Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
					ManagementOperationContext managementOperationContext = new ManagementOperationContext();
					managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
					managementOperationContext.set_OperationId(operation.OperationTrackingId);
					managementOperationContext.set_OperationStatus(operation.Status);
					ManagementOperationContext managementOperationContext1 = managementOperationContext;
					base.WriteObject(managementOperationContext1, true);
				}
				catch (CommunicationException communicationException1)
				{
					CommunicationException communicationException = communicationException1;
					this.WriteErrorDetails(communicationException);
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:35,代码来源:AddAzureCertificateCommand.cs

示例6: ResampleImageVolume

        /// <summary>
        /// one-way call to resample an image volume
        /// </summary>
        /// <param name="seriesInstanceUID"></param>
        public void ResampleImageVolume(ImageVolumeResampleRequest request)
        {
            _responseContext =
                OperationContext.Current.IncomingMessageHeaders.GetHeader<ResponseContext>(
                    "ResponseContext", "ServiceModelEx");
            _responseAddress =
                new EndpointAddress(_responseContext.ResponseAddress);

            ResampleEngineClient re = new ResampleEngineClient();

            ImageVolumeResampleResponse response = re.ResampleImageVolume(request);
            System.Diagnostics.Trace.Assert(response.ResampledImageVolumeGuid.CompareTo(Guid.Empty) != 0);

            MessageHeader<ResponseContext> responseHeader = new MessageHeader<ResponseContext>(_responseContext);
            NetMsmqBinding binding = new NetMsmqBinding("NoMsmqSecurity");
            ResampleResponseProxy proxy = new ResampleResponseProxy(binding, _responseAddress);

            using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    responseHeader.GetUntypedHeader("ResponseContext", "ServiceModelEx"));

                proxy.OnResampleDone(response);
            }

            proxy.Close();
        }
开发者ID:dg1an3,项目名称:PheonixRt.Mvvm,代码行数:31,代码来源:ResampleManager.cs

示例7: Main

        static void Main(string[] args)
        {
            var factory = new ChannelFactory<IFantasyService>("*");
            factory.Credentials.UserName.UserName = "scott";
            factory.Credentials.UserName.Password = "sas0927";
            factory.Endpoint.Behaviors.Add(new CustomHeaderEndpointBehavior());
            var proxy = factory.CreateChannel();
            MessageHeader header = MessageHeader.CreateHeader("userId", "http://www.identitystream.com", "Custom Header");

            using (OperationContextScope scope = new OperationContextScope((IContextChannel)proxy))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(header);

                //HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
                //httpRequestProperty.Headers.Add("myCustomHeader", "Custom Happy Value.");
                //httpRequestProperty.Headers.Add(HttpRequestHeader.UserAgent, "my user agent");
                //OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

            }
            IList<string> leagueNames = proxy.GetLeagueNames();
            Console.WriteLine(string.Format("{0} league names returned.", leagueNames.Count));
            int teamWins = proxy.GetTeamWins(1);
            Console.WriteLine(string.Format("{0} team wins for team 1.", teamWins));
            Console.ReadLine();
        }
开发者ID:ssickles,项目名称:archive,代码行数:25,代码来源:Program.cs

示例8: SetAffinityGroupProcess

		public void SetAffinityGroupProcess()
		{
			this.ValidateParameters();
			using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
			{
				try
				{
					UpdateAffinityGroupInput updateAffinityGroupInput = new UpdateAffinityGroupInput();
					updateAffinityGroupInput.Label = ServiceManagementHelper.EncodeToBase64String(this.Label);
					UpdateAffinityGroupInput description = updateAffinityGroupInput;
					if (this.Description != null)
					{
						description.Description = this.Description;
					}
					CmdletExtensions.WriteVerboseOutputForObject(this, description);
					base.RetryCall((string s) => base.Channel.UpdateAffinityGroup(s, this.Name, description));
					Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
					ManagementOperationContext managementOperationContext = new ManagementOperationContext();
					managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
					managementOperationContext.set_OperationId(operation.OperationTrackingId);
					managementOperationContext.set_OperationStatus(operation.Status);
					ManagementOperationContext managementOperationContext1 = managementOperationContext;
					base.WriteObject(managementOperationContext1, true);
				}
				catch (CommunicationException communicationException1)
				{
					CommunicationException communicationException = communicationException1;
					this.WriteErrorDetails(communicationException);
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:31,代码来源:SetAzureAffinityGroupCommand.cs

示例9: ReConnection

        /// <summary>
        /// 重新连接wcf服务
        /// </summary>
        /// <param name="mainfrm"></param>
        public static void ReConnection()
        {
            try
            {
                NetTcpBinding binding = new NetTcpBinding("NetTcpBinding_WCFHandlerService");
                //binding.OpenTimeout = TimeSpan.FromSeconds(10);
                //binding.TransferMode = TransferMode.Buffered;
                DuplexChannelFactory<IWCFHandlerService> mChannelFactory = new DuplexChannelFactory<IWCFHandlerService>(AppGlobal.cache.GetData("ClientService") as IClientService, binding, System.Configuration.ConfigurationSettings.AppSettings["WCF_endpoint"]);
                IWCFHandlerService wcfHandlerService = mChannelFactory.CreateChannel();

                using (var scope = new OperationContextScope(wcfHandlerService as IContextChannel))
                {
                    var router = System.ServiceModel.Channels.MessageHeader.CreateHeader("routerID", myNamespace, AppGlobal.cache.GetData("routerID").ToString());
                    OperationContext.Current.OutgoingMessageHeaders.Add(router);
                    wcfHandlerService.Heartbeat(AppGlobal.cache.GetData("WCFClientID").ToString());
                }

                if (AppGlobal.cache.Contains("WCFService")) AppGlobal.cache.Remove("WCFService");
                AppGlobal.cache.Add("WCFService", wcfHandlerService);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
        }
开发者ID:keep01,项目名称:efwplus_winformframe,代码行数:29,代码来源:WcfClientManage.cs

示例10: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // Local Variables.
                string uRequestID = String.Empty;
                string uStatus = String.Empty;
                String SOAPEndPoint = context.Session["SOAPEndPoint"].ToString();
                String internalOauthToken = context.Session["internalOauthToken"].ToString();
                String id = context.Request.QueryString["id"].ToString().Trim();
                String status = context.Request.QueryString["status"].ToString().Trim();

                // Create the SOAP binding for call.
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Name = "UserNameSoapBinding";
                binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
                binding.MaxReceivedMessageSize = 2147483647;
                var client = new SoapClient(binding, new EndpointAddress(new Uri(SOAPEndPoint)));
                client.ClientCredentials.UserName.UserName = "*";
                client.ClientCredentials.UserName.Password = "*";

                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                    // Add oAuth token to SOAP header.
                    XNamespace ns = "http://exacttarget.com";
                    var oauthElement = new XElement(ns + "oAuthToken", internalOauthToken);
                    var xmlHeader = MessageHeader.CreateHeader("oAuth", "http://exacttarget.com", oauthElement);
                    OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader);

                    // Setup Subscriber Object to pass fields for updating.
                    Subscriber sub = new Subscriber();
                    sub.ID = int.Parse(id);
                    sub.IDSpecified = true;
                    if (status.ToLower() == "unsubscribed")
                        sub.Status = SubscriberStatus.Unsubscribed;
                    else
                        sub.Status = SubscriberStatus.Active;
                    sub.StatusSpecified = true;

                    // Call the Update method on the Subscriber object.
                    UpdateResult[] uResults = client.Update(new UpdateOptions(), new APIObject[] { sub }, out uRequestID, out uStatus);

                    if (uResults != null && uStatus.ToLower().Equals("ok"))
                    {
                        String strResults = string.Empty;
                        strResults += uResults;
                        // Return the update results from handler.
                        context.Response.Write(strResults);
                    }
                    else
                    {
                        context.Response.Write("Not OK!");
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex);
            }
        }
开发者ID:haithemaraissia,项目名称:SubscriberSearch-net,代码行数:60,代码来源:SubscriberUpdate.ashx.cs

示例11: Main

        static void Main(string[] args)
        {
            using (ChannelFactory<IMessage> channelFactory = new ChannelFactory<IMessage>("messageservice"))
            {
                IMessage proxy = channelFactory.CreateChannel();
                using (OperationContextScope contextScope = new OperationContextScope(proxy as IContextChannel))
                {
                    MessageHeader<CultureInfo> header = new MessageHeader<CultureInfo>(Thread.CurrentThread.CurrentUICulture);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header.GetUntypedHeader(CultureInfoHeadLocalName, CultureInfoHeaderNamespace));
                    Console.WriteLine("The UI culture of current thread is {0}", Thread.CurrentThread.CurrentUICulture);
                    Console.WriteLine(proxy.GetMessage());
                }

                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                using (OperationContextScope contextScope = new OperationContextScope(proxy as IContextChannel))
                {
                    MessageHeader<CultureInfo> header = new MessageHeader<CultureInfo>(Thread.CurrentThread.CurrentUICulture);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header.GetUntypedHeader(CultureInfoHeadLocalName, CultureInfoHeaderNamespace));
                    Console.WriteLine("The UI culture of current thread is {0}", Thread.CurrentThread.CurrentUICulture);
                    Console.WriteLine(proxy.GetMessage());
                }
            }

            Console.Read();
        }
开发者ID:Kelvin-Lei,项目名称:WCFService_Demo,代码行数:25,代码来源:Program.cs

示例12: 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);
            }
        }
开发者ID:sven-s,项目名称:SilverlightErfahrungsbericht,代码行数:26,代码来源:MainPage.xaml.cs

示例13: GetResponse

        private void GetResponse(ICollection<IPointToLaceProvider> response)
        {
            var webService = new ConfigureIvidTitleHolder();

            using (var scope = new OperationContextScope(webService.Client.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] =
                    webService.RequestMessageProperty;

                var request =
                    HandleRequest.GetTitleholderQueryRequest(response,_dataProvider.GetRequest<IAmIvidTitleholderRequest>());

                _logCommand.LogConfiguration(new {request}, null);
                _logCommand.LogRequest(new ConnectionTypeIdentifier(webService.Client.Endpoint.Address.ToString()).ForWebApiType(), new { request }, _dataProvider.BillablleState.NoRecordState);

                _response = webService
                    .Client
                    .TitleholderQuery(request);

                webService.Close();

                _logCommand.LogResponse(_response == null ? DataProviderResponseState.NoRecords : DataProviderResponseState.Successful,
                    new ConnectionTypeIdentifier(webService.Client.Endpoint.Address.ToString())
                        .ForWebApiType(), _response ?? new TitleholderQueryResponse(), _dataProvider.BillablleState.NoRecordState);

                if (_response == null)
                    _logCommand.LogFault(new {_dataProvider}, new {NoRequestReceived = "No response received from Ivid Title Holder Data Provider"});
            }
        }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:29,代码来源:CallIvidTitleHolderDataProvider.cs

示例14: RemoveDeploymentProcess

		public void RemoveDeploymentProcess()
		{
			Action<string> action = null;
			using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
			{
				try
				{
					RemoveAzureDeploymentCommand removeAzureDeploymentCommand = this;
					if (action == null)
					{
						action = (string s) => base.Channel.DeleteDeploymentBySlot(s, this.ServiceName, this.Slot);
					}
					((CmdletBase<IServiceManagement>)removeAzureDeploymentCommand).RetryCall(action);
					Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
					ManagementOperationContext managementOperationContext = new ManagementOperationContext();
					managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
					managementOperationContext.set_OperationId(operation.OperationTrackingId);
					managementOperationContext.set_OperationStatus(operation.Status);
					ManagementOperationContext managementOperationContext1 = managementOperationContext;
					base.WriteObject(managementOperationContext1, true);
				}
				catch (CommunicationException communicationException1)
				{
					CommunicationException communicationException = communicationException1;
					this.WriteErrorDetails(communicationException);
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:28,代码来源:RemoveAzureDeploymentCommand.cs

示例15: Main

        static void Main(string[] args)
        {
            Order order1 = new Order(Guid.NewGuid(), DateTime.Today.AddDays(5), Guid.NewGuid(), "Supplier A");
            Order order2 = new Order(Guid.NewGuid(), DateTime.Today.AddDays(-5), Guid.NewGuid(), "Supplier A");

            string path = ConfigurationManager.AppSettings["msmqPath"];
            var address = new Uri(path);
            OrderResponseContext context = new OrderResponseContext();
            context.ResponseAddress = address;

            var channelFactory = new ChannelFactory<IOrderProcesser>("defaultEndpoint");
            var orderProcessor = channelFactory.CreateChannel();
            using (var contextScope = new OperationContextScope(orderProcessor as IContextChannel)) {
                Console.WriteLine("Submit the order of order No.: {0}", order1.OrderNo);
                OrderResponseContext.Current = context;
                orderProcessor.Submit(order1);
            }

            using (OperationContextScope contextScope = new OperationContextScope(orderProcessor as IContextChannel)) {
                Console.WriteLine("Submit the order of order No.: {0}", order2.OrderNo);
                OrderResponseContext.Current = context;
                orderProcessor.Submit(order2);
            }

            Console.Read();
        }
开发者ID:0811112150,项目名称:HappyDayHistory,代码行数:26,代码来源:Program.cs


注:本文中的System.ServiceModel.OperationContextScope类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。