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


C# RequestContext.Reply方法代码示例

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


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

示例1: ProcessRequest

 public override void ProcessRequest(ref RequestContext requestContext)
 {
     if (!manager.AuthenticateRequest(requestContext.RequestMessage)) {
         requestContext.Reply(manager.CreateInvalidAuthenticationRequest());
         requestContext = null;
     }
 }
开发者ID:barbarossia,项目名称:DIS,代码行数:7,代码来源:BasicAuthenticationInterceptor.cs

示例2: CreateAndSendInvalidAuthenticationRequest

 private RequestContext CreateAndSendInvalidAuthenticationRequest(RequestContext requestContext)
 {
     using (Message responseMessage = authenticationManager.CreateInvalidAuthenticationRequest(requestContext.RequestMessage))
      {
     requestContext.Reply(responseMessage);
     requestContext = null;
     return requestContext;
      }
 }
开发者ID:kalkie,项目名称:DigestAuthenticationUsingWCF,代码行数:9,代码来源:DigestAuthenticationInterceptor.cs

示例3: Unauthorized

        public static void Unauthorized(ref RequestContext context, string nonauthorizedHeaderValue)
        {
            var reply = Message.CreateMessage(MessageVersion.None, null);
            var responseProperty = new HttpResponseMessageProperty() { StatusCode = HttpStatusCode.Unauthorized };

            responseProperty.Headers.Add(HttpResponseHeader.WwwAuthenticate,
                                         nonauthorizedHeaderValue);

            reply.Properties[HttpResponseMessageProperty.Name] = responseProperty;
            context.Reply(reply);
            context = null;
        }
开发者ID:javicrespo,项目名称:WcfRestAuth,代码行数:12,代码来源:RequestContextUtils.cs

示例4: ProcessRequest

        public override void ProcessRequest(ref RequestContext requestContext)
        {
            string[] credentials = ExtractCredentials(requestContext.RequestMessage);
            if (credentials.Length > 0 && AuthenticateUser(credentials[0], credentials[1]))
            {
                InitializeSecurityContext(requestContext.RequestMessage, credentials[0]);
            }
            else
            {
                Message reply = Message.CreateMessage(MessageVersion.None, null);
                HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty() { StatusCode = HttpStatusCode.Unauthorized };

                responseProperty.Headers.Add("WWW-Authenticate",
                    String.Format("Basic realm=\"{0}\"", Realm));

                reply.Properties[HttpResponseMessageProperty.Name] = responseProperty;
                requestContext.Reply(reply);

                requestContext = null;
            }
        }
开发者ID:zxcnasab,项目名称:CustomBasicAuthentication,代码行数:21,代码来源:BasicAuthenticationInterceptor.cs

示例5: GenerateErrorResponse

		public void GenerateErrorResponse(ref RequestContext requestContext, HttpStatusCode statusCode, string errorMessage)
		{
			// The error message is padded so that IE shows the response by default
			var reply = Message.CreateMessage(MessageVersion.None, null, new Error() { Message = errorMessage });
			var responseProp = new HttpResponseMessageProperty()
			{
				StatusCode = statusCode
			};
			reply.Properties[HttpResponseMessageProperty.Name] = responseProp;
			requestContext.Reply(reply);
			requestContext = null;
		}
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:12,代码来源:AuthorizationInterceptor.cs

示例6: ProcessRequest

    public override void ProcessRequest(ref RequestContext requestContext)
    {
      if (requestContext == null || requestContext.RequestMessage == null)
      {
        return;
      }

      Message request = requestContext.RequestMessage;

      var requestProperty = (HttpRequestMessageProperty) request.Properties[HttpRequestMessageProperty.Name];

      IOAuthContext context = new OAuthContextBuilder().FromUri(requestProperty.Method, request.Headers.To);

      try
      {
        _provider.AccessProtectedResourceRequest(context);

        AccessToken accessToken = _repository.GetToken(context.Token);

        TokenPrincipal principal = CreatePrincipalFromToken(accessToken);

        InitializeSecurityContext(request, principal);
      }
      catch (OAuthException authEx)
      {
        XElement response = GetHtmlFormattedErrorReport(authEx);
        Message reply = Message.CreateMessage(MessageVersion.None, null, response);
        var responseProperty = new HttpResponseMessageProperty {StatusCode = HttpStatusCode.Forbidden, StatusDescription = authEx.Report.ToString()};
        responseProperty.Headers[HttpResponseHeader.ContentType] = "text/html";
        reply.Properties[HttpResponseMessageProperty.Name] = responseProperty;
        requestContext.Reply(reply);

        requestContext = null;
      }
    }
开发者ID:yonglehou,项目名称:DevDefined.OAuth,代码行数:35,代码来源:OAuthInterceptor.cs

示例7: ProcessRequest

 private void ProcessRequest(RequestContext context, WsrmMessageInfo info)
 {
     bool flag = true;
     bool flag2 = true;
     try
     {
         EndpointAddress address;
         bool flag3;
         if (!base.ReliableSession.ProcessInfo(info, context))
         {
             flag = false;
             flag2 = false;
             return;
         }
         if (!base.ReliableSession.VerifySimplexProtocolElements(info, context))
         {
             flag = false;
             flag2 = false;
             return;
         }
         base.ReliableSession.OnRemoteActivity(false);
         if (info.CreateSequenceInfo == null)
         {
             goto Label_0104;
         }
         if (WsrmUtilities.ValidateCreateSequence<IInputSessionChannel>(info, base.Listener, base.Binder.Channel, out address))
         {
             Message response = WsrmUtilities.CreateCreateSequenceResponse(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion, false, info.CreateSequenceInfo, base.Listener.Ordered, base.ReliableSession.InputID, address);
             using (context)
             {
                 using (response)
                 {
                     if (base.Binder.AddressResponse(info.Message, response))
                     {
                         context.Reply(response, base.DefaultSendTimeout);
                     }
                 }
                 goto Label_00FB;
             }
         }
         base.ReliableSession.OnLocalFault(info.FaultException, info.FaultReply, context);
     Label_00FB:
         flag = false;
         flag2 = false;
         return;
     Label_0104:
         flag3 = false;
         bool allAdded = false;
         bool flag5 = false;
         WsrmFault fault = null;
         Message message2 = null;
         Exception e = null;
         bool flag6 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005;
         bool flag7 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;
         bool flag8 = info.AckRequestedInfo != null;
         if (info.SequencedMessageInfo != null)
         {
             lock (base.ThisLock)
             {
                 if (base.Aborted || (base.State == CommunicationState.Faulted))
                 {
                     return;
                 }
                 long sequenceNumber = info.SequencedMessageInfo.SequenceNumber;
                 bool isLast = flag6 && info.SequencedMessageInfo.LastMessage;
                 if (!base.Connection.IsValid(sequenceNumber, isLast))
                 {
                     if (flag6)
                     {
                         fault = new LastMessageNumberExceededFault(base.ReliableSession.InputID);
                     }
                     else
                     {
                         message2 = new SequenceClosedFault(base.ReliableSession.InputID).CreateMessage(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion);
                         if (PerformanceCounters.PerformanceCountersEnabled)
                         {
                             PerformanceCounters.MessageDropped(base.perfCounterId);
                         }
                     }
                 }
                 else if (base.Connection.Ranges.Contains(sequenceNumber))
                 {
                     if (PerformanceCounters.PerformanceCountersEnabled)
                     {
                         PerformanceCounters.MessageDropped(base.perfCounterId);
                     }
                 }
                 else if (flag6 && (info.Action == "http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage"))
                 {
                     base.Connection.Merge(sequenceNumber, isLast);
                     allAdded = base.Connection.AllAdded;
                 }
                 else if (base.State == CommunicationState.Closing)
                 {
                     if (flag6)
                     {
                         fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedSessionClosedBeforeDone"), System.ServiceModel.SR.GetString("SessionClosedBeforeDone"));
                     }
                     else
                     {
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:ReliableInputSessionChannelOverReply.cs

示例8: SendResponse

        private void SendResponse(RequestContext context)
        {
            Assert.IsNotNull(context);

            // Validate request
            var request = context.RequestMessage;
            Assert.IsNotNull(request);
            var httpRequest = request.ToHttpRequestMessage();
            Assert.IsNotNull(httpRequest);

            // Create response
            var httpResponse = new HttpResponseMessage(HttpStatusCode.OK, BasicChannelTests.ChannelHttpReasonPhrase);
            Assert.IsNotNull(httpResponse);
            TestServiceCommon.CopyTestHeader(httpRequest, httpResponse);

            // Send response
            var response = httpResponse.ToMessage();
            Assert.IsNotNull(response);
            context.Reply(response);
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:20,代码来源:ChannelTests.cs

示例9: HandleHttpGet

        void HandleHttpGet(RequestContext context)
        {
            Message message = new HtmlMessage(
                context.RequestMessage.Version,
                context.RequestMessage.Headers.ReplyTo.ToString(),
                HelloWorldService.ServiceName,
                HelloWorldService.OperationName);

            HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty();
            responseProperty.StatusCode = HttpStatusCode.OK;
            HttpRequestMessageProperty requestProperty = (HttpRequestMessageProperty)context.RequestMessage.Properties[HttpRequestMessageProperty.Name];
            responseProperty.Headers.Add(HttpResponseHeader.ContentType, requestProperty.Headers[HttpRequestHeader.ContentType]);
            
            message.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);

            context.Reply(message);
        }
开发者ID:ssickles,项目名称:archive,代码行数:17,代码来源:Service.cs

示例10: HandleRequest

        public void HandleRequest(RequestContext context)
        {
            Debug.Assert(context != null);

            if (context.RequestMessage.Headers.Action == requestAction)
            {
                XmlDictionaryReader reader = context.RequestMessage.GetReaderAtBodyContents();
                DataContractSerializer serializer = new DataContractSerializer(typeof(string));
                reader.ReadStartElement(); // read wrapper begin
                string value = (string)serializer.ReadObject(reader, false);
                reader.ReadEndElement(); // read wrapper end

                reader.Close();

                string result = serviceInstance.Hello(value);
                ResponseBodyWriter responseBodyWriter = new ResponseBodyWriter(
                    HelloWorldService.OperationName,
                    HelloWorldService.Namespace);
                responseBodyWriter.Result = result;

                MessageVersion requestVersion = context.RequestMessage.Version;
                UniqueId requestId = context.RequestMessage.Headers.MessageId;

                Message reply = Message.CreateMessage(requestVersion,
                                                      responseAction,
                                                      responseBodyWriter);

                PrepareReply(reply, requestId);
                if (context.RequestMessage.Headers.ReplyTo != null)
                {
                    reply.Headers.To = context.RequestMessage.Headers.ReplyTo.Uri;
                }

                context.Reply(reply);
            }
            else
            {                
                object property = null;
                if (context.RequestMessage.Properties.TryGetValue(HttpRequestMessageProperty.Name,
                    out property))
                {
                    if (string.Compare(((HttpRequestMessageProperty)property).Method, "GET", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        HandleHttpGet(context);
                        return;
                    }
                }

                SendMismatchFault(context);
            }
        }
开发者ID:ssickles,项目名称:archive,代码行数:51,代码来源:Service.cs

示例11: ProcessRequest

        public void ProcessRequest(RequestContext context)
        {
            MessageHeaders headers = context.RequestMessage.Headers;

            //create new request channel if needed
            IRequestChannel requestChannel = null;
            if (!_Clients.TryGetValue(headers.To, out requestChannel))
            {
                WSHttpBinding binding = CreateBinding();
                IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
                factory.Open();

                requestChannel = factory.CreateChannel(new EndpointAddress(headers.To));
                requestChannel.Open();
                _Clients.Add(headers.To, requestChannel);
            }

            //forward request and send back response
            MessageContainer container = new MessageContainer();
            Message incoming = CopyMessage(context.RequestMessage, container, MessageDirection.Incoming);
            if ((DateTime.Now - _LastReceived).TotalMilliseconds > 1750)
            {
                _Group += 1;
            }
            container.Group = _Group;
            _LastReceived = DateTime.Now;

            //add request to gui
            Action<int, MessageContainer> msg = new Action<int, MessageContainer>(Messages.Insert);
            this.Dispatcher.Invoke(msg, new object[] { 0, container });

            //get response
            Message responseMessage = requestChannel.Request(incoming);
            Message outgoing = CopyMessage(responseMessage, container, MessageDirection.Outgoing);
            context.Reply(outgoing);
        }
开发者ID:JoeBuntu,项目名称:Messaging-Tool,代码行数:36,代码来源:MainWindow.xaml.cs

示例12: Reply

 private bool Reply(RequestContext request, Message reply)
 {
     if (this.replied != request)
     {
         this.replied = request;
         bool flag = true;
         Message objA = null;
         try
         {
             objA = request.RequestMessage;
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
         }
         if (!object.ReferenceEquals(objA, null))
         {
             UniqueId messageId = null;
             try
             {
                 messageId = objA.Headers.MessageId;
             }
             catch (MessageHeaderException)
             {
             }
             if (!object.ReferenceEquals(messageId, null) && !this.isManualAddressing)
             {
                 RequestReplyCorrelator.PrepareReply(reply, messageId);
             }
             if (!this.hasSession && !this.isManualAddressing)
             {
                 try
                 {
                     flag = RequestReplyCorrelator.AddressReply(reply, objA);
                 }
                 catch (MessageHeaderException)
                 {
                 }
             }
         }
         if (this.IsOpen && flag)
         {
             request.Reply(reply);
             return true;
         }
     }
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:51,代码来源:ChannelHandler.cs

示例13: CreateErrorReply

        private void CreateErrorReply(ref RequestContext p_RequestContext)
        {
            var l_Message = new CustomResponse();
            l_Message.Message = "Login Failed";

             using (Message reply = Message.CreateMessage(MessageVersion.None, "", l_Message, new DataContractJsonSerializer(typeof(CustomResponse))))
             {
                 var responseProp = new HttpResponseMessageProperty
                 {
                     StatusCode = HttpStatusCode.Forbidden,
                     StatusDescription = String.Format("Forbidden")
                 };

                 responseProp.Headers.Add("WWW-Authenticate", String.Format("Basic realm=\"{0}\"", Realm));
                 responseProp.Headers[HttpResponseHeader.ContentType] = "application/json; charset=utf-8";
                 reply.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
                 reply.Properties[HttpResponseMessageProperty.Name] = responseProp;

                 p_RequestContext.Reply(reply);
                 // set the request context to null to terminate processing of this request
                 p_RequestContext = null;

             }
        }
开发者ID:px-lewis-wilkie,项目名称:PxLogWebService,代码行数:24,代码来源:Authorization.cs

示例14: CreateSuccessReply

        private void CreateSuccessReply(ref RequestContext p_RequestContext, string p_PasswordHash)
        {
            var l_Message = new CustomResponse();
            l_Message.Message = "Login Successful";
            l_Message.Data = p_PasswordHash;

            using (Message reply = Message.CreateMessage(MessageVersion.None, "", l_Message, new DataContractJsonSerializer(typeof(CustomResponse))))
            {
                var responseProp = new HttpResponseMessageProperty
                {
                    StatusCode = HttpStatusCode.Accepted,
                    StatusDescription = String.Format("Accepted")
                };

                responseProp.Headers.Add("WWW-Authenticate", String.Format("Basic realm=\"{0}\"", Realm));
                responseProp.Headers[HttpResponseHeader.ContentType] = "application/json; charset=utf-8";
                reply.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
                reply.Properties[HttpResponseMessageProperty.Name] = responseProp;

                p_RequestContext.Reply(reply);

            }
        }
开发者ID:px-lewis-wilkie,项目名称:PxLogWebService,代码行数:23,代码来源:Authorization.cs

示例15: CreateErrorReply

 private void CreateErrorReply(ref RequestContext requestContext)
 {
     // The error message is padded so that IE shows the response by default
     using (var sr = new StringReader("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + ErrorHtml))
     {
         XElement response = XElement.Load(sr);
         using (Message reply = Message.CreateMessage(MessageVersion.None, null, response))
         {
             var responseProp = new HttpResponseMessageProperty
             {
                 StatusCode = HttpStatusCode.Forbidden,
                 StatusDescription = String.Format("Forbidden")
             };
             responseProp.Headers.Add("WWW-Authenticate", String.Format("Basic realm=\"{0}\"", Realm));
             responseProp.Headers[System.Net.HttpResponseHeader.ContentType] = "text/html";
             reply.Properties[HttpResponseMessageProperty.Name] = responseProp;
             requestContext.Reply(reply);
             // set the request context to null to terminate processing of this request
             requestContext = null;
         }
     }
 }
开发者ID:jkyadav,项目名称:wcf-cross-domain,代码行数:22,代码来源:BasicAuthorization.cs


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