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


C# Channels.HttpResponseMessageProperty类代码示例

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


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

示例1: IncomingWebResponseContext

		internal IncomingWebResponseContext (OperationContext context)
		{
			if (context.IncomingMessageProperties != null)
				hp = (HttpResponseMessageProperty) context.IncomingMessageProperties [HttpResponseMessageProperty.Name];
			else
				hp = new HttpResponseMessageProperty ();
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:IncomingWebResponseContext.cs

示例2: 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

示例3: Get

        public Message Get(Message message)
        {
            HttpRequestMessageProperty requestMessageProperty = (HttpRequestMessageProperty) message.Properties[HttpRequestMessageProperty.Name];
            HttpResponseMessageProperty responseMessageProperty = new HttpResponseMessageProperty();

            if ((requestMessageProperty != null) && IsServiceUnchanged(requestMessageProperty.Headers[JsonGlobals.IfModifiedSinceString]))
            {
                Message responseMessage = Message.CreateMessage(MessageVersion.None, string.Empty);
                responseMessageProperty.StatusCode = HttpStatusCode.NotModified;
                responseMessage.Properties.Add(HttpResponseMessageProperty.Name, responseMessageProperty);
                return responseMessage;
            }

            string proxyContent = this.GetProxyContent(UriTemplate.RewriteUri(this.endpoint.Address.Uri, requestMessageProperty.Headers[HttpRequestHeader.Host]));
            Message response = new WebScriptMetadataMessage(string.Empty, proxyContent);
            responseMessageProperty.Headers.Add(JsonGlobals.LastModifiedString, ServiceLastModifiedRfc1123String);
            responseMessageProperty.Headers.Add(JsonGlobals.ExpiresString, ServiceLastModifiedRfc1123String);
            if (AspNetEnvironment.Current.AspNetCompatibilityEnabled)
            {
                HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
            }
            else
            {
                responseMessageProperty.Headers.Add(JsonGlobals.CacheControlString, JsonGlobals.publicString);
            }
            response.Properties.Add(HttpResponseMessageProperty.Name, responseMessageProperty);
            return response;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:28,代码来源:WebScriptClientGenerator.cs

示例4: ProvideFault

        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            var errorModel = new ErrorModel {Message = error.Message, Type = error.GetType().Name, Success = false};
            fault = Message.CreateMessage(version, null, errorModel, new DataContractJsonSerializer(typeof (ErrorModel)));
            fault.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));

            if (IsAuthenticationException(error))
            {
                var rmp = new HttpResponseMessageProperty {StatusCode = HttpStatusCode.Unauthorized};
                rmp.StatusDescription = rmp.StatusCode.ToString();
                rmp.Headers[HttpResponseHeader.ContentType] = "application/json";
                fault.Properties.Add(HttpResponseMessageProperty.Name, rmp);
            }
            else if (error.GetType() == typeof (InvalidOperationException) || error.GetType() == typeof (ArgumentException))
            {
                var rmp = new HttpResponseMessageProperty {StatusCode = HttpStatusCode.BadRequest};
                rmp.StatusDescription = rmp.StatusCode.ToString();
                rmp.Headers[HttpResponseHeader.ContentType] = "application/json";
                fault.Properties.Add(HttpResponseMessageProperty.Name, rmp);
            }
            else
            {
                errorModel.Message = "Unable to perform the operation";
                var rmp = new HttpResponseMessageProperty {StatusCode = HttpStatusCode.InternalServerError};
                rmp.StatusDescription = rmp.StatusCode.ToString();
                rmp.Headers[HttpResponseHeader.ContentType] = "application/json";
                fault.Properties.Add(HttpResponseMessageProperty.Name, rmp);
            }
        }
开发者ID:XerMajor,项目名称:Shamsullin,代码行数:29,代码来源:WcfRestErrorHandler.cs

示例5: ProcessRequest

        public override void ProcessRequest(ref System.ServiceModel.Channels.RequestContext requestContext)
        {
            var request = requestContext.RequestMessage;

            if (endpointFilter == null || endpointFilter(request))
            {
                IPrincipal principal = ExtractCredentials(request);
                if (principal != null)
                {
                    InitializeSecurityContext(request, principal);
                }
                else
                {
                    var reply = Message.CreateMessage(MessageVersion.None, null);
                    var responseProperty = new HttpResponseMessageProperty() { StatusCode = HttpStatusCode.Unauthorized };

                    if (sendChallenge)
                    {
                        var ts = Hawk.ConvertToUnixTimestamp(DateTime.Now).ToString();
                        var challenge = string.Format("ts=\"{0}\" ntp=\"{1}\"",
                            ts, "pool.ntp.org");

                        responseProperty.Headers.Add("WWW-Authenticate", challenge);
                    }

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

                    requestContext = null;
                }
            }
        }
开发者ID:tugberkugurlu,项目名称:hawknet,代码行数:32,代码来源:HawkRequestInterceptor.cs

示例6: BeginReply_Ignores_HttpResponseMessageProperty_When_Response_Is_Not_HttpMessage

        public void BeginReply_Ignores_HttpResponseMessageProperty_When_Response_Is_Not_HttpMessage()
        {
            Message message = Message.CreateMessage(MessageVersion.None, string.Empty, "some content");
            HttpResponseMessageProperty property = new HttpResponseMessageProperty();
            property.StatusCode = HttpStatusCode.OK;
            property.SuppressEntityBody = false;
            property.Headers.Add(HttpResponseHeader.ContentType, "someType/someSubType");
            message.Properties.Add(HttpResponseMessageProperty.Name, property);

            MockRequestContext innerRequestContext = new MockRequestContext();
            innerRequestContext.OnReplyReceived = innerMessage =>
            {
                HttpResponseMessageProperty innerProperty = innerMessage.Properties[HttpResponseMessageProperty.Name] as HttpResponseMessageProperty;
                Assert.IsNotNull(innerProperty, "The inner HttpMessage instance should have had an HttpResponseMessageProperty.");
                Assert.AreNotSame(property, innerProperty, "The inner HttpResponseMessageProperty should have been a different instance from the one on the response message.");

                Assert.AreEqual(HttpStatusCode.InternalServerError, innerProperty.StatusCode, "HttpResponseMessageProperty.StatusCode should have been HttpStatusCode.InternalServerError.");
                Assert.IsTrue(innerProperty.SuppressEntityBody, "HttpResponseMessageProperty.SuppressEntityBody should have been 'true'.");
                Assert.AreEqual(0, innerProperty.Headers.Count, "HttpResponseMessageProperty.Header.Count should have been zero.");
            };

            HttpMessageEncodingRequestContext requestContext = new HttpMessageEncodingRequestContext(innerRequestContext);
            requestContext.BeginReply(message, null, null);
            Assert.IsTrue(innerRequestContext.BeginReplyCalled, "HttpMessageEncodingRequestContext.BeginReply should have called BeginReply on the inner RequestContext.");
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:25,代码来源:HttpMessageEncodingRequestContextTests.cs

示例7: ProvideFault

        /// <summary>
        /// Enables the creation of a custom <see cref="System.ServiceModel.FaultException"/>
        /// that is returned from an exception in the course of a service method.
        /// </summary>
        /// <param name="error"></param>
        /// <param name="version"></param>
        /// <param name="faultMessage"></param>
        public void ProvideFault(Exception error, MessageVersion version, ref Message faultMessage)
        {
            // Gets a serializable Fault object fromn error.
            Fault fault = Fault.GetFault(error);

            // Now we make the message by serializing the Fault to JSON.
            faultMessage = Message.CreateMessage(version, null, fault,
              new DataContractJsonSerializer(fault.GetType()));

            // Gotta set HTTP status codes.
            HttpResponseMessageProperty prop = new HttpResponseMessageProperty()
            {
                StatusCode = HttpStatusCode.InternalServerError, // 500
                StatusDescription = "An internal server error occurred." // Could use elaboration.
            };

            // Make sure to set the content type. Important for avoiding
            // certain kinds of encoding-specific XSS attacks.
            prop.Headers[HttpResponseHeader.ContentType] = "application/json; charset=utf-8";

            // Set a few other properties of the Message.
            faultMessage.Properties.Add(HttpResponseMessageProperty.Name, prop);
            faultMessage.Properties.Add(WebBodyFormatMessageProperty.Name,
                new WebBodyFormatMessageProperty(WebContentFormat.Json));
        }
开发者ID:ZaneKaminski,项目名称:wcf-raw-json,代码行数:32,代码来源:JsonErrorHandler.cs

示例8: GetFlashPolicy

        public Message GetFlashPolicy(Message request)
        {
            HttpRequestMessageProperty httpRequestProperty;
            if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
            {
                httpRequestProperty = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
                if (!httpRequestProperty.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
                {
                    Message reply = Message.CreateMessage(MessageVersion.None, String.Empty);
                    HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty();
                    responseProperty.StatusCode = System.Net.HttpStatusCode.MethodNotAllowed;
                    responseProperty.SuppressEntityBody = true;
                    reply.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
                    return reply;
                }
            }

            string result = @"<?xml version=""1.0""?>
                                    <!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
                                    <cross-domain-policy>
                                        <allow-access-from domain=""*"" />
                                    </cross-domain-policy>";
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
            Message replyMessage = StreamMessageHelper.CreateMessage(MessageVersion.None, String.Empty, new MemoryStream(Encoding.UTF8.GetBytes(result)));
            HttpResponseMessageProperty replyProperty = new HttpResponseMessageProperty();
            replyProperty.StatusCode = System.Net.HttpStatusCode.OK;
            replyProperty.Headers[HttpResponseHeader.ContentType] = "text/xml;charset=utf-8";
            replyMessage.Properties.Add(HttpResponseMessageProperty.Name, replyProperty);
            return replyMessage;
        }
开发者ID:RobBlackwell,项目名称:ServiceBusReverseWebProxy,代码行数:30,代码来源:PolicyService.cs

示例9: BeforeSendReply

 public void BeforeSendReply(ref Message reply, object correlationState)
 {
     if ((reply != null) && reply.IsFault) {
         var property = new HttpResponseMessageProperty { StatusCode = HttpStatusCode.OK };
         reply.Properties[HttpResponseMessageProperty.Name] = property;
     }
 }
开发者ID:brainster-one,项目名称:uberball,代码行数:7,代码来源:SilverlightFaultBehavior.cs

示例10: AuthenticationService_Authenticating

        void AuthenticationService_Authenticating(object sender, System.Web.ApplicationServices.AuthenticatingEventArgs e)
        {
            string roles = string.Empty;

            e.Authenticated = new UserValidator().IsUserValid(e.UserName, e.Password, out roles);
            e.AuthenticationIsComplete = true;

            if (e.Authenticated)
            {
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                    1,
                    e.UserName,
                    DateTime.Now,
                    DateTime.Now.AddHours(24),
                    true,
                    roles,
                    FormsAuthentication.FormsCookiePath);

                // Encrypt the ticket using machine key
                string encryptedValue = FormsAuthentication.Encrypt(ticket);

                // Attach Cookie to Operation Context header
            HttpResponseMessageProperty response = new HttpResponseMessageProperty();
            response.Headers[HttpResponseHeader.SetCookie] = FormsAuthentication.FormsCookieName + "=" + encryptedValue;
            OperationContext.Current.OutgoingMessageProperties[HttpResponseMessageProperty.Name] = response;
            }
        }
开发者ID:pipiak,项目名称:NovaDemokracia,代码行数:27,代码来源:Global.asax.cs

示例11: AssignLogStatus

 private static void AssignLogStatus(HttpResponseMessageProperty httpResp, Message reply, Log log)
 {
     string errorElement = log["SuccessElement"];
     if(string.IsNullOrEmpty(errorElement)) return;
     if (!log.Response.Contains(errorElement))
         log.Status = Status.Failure;
 }
开发者ID:varunupcurve,项目名称:myrepo,代码行数:7,代码来源:MessageInspectorHelper.cs

示例12: CreateResponseProperty

 private static HttpResponseMessageProperty CreateResponseProperty(DigestHeader digestHeader)
 {
     var responseProperty = new HttpResponseMessageProperty();
      responseProperty.StatusCode = HttpStatusCode.Unauthorized;
      responseProperty.Headers.Add(DigestAuthenticationHeaderName, digestHeader.GenerateHeaderString());
      return responseProperty;
 }
开发者ID:kalkie,项目名称:DigestAuthenticationUsingWCF,代码行数:7,代码来源:ResponseMessageFactory.cs

示例13: BeforeSendReply

 public void BeforeSendReply(ref Message reply, object correlationState)
 {
     var state = correlationState as CorsState;
     if (state != null)
     {
         if (state.Message != null)
         {
             reply = state.Message;
         }
         HttpResponseMessageProperty responseProperty = null;
         if (reply.Properties.ContainsKey(HttpResponseMessageProperty.Name))
         {
             responseProperty = reply.Properties[HttpResponseMessageProperty.Name] as HttpResponseMessageProperty;
         }
         if (responseProperty == null)
         {
             responseProperty = new HttpResponseMessageProperty();
             reply.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
         }
         //Acao should be added for all cors responses
         responseProperty.Headers.Set("Access-Control-Allow-Origin", _behavior.AllowOrigin);
         if (state.Message != null)
         {
             //the following headers should only be added for OPTIONS requests
             responseProperty.Headers.Set("Access-Control-Allow-Methods", _behavior.AllowMethods);
             responseProperty.Headers.Set("Access-Control-Allow-Headers", _behavior.AllowHeaders);
         }
     }
 }
开发者ID:nescalante,项目名称:taxbillerservice,代码行数:29,代码来源:CorsDispatchMessageInspector.cs

示例14: ProvideFault

        public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
//            var newEx = new FaultException(string.Format("WCF接口出错 {0}", error.TargetSite.Name));
//            var newEx = new FaultException(error.Message);
//            MessageFault msgFault = newEx.CreateMessageFault();
//            fault = Message.CreateMessage(version, msgFault, newEx.Action);

            string errMsg = new JavaScriptSerializer().Serialize(new Fault(error.Message, "测试"));

            fault = Message.CreateMessage(version, "",errMsg, new DataContractJsonSerializer(typeof (string)));

            // tell WCF to use JSON encoding rather than default XML  
            WebBodyFormatMessageProperty wbf = new WebBodyFormatMessageProperty(WebContentFormat.Json);

            // Add the formatter to the fault  
            fault.Properties.Add(WebBodyFormatMessageProperty.Name, wbf);

            //Modify response  
            HttpResponseMessageProperty rmp = new HttpResponseMessageProperty();

            // return custom error code, 500.  
            rmp.StatusCode = System.Net.HttpStatusCode.InternalServerError;
            rmp.StatusDescription = "InternalServerError";

            //Mark the jsonerror and json content  
            rmp.Headers[HttpResponseHeader.ContentType] = "application/json";
            rmp.Headers[HttpResponseHeader.ContentEncoding] = "utf-8";
            rmp.Headers["jsonerror"] = "true";

            //Add to msg  
            fault.Properties.Add(HttpResponseMessageProperty.Name, rmp); 
        }
开发者ID:linyuxiangfly,项目名称:EasyJob_MVC_REST,代码行数:32,代码来源:GlobalExceptionHandler.cs

示例15: CreateResponseProperty

 private HttpResponseMessageProperty CreateResponseProperty()
 {
     var responseProperty = new HttpResponseMessageProperty();
      responseProperty.StatusCode = HttpStatusCode.Unauthorized;
      responseProperty.Headers.Add(BasicAuthenticationHeaderName, string.Format(CultureInfo.InvariantCulture, "Basic realm=\"{0}\"", realm));
      return responseProperty;
 }
开发者ID:kalkie,项目名称:BasicAuthenticationUsingWCFRest,代码行数:7,代码来源:ResponseMessageFactory.cs


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