本文整理汇总了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);
}
}
示例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);
}
}
示例3: Before_each_spec
protected override void Before_each_spec()
{
_presenter = Create<ExampleWidgetPresenter>();
_request = new Request();
_request.SetItem("data", "test");
}