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


C# IRequest.SetItem方法代码示例

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


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

示例1: ExtractTokenFromRequestFilter

        public void ExtractTokenFromRequestFilter(IRequest req, IResponse res, object requestDto)
        {
            var auth = req.GetHeader("Authorization");

            if (!String.IsNullOrEmpty(auth) && auth.StartsWith(bearerPrefix) && auth.Length > bearerPrefix.Length)
            {
                SecurityToken loginToken = null;

                try
                {
                    loginToken = tokenManager.ToSecurityToken(auth.Substring(bearerPrefix.Length), "login");
                }
                catch (Exception)
                {
                    throw HttpError.Unauthorized("Login token is invalid");
                }

                // Validate the token is not expired
                if (DateTime.UtcNow > loginToken.ExpiresAtUtc)
                    throw HttpError.Unauthorized("Login token has expired");

                req.SetItem("LoginToken", loginToken);
            }
        }
开发者ID:jlyonsmith,项目名称:ToolBelt,代码行数:24,代码来源:LoginTokenFeature.cs

示例2: ExecuteMessage

        protected Message ExecuteMessage(Message message, RequestAttributes requestAttributes, IRequest httpReq, IResponse httpRes)
        {
            var soapFeature = requestAttributes.ToSoapFeature();
            HostContext.AppHost.AssertFeatures(soapFeature);

            if (httpReq == null)
                httpReq = HostContext.GetCurrentRequest();

            if (httpRes == null && httpReq != null)
                httpRes = httpReq.Response;

            if (httpReq == null)
                throw new ArgumentNullException("httpReq");

            if (httpRes == null)
                throw new ArgumentNullException("httpRes");

            httpReq.UseBufferedStream = true;
            var requestMsg = message ?? GetRequestMessageFromStream(httpReq.InputStream);

            var soapAction = httpReq.GetHeader(HttpHeaders.SOAPAction)
                ?? GetAction(requestMsg);

            if (soapAction != null)
            {
                httpReq.OperationName = soapAction.Trim('"');
            }

            if (HostContext.ApplyPreRequestFilters(httpReq, httpRes))
                return PrepareEmptyResponse(message, httpReq);

            string requestXml = GetRequestXml(requestMsg);
            var requestType = GetRequestType(requestMsg, requestXml);
            httpReq.OperationName = requestType.GetOperationName();
            if (!HostContext.Metadata.CanAccess(requestAttributes, soapFeature.ToFormat(), requestType.GetOperationName()))
                throw HostContext.UnauthorizedAccess(requestAttributes);

            try
            {
                var useXmlSerializerRequest = requestType.HasAttribute<XmlSerializerFormatAttribute>();

                var request = useXmlSerializerRequest
                    ? XmlSerializableSerializer.Instance.DeserializeFromString(requestXml, requestType)
                    : Serialization.DataContractSerializer.Instance.DeserializeFromString(requestXml, requestType);

                httpReq.Dto = request;

                var requiresSoapMessage = request as IRequiresSoapMessage;
                if (requiresSoapMessage != null)
                {
                    requiresSoapMessage.Message = requestMsg;
                }

                httpReq.SetItem("SoapMessage", requestMsg);

                httpRes.ContentType = GetSoapContentType(httpReq.ContentType);

                var hasRequestFilters = HostContext.GlobalRequestFilters.Count > 0
                    || FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any();

                if (hasRequestFilters && HostContext.ApplyRequestFilters(httpReq, httpRes, request))
                    return EmptyResponse(requestMsg, requestType);

                httpReq.RequestAttributes |= requestAttributes;
                var response = ExecuteService(request, httpReq);

                var taskResponse = response as Task;
                if (taskResponse != null)
                {
                    taskResponse.Wait();
                    response = TypeAccessor.Create(taskResponse.GetType())[taskResponse, "Result"];
                }

                var hasResponseFilters = HostContext.GlobalResponseFilters.Count > 0
                   || FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any();

                if (hasResponseFilters && HostContext.ApplyResponseFilters(httpReq, httpRes, response))
                    return EmptyResponse(requestMsg, requestType);

                var httpResult = response as IHttpResult;
                if (httpResult != null)
                    response = httpResult.Response;

                var noMsgAction = requestMsg.Headers.Action == null;
                var responseMsg = CreateResponseMessage(response, requestMsg.Version, requestType, noMsgAction);

                if (httpResult != null)
                {
                    SetErrorStatusIfAny(httpReq.Response, responseMsg, httpResult.Status);
                }

                return responseMsg;
            }
            catch (Exception ex)
            {
                throw new SerializationException("3) Error trying to deserialize requestType: "
                    + requestType
                    + ", xml body: " + requestXml, ex);
            }
        }
开发者ID:softwx,项目名称:ServiceStack,代码行数:100,代码来源:SoapHandler.cs

示例3: Before_each_spec

 protected override void Before_each_spec()
 {
     _presenter = Create<ExampleWidgetPresenter>();
      _request = new Request();
      _request.SetItem("data", "test");
 }
开发者ID:bsimser,项目名称:xeva,代码行数:6,代码来源:PresenterSpecs.cs


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