Пример #1
1
        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);
                                                         }
                                             		}
                                             	});
            }
        }
Пример #2
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            if (WcfPerformaceMonitorContext.Current != null)
            {
                MessageHeader <bool> mhMonitorSwitch = new MessageHeader <bool>(true);
                string        messageHeaderName      = SOD.PERFORMANCE_MONITOR_SWITCH_MESSAGE_HEADER;
                MessageHeader header = mhMonitorSwitch.GetUntypedHeader(messageHeaderName, SOD.MESSAGE_HEADER_NAME_SPACE);
                int           ret    = request.Headers.FindHeader(messageHeaderName, SOD.MESSAGE_HEADER_NAME_SPACE);
                if (ret < 0)
                {
                    request.Headers.Add(header);
                }

                WcfRequestMonitorInfo monitorInfo = new WcfRequestMonitorInfo();
                monitorInfo.RequestURI      = channel.Via.ToString();
                monitorInfo.RequestAction   = request.Headers.Action;
                monitorInfo.WcfRequestWatch = new System.Diagnostics.Stopwatch();
                monitorInfo.WcfRequestWatch.Start();
                WcfPerformaceMonitorContext.Current.WcfProcessMonitorInfos.Add(monitorInfo);

                return(monitorInfo);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            if (WcfPerformaceMonitorContext.Current != null)
            {
                DateTime dtWcfProcessBegin = (DateTime)correlationState;
                DateTime dtWcfProcessEnd   = DateTime.Now;
                WcfPerformaceMonitorContext.Current.WcfProcessMonitorInfos[0].WcfProcessTimeOnServer = dtWcfProcessEnd.Subtract(dtWcfProcessBegin);
                WcfRequestMonitorInfo monitorInfo = WcfPerformaceMonitorContext.Current.WcfProcessMonitorInfos[0];

                MessageHeader <WcfRequestMonitorInfo> response = new MessageHeader <WcfRequestMonitorInfo>(monitorInfo);
                string        messageHeaderName = SOD.PERFORMANCE_MONITOR_RESPONSE_MESSAGE_HEADER;
                MessageHeader header            = response.GetUntypedHeader(messageHeaderName, SOD.MESSAGE_HEADER_NAME_SPACE);
                int           ret = reply.Headers.FindHeader(messageHeaderName, SOD.MESSAGE_HEADER_NAME_SPACE);
                if (ret < 0)
                {
                    reply.Headers.Add(header);
                }

                //释放服务器中的当前WCF监测的对象
                while (WcfPerformanceMonitorScope.CurrentScope != null)
                {
                    WcfPerformanceMonitorScope.CurrentScope.Dispose();
                }
            }
        }
Пример #4
0
        public void OnBeforeRequest(ref Message requestMessage)
        {
            var customHeader        = new MessageHeader <Guid>(m_CustomToken);
            var customUntypedHeader = customHeader.GetUntypedHeader("customToken", "http://customToken");

            requestMessage.Headers.Add(customUntypedHeader);
        }
Пример #5
0
        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();
        }
Пример #6
0
        public static void SetHeader(IContextChannel channel, T header)
        {
            MessageHeader <T>     messageHeader         = new MessageHeader <T>(header);
            OperationContextScope operationContextScope = new OperationContextScope(channel);

            OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader.GetUntypedHeader(typeof(T).ToString(), typeof(T).Namespace));
        }
Пример #7
0
        public static void Add(MessageHeaders headers, ActorId actorId)
        {
            GenericContext <ActorId> context = new GenericContext <ActorId>(actorId);
            MessageHeader <GenericContext <ActorId> > genericHeader = new MessageHeader <GenericContext <ActorId> >(context);

            headers.Add(genericHeader.GetUntypedHeader(GenericContext <ActorId> .TypeName, GenericContext <ActorId> .TypeNamespace));
        }
Пример #8
0
        /// <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();
        }
Пример #9
0
        public static void Add(MessageHeaders headers, ServiceContext serviceContext)
        {
            GenericContext <ServiceContext> context = new GenericContext <ServiceContext>(serviceContext);
            MessageHeader <GenericContext <ServiceContext> > genericHeader = new MessageHeader <GenericContext <ServiceContext> >(context);

            headers.Add(genericHeader.GetUntypedHeader(GenericContext <ServiceContext> .TypeName, GenericContext <ServiceContext> .TypeNamespace));
        }
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            MessageHeader <ApplicationContext> contextHeader = new MessageHeader <ApplicationContext>(ApplicationContext.Current);

            request.Headers.Add(contextHeader.GetUntypedHeader(ApplicationContext.ContextHeaderLocalName, ApplicationContext.ContextHeaderNamespace));
            return(null);
        }
Пример #11
0
        /// <summary>
        /// 在回复的通道中设定需要回复的消息头信息
        /// </summary>
        /// <param name="headerKey"></param>
        /// <param name="content"></param>
        /// <param name="isOverwrite"></param>
        public static void AppendMessageHeader(string headerKey, string content, bool isOverwrite)
        {
            if (OperationContext.Current == null ||
                OperationContext.Current.IncomingMessageVersion == MessageVersion.None ||
                OperationContext.Current.IncomingMessageVersion.Envelope == EnvelopeVersion.None ||
                OperationContext.Current.OutgoingMessageHeaders.MessageVersion == MessageVersion.None ||
                OperationContext.Current.OutgoingMessageHeaders.MessageVersion.Envelope == EnvelopeVersion.None)
            {
                return;
            }

            MessageHeader <string> mh     = new MessageHeader <string>(content);
            MessageHeader          header = mh.GetUntypedHeader(headerKey, SOD.MESSAGE_HEADER_NAME_SPACE);


            int re = OperationContext.Current.OutgoingMessageHeaders.FindHeader(headerKey, SOD.MESSAGE_HEADER_NAME_SPACE);

            if (re < 0)
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(header);
            }
            else
            {
                if (isOverwrite)
                {
                    OperationContext.Current.OutgoingMessageHeaders.RemoveAt(re);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                }
            }
        }
Пример #12
0
        protected override void PreInvoke(ref Message request)
        {
            GenericContext <H> context = new GenericContext <H>(Header);
            MessageHeader <GenericContext <H> > genericHeader = new MessageHeader <GenericContext <H> >(context);

            request.Headers.Add(genericHeader.GetUntypedHeader(GenericContext <H> .TypeName, GenericContext <H> .TypeNamespace));
        }
Пример #13
0
        public static void AddHeader <T>(this MessageHeaders headers, string name, T value)
        {
            if (headers == null)
            {
                throw new InvalidOperationException("No headers could be found in the OperationContext, or the OperationContext does not exist.");
            }
            bool headerExists = false;

            try
            {
                var existingHeader = headers.GetHeader <T>(Header <T> .GetFullName(name),
                                                           Header <T> .TypeNamespace);
                if (existingHeader != null)
                {
                    headerExists = true;
                }
            }
            catch (MessageHeaderException)
            {
                // Debug.Assert(IsHeaderNotExistsException(exception));
            }

            if (headerExists)
            {
                throw new InvalidOperationException("A header with name " + Header <T> .GetFullName(name) + " and namespace " + Header <T> .TypeNamespace + " already exists in the message.");
            }

            MessageHeader <Header <T> > genericHeader = new MessageHeader <Header <T> >(new Header <T>(value));

            headers.Add(genericHeader.GetUntypedHeader(Header <T> .GetFullName(name), Header <T> .TypeNamespace));
        }
        private static void CallSimpleCustomHeaderService()
        {
            using (var client = new SimpleCustomHeaderServiceClient())
            {
                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                    //Log the user who's web session resulted in this service call
                    var webUser = new MessageHeader<string>("joe.bloggs");
                    var webUserHeader = webUser.GetUntypedHeader("web-user", "ns");

                    //Log which webnode we were on behind the load balancer
                    var webNodeId = new MessageHeader<int>(1234);
                    var webNodeIdHeader = webNodeId.GetUntypedHeader("web-node-id", "ns");

                    //Log a unique session id
                    var webSessionId = new MessageHeader<Guid>(Guid.NewGuid());
                    var webSessionIdHeader = webSessionId.GetUntypedHeader("web-session-id", "ns");

                    OperationContext.Current.OutgoingMessageHeaders.Add(webUserHeader);
                    OperationContext.Current.OutgoingMessageHeaders.Add(webNodeIdHeader);
                    OperationContext.Current.OutgoingMessageHeaders.Add(webSessionIdHeader);

                    System.Console.WriteLine(client.DoWork());
                }
            }
        }
Пример #15
0
        //其他成员
        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);
            }
        }
Пример #16
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var contextHeader = new MessageHeader <WCFContext>(WCFContext.Current);

            request.Headers.Add(contextHeader.GetUntypedHeader(WCFContext.ContextHeaderLocalName, WCFContext.ContextHeaderNamespace));
            return(null);
        }
Пример #17
0
        /// <summary>
        /// one-way call to resample an image volume
        /// </summary>
        /// <param name="seriesInstanceUID"></param>
        public void ResampleImageVolume(ImageVolumeResampleRequest request)
        {
            Console.WriteLine(string.Format("Resampling volume {0}", request.SeriesInstanceUID));

            _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();
        }
Пример #18
0
        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;
            _channelFactory = new ChannelFactory <ICalculator>("calculatorservice");

            EventMonitor.MonitoringNotificationSended += ReceiveMonitoringNotification;
            this.Disposed += delegate
            {
                EventMonitor.MonitoringNotificationSended -= ReceiveMonitoringNotification;
                _channelFactory.Close();
            };

            ICalculator proxy = _channelFactory.CreateChannel();

            (proxy as ICommunicationObject).Open();
            for (int i = 1; i < 6; i++)
            {
                ThreadPool.QueueUserWorkItem(state =>
                {
                    int clientId = Interlocked.Increment(ref clientIdIndex);
                    EventMonitor.Send(clientId, EventType.StartCall);
                    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);
            }
        }
Пример #19
0
        internal static MessageHeader CreateCustomSOAPHeader <T>(string name, T value)
        {
            MessageHeader <T> header  = new MessageHeader <T>(value);
            MessageHeader     untyped = header.GetUntypedHeader(name, HEADER_NAMESPACE);

            return(untyped);
        }
        private static void CallSimpleCustomHeaderService()
        {
            using (var client = new SimpleCustomHeaderServiceClient())
            {
                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                    //Log the user who's web session resulted in this service call
                    var webUser       = new MessageHeader <string>("joe.bloggs");
                    var webUserHeader = webUser.GetUntypedHeader("web-user", "ns");

                    //Log which webnode we were on behind the load balancer
                    var webNodeId       = new MessageHeader <int>(1234);
                    var webNodeIdHeader = webNodeId.GetUntypedHeader("web-node-id", "ns");

                    //Log a unique session id
                    var webSessionId       = new MessageHeader <Guid>(Guid.NewGuid());
                    var webSessionIdHeader = webSessionId.GetUntypedHeader("web-session-id", "ns");

                    OperationContext.Current.OutgoingMessageHeaders.Add(webUserHeader);
                    OperationContext.Current.OutgoingMessageHeaders.Add(webNodeIdHeader);
                    OperationContext.Current.OutgoingMessageHeaders.Add(webSessionIdHeader);

                    System.Console.WriteLine(client.DoWork());
                }
            }
        }
Пример #21
0
        static void Main(string[] args)
        {
            string action = "http://www.artech.com/crm/AddCustomer";

            using (Message message = Message.CreateMessage(MessageVersion.Soap11WSAddressingAugust2004, action))
            {
                string          ns      = "http://www.artech.com/crm";
                EndpointAddress address = new EndpointAddress("http://www.artech.com/crm/client");
                message.Headers.To        = new Uri("http://www.artech.com/crm/customerservice");
                message.Headers.From      = address;
                message.Headers.ReplyTo   = address;
                message.Headers.FaultTo   = address;
                message.Headers.MessageId = new UniqueId(Guid.NewGuid());
                message.Headers.RelatesTo = new UniqueId(Guid.NewGuid());

                MessageHeader <string> foo = new MessageHeader <string>("ABC");
                MessageHeader <string> bar = new MessageHeader <string>("abc", true, "", false);
                MessageHeader <string> baz = new MessageHeader <string>("123", false, "http://schemas.xmlsoap.org/soap/actor/next", true);

                message.Headers.Add(foo.GetUntypedHeader("Foo", ns));
                message.Headers.Add(bar.GetUntypedHeader("Bar", ns));
                message.Headers.Add(baz.GetUntypedHeader("Baz", ns));

                WriteMessage(message, "message.xml");
            }
        }
Пример #22
0
        public static void Add(MessageHeaders headers)
        {
            GenericContext <InitializingContext> context = new GenericContext <InitializingContext>(new InitializingContext());
            MessageHeader <GenericContext <InitializingContext> > genericHeader = new MessageHeader <GenericContext <InitializingContext> >(context);

            headers.Add(genericHeader.GetUntypedHeader(GenericContext <InitializingContext> .TypeName, GenericContext <InitializingContext> .TypeNamespace));
        }
Пример #23
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            DateTime now       = DateTime.UtcNow;
            string   timestamp = now.ToString("yyyy-MM-ddTHH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture);

            AuthenticationData authData = new AuthenticationData
            {
                Username = ClientAuthenticationHeaderContext.HeaderInformation.Username,
                Password = ClientAuthenticationHeaderContext.HeaderInformation.Password,
                Timespan = timestamp // This is the seed..
            };

            string serializedAuthData = Serializer.JsonSerializer <AuthenticationData>(authData);

            string signature = string.Empty;

            signature = Encryption.Encrypt(serializedAuthData, true);

            var encryptedHeader = new AuthenticationHeader
            {
                EncryptedSignature = signature
            };

            var typedHeader   = new MessageHeader <AuthenticationHeader>(encryptedHeader);
            var untypedHeader = typedHeader.GetUntypedHeader("authentication-header", "chsakell.com");

            request.Headers.Add(untypedHeader);
            return(null);
        }
Пример #24
0
        public T SetHeaderContainer <V>(V container)
        {
            MessageHeader <V>     messageHeader         = new MessageHeader <V>(container);
            OperationContextScope operationContextScope = new OperationContextScope(base.InnerChannel);

            OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader.GetUntypedHeader(typeof(V).ToString(), typeof(V).Namespace));
            return(Channel);
        }
Пример #25
0
        private static void AddCustomHeaderUserInformation(OperationContextScope scope, string SiteCode)
        {
            string sEncryption = CryptographyHelper.Encrypt(SiteCode);
            MessageHeader <string> customHeaderSiteCode  = new MessageHeader <string>(sEncryption);
            MessageHeader          untypedHeaderSiteCode = customHeaderSiteCode.GetUntypedHeader("SiteCode", "CustomHeader");

            OperationContext.Current.OutgoingMessageHeaders.Add(untypedHeaderSiteCode);
        }
Пример #26
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var messageHeader        = new MessageHeader <string>(CorrelationID);
            var untypedMessageHeader = messageHeader.GetUntypedHeader("SubscriptionID", "");

            request.Headers.Add(untypedMessageHeader);
            return(null);
        }
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            GenericContext <ActorId> context = new GenericContext <ActorId>(m_ActorId);
            MessageHeader <GenericContext <ActorId> > genericHeader = new MessageHeader <GenericContext <ActorId> >(context);

            request.Headers.Add(genericHeader.GetUntypedHeader(GenericContext <ActorId> .TypeName, GenericContext <ActorId> .TypeNamespace));
            return(null);
        }
Пример #28
0
        public UserClientBase()
        {
            MessageHeader <string> header = new MessageHeader <string>("_identity.GetAuthenticationToken()");

            var contextScope = new OperationContextScope(InnerChannel);

            OperationContext.Current.OutgoingMessageHeaders.Add(header.GetUntypedHeader("String", "System"));
        }
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var messageHeader = new MessageHeader <Session>(SessionContext.CurrentSession);
            var unType        = messageHeader.GetUntypedHeader("HeaderMessage", "");

            request.Headers.Add(unType);
            return(null);
        }
Пример #30
0
        protected override void PreInvoke(ref Message request)
        {
            string userName = Thread.CurrentPrincipal.Identity.Name;

            HeaderContext <string> context = new HeaderContext <string>(userName);
            MessageHeader <HeaderContext <string> > genericHeader = new MessageHeader <HeaderContext <string> >(context);

            request.Headers.Add(genericHeader.GetUntypedHeader(HeaderContext <string> .TypeName, HeaderContext <string> .TypeNamespace));
        }
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            request.Headers.RemoveAll("serviceVersion", "https://nww.pathwaysdos.nhs.uk/app/api/webservices");
            var header  = new MessageHeader <string>("1.5");
            var untyped = header.GetUntypedHeader("serviceVersion", string.Empty);

            request.Headers.Add(untyped);
            return(null);
        }
Пример #32
0
        public UserClientBase()
        {
            string userName = Thread.CurrentPrincipal.Identity.Name;
            MessageHeader <string> header = new MessageHeader <string>(userName);

            OperationContextScope contextScope = new OperationContextScope(InnerChannel);

            OperationContext.Current.OutgoingMessageHeaders.Add(header.GetUntypedHeader("String", "System"));
        }
        /// <summary>
        /// This method is called after processing a method on the server side and just
        /// before sending the response to the client.
        /// </summary>
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            // WCF does not automatically add a MessageID on responses.
            Logger.Instance.Trace("Adding MessageID header on response from WSP.");
            var header = new MessageHeader <string>("urn:uuid:" + Guid.NewGuid());

            reply.Headers.Add(header.GetUntypedHeader(WsAdressing.WsAdressingMessageId, WsAdressing.WsAdressing10NameSpace));
            Logger.Instance.Trace("Added MessageID header on response from WSP.");
        }
Пример #34
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            this.GetRequestInfo();
            var typedHeader   = new MessageHeader <RequestInfo>(HeaderInformation.Current);
            var untypedHeader = typedHeader.GetUntypedHeader("request-info", "Arwend.Web.Service");

            request.Headers.Add(untypedHeader);
            return(null);
        }
Пример #35
0
        public void Add(double x, double y)
        {
            //PreCallback
            EventMonitor.Send(EventType.StartExecute);
            Thread.Sleep(5000);
            double result = x + y;

            //Callback
            EventMonitor.Send(EventType.StartCallback);
            int clientId = OperationContext.Current.IncomingMessageHeaders.GetHeader<int>(EventMonitor.CientIdHeaderLocalName, EventMonitor.CientIdHeaderNamespace);
            MessageHeader<int> messageHeader = new MessageHeader<int>(clientId);
            OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader.GetUntypedHeader(EventMonitor.CientIdHeaderLocalName, EventMonitor.CientIdHeaderNamespace));
            OperationContext.Current.GetCallbackChannel<ICalculatorCallback>().ShowResult(result);
            EventMonitor.Send(EventType.EndCallback);

            //PostCallback
            Thread.Sleep(5000);
            EventMonitor.Send(EventType.EndExecute);
        }
Пример #36
0
        private static void Main(string[] args)
        {
            string header = string.Format("{0, -13}{1, -22}{2}", "Client", "Time", "Event");
            Console.WriteLine(header);
            Console.WriteLine("Press any key to run clients");
            Console.ReadKey();

            _syncContext = SynchronizationContext.Current;
            _callbackInstance = new InstanceContext(new CalculatorCallbackService());

            //Create DuplexChannel 
            _channelFactory = new DuplexChannelFactory<ICalculator>(_callbackInstance, "calculatorservice");

            EventMonitor.MonitoringNotificationSended += ReceiveMonitoringNotification;

            for (int i = 0; i < 5; 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);
            }

            Console.WriteLine("Press any key to exit.Client");

            header = string.Format("{0, -13}{1, -22}{2}", "Client", "Time", "Event");
            Console.WriteLine(header);

            Console.ReadKey();

            EventMonitor.MonitoringNotificationSended -= ReceiveMonitoringNotification;

            _channelFactory.Close();
        }
Пример #37
0
        private static void Main(string[] args)
        {
            using (var _channelFactory = new ChannelFactory<ICalculator>("calculatorservice"))
            {
                Console.WriteLine("Press any key to run, Client.");
                Console.ReadKey();
                EventMonitor.MonitoringNotificationSended += ReceiveMonitoringNotification;

                for (int i = 1; i <= 5; i++)
                {
                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        int clientId = Interlocked.Increment(ref clientIdIndex);
                        ICalculator proxy = _channelFactory.CreateChannel();
                        using (proxy as IDisposable)
                        {
                            EventMonitor.Send(clientId, EventType.StartCall);
                            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);
                        }
                    });
                }

                Console.WriteLine("Press any key to exit.Client");
                string header = string.Format("{0, -13}{1, -22}{2}", "Client", "Time", "Event");
                Console.WriteLine(header);

                Console.ReadKey();

                EventMonitor.MonitoringNotificationSended -= ReceiveMonitoringNotification;

                _channelFactory.Close();
            }
        }
Пример #38
0
        /// <summary>
        /// begin meshing for a particular structure
        /// </summary>
        /// <param name="request"></param>
        public void MeshStructure(MeshingRequest request)
        {
            // store the return address
            _responseContext =
                OperationContext.Current.IncomingMessageHeaders.GetHeader<ResponseContext>(
                    "ResponseContext", "ServiceModelEx");
            _responseAddress =
                new EndpointAddress(_responseContext.ResponseAddress);

            // notify that we are performing a meshing
            System.Diagnostics.Trace.WriteLine(
                string.Format("Meshing for structure {0} ({1} contours)",
                    request.StructureGuid,
                    request.ContourGuids != null 
                        ? request.ContourGuids.Count.ToString() : "?"));

            // create the engine
            MeshingEngineClient meshingEngine = new MeshingEngineClient();

            // synchronous call to perform meshing
            MeshingResponse response = meshingEngine.MeshStructure(request);
            meshingEngine.Close();

            // now construct the response proxy based on the return address
            MessageHeader<ResponseContext> responseHeader = new MessageHeader<ResponseContext>(_responseContext);
            NetMsmqBinding binding = new NetMsmqBinding("NoMsmqSecurity");
            MeshingResponseProxy proxy = new MeshingResponseProxy(binding, _responseAddress);

            // and set up the operation context to relay response info
            using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    responseHeader.GetUntypedHeader("ResponseContext", "ServiceModelEx"));

                // send the response
                proxy.OnMeshingDone(response);
            }

            proxy.Close();
        }
        public EnsureCredentialsUseContext(
            string username, string password, string accessKey, IContextChannel channel)
        {
            EsbCredentials credentials = new EsbCredentials
            {
                Username = username,
                Password = password,
            };

            _scope = new OperationContextScope(channel);
            MessageHeader<EsbCredentials> credentialsMessageHeader =
                new MessageHeader<EsbCredentials>(credentials);
            MessageHeader<string> accessKeyMessageHeader =
                new MessageHeader<string>(accessKey);

            OperationContext.Current.OutgoingMessageHeaders
                .Add(credentialsMessageHeader
                .GetUntypedHeader(Esbcredentials, HttpServicesSapoPtDefinitions));

            OperationContext.Current.OutgoingMessageHeaders
                .Add(accessKeyMessageHeader
                .GetUntypedHeader(Esbaccesskey, HttpServicesSapoPtMetadataMarket));
        }
Пример #40
0
        static void InvokeWithDiffrentProxy()
        {
            ChannelFactory<IAdd> factory = new ChannelFactory<IAdd>("AddService");

            for (int i = 0; i < 5; i++)
            {
                IAdd proxy = factory.CreateChannel();
                ThreadPool.QueueUserWorkItem(delegate
                                             	{
                                             		int clientId = Interlocked.Increment(ref index);
                                             		using (
                                             			OperationContextScope contextScope =
                                             				new OperationContextScope(proxy as IContextChannel))
                                             		{
                                             			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);
                                             		}
                                             	});
            }
        }
 public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
 {
     MessageHeader<ApplicationContext> contextHeader = new MessageHeader<ApplicationContext>(ApplicationContext.Current);
     request.Headers.Add(contextHeader.GetUntypedHeader(ApplicationContext.ContextHeaderLocalName, ApplicationContext.ContextHeaderNamespace));
     return null;
 }
Пример #42
0
            public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
            {
                MessageHeader<string> header = new MessageHeader<string>(AppContext.UserName);
                request.Headers.Add(header.GetUntypedHeader("UserName", Ns));

                header = new MessageHeader<string>(AppContext.Password);
                request.Headers.Add(header.GetUntypedHeader("Password", Ns));
                return null;
            }
 public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
 {
     MessageHeader<string> header = new MessageHeader<string>(_username);
     request.Headers.Add(header.GetUntypedHeader("String", "System"));
     return null;
 }
Пример #44
0
 //"ручная" реализация wcf-сессиии - sessionKey передаётся wcf-сервису в header,
 //который его хранит в памяти
 private void setHeader()
 {
     MessageHeader<string> header = new MessageHeader<string>(RepositoryProfile.SessionKey.ToString());
     var sessionKey = header.GetUntypedHeader("sessionKey", "http://VCSmyServerService");
     OperationContext.Current.OutgoingMessageHeaders.Add(sessionKey);
 }