本文整理汇总了C#中System.ServiceModel.Channels.HttpResponseMessageProperty类的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessageProperty类的具体用法?C# HttpResponseMessageProperty怎么用?C# HttpResponseMessageProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponseMessageProperty类属于System.ServiceModel.Channels命名空间,在下文中一共展示了HttpResponseMessageProperty类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: BeforeSendReply
public void BeforeSendReply(ref Message reply, object correlationState)
{
HttpResponseMessageProperty property = null;
if (reply == null)
{
// This will usually be for a preflight response
reply = Message.CreateMessage(MessageVersion.None, null);
property = new HttpResponseMessageProperty();
reply.Properties[HttpResponseMessageProperty.Name] = property;
property.StatusCode = HttpStatusCode.OK;
}
else
{
property = reply.Properties[HttpResponseMessageProperty.Name] as HttpResponseMessageProperty;
}
PreflightDetected preflightRequest = OperationContext.Current.Extensions.Find<PreflightDetected>();
if (preflightRequest != null)
{
// Add allow HTTP headers to respond to the preflight request
if (preflightRequest.RequestedHeaders == string.Empty)
property.Headers.Add("Access-Control-Allow-Headers", "Accept");
else
property.Headers.Add("Access-Control-Allow-Headers", preflightRequest.RequestedHeaders + ", Accept");
property.Headers.Add("Access-Control-Allow-Methods", "*");
}
// Add allow-origin header to each response message, because client expects it
if (property != null) property.Headers.Add("Access-Control-Allow-Origin", "*");
}
开发者ID:ZyshchykMaksim,项目名称:WCF.REST,代码行数:33,代码来源:CorsMessageInspector.cs
示例17: SetHttpResponseProperty
public static void SetHttpResponseProperty(this Message message, HttpResponseMessageProperty httpResponse)
{
if (message.Properties.ContainsKey(HttpResponseMessageProperty.Name))
message.Properties.Remove(HttpResponseMessageProperty.Name);
message.Properties.Add(HttpResponseMessageProperty.Name, httpResponse);
}
开发者ID:huoxudong125,项目名称:WcfRestContrib,代码行数:7,代码来源:MessageExtensions.cs
示例18: HandlePreflight
Message HandlePreflight(Message input)
{
HttpRequestMessageProperty httpRequest = (HttpRequestMessageProperty)input.Properties[HttpRequestMessageProperty.Name];
string origin = httpRequest.Headers[CorsConstants.Origin];
string requestMethod = httpRequest.Headers[CorsConstants.AccessControlRequestMethod];
string requestHeaders = httpRequest.Headers[CorsConstants.AccessControlRequestHeaders];
Message reply = Message.CreateMessage(MessageVersion.None, replyAction);
HttpResponseMessageProperty httpResponse = new HttpResponseMessageProperty();
reply.Properties.Add(HttpResponseMessageProperty.Name, httpResponse);
httpResponse.SuppressEntityBody = true;
httpResponse.StatusCode = HttpStatusCode.OK;
if (origin != null)
{
httpResponse.Headers.Add(CorsConstants.AccessControlAllowOrigin, origin);
}
if (requestMethod != null && this.allowedHttpMethods.Contains(requestMethod))
{
httpResponse.Headers.Add(CorsConstants.AccessControlAllowMethods, string.Join(",", this.allowedHttpMethods));
}
if (requestHeaders != null)
{
httpResponse.Headers.Add(CorsConstants.AccessControlAllowHeaders, requestHeaders);
}
return reply;
}
开发者ID:GusLab,项目名称:WCFSamples,代码行数:30,代码来源:PreflightOperationInvoker.cs
示例19: ProvideFault
/// <summary>
/// Provides the fault.
/// </summary>
/// <param name="error">The error.</param>
/// <param name="version">The version.</param>
/// <param name="fault">The fault.</param>
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (fault != null)
{
HttpResponseMessageProperty properties = new HttpResponseMessageProperty();
properties.StatusCode = HttpStatusCode.InternalServerError;
fault.Properties.Add(HttpResponseMessageProperty.Name, properties);
}
}
开发者ID:Dilli,项目名称:RedPill,代码行数:15,代码来源:HttpErrorHandler.cs
示例20: ProcessRequest
public Message ProcessRequest(Message request)
{
Console.WriteLine("Server received a request from client");
HttpResponseMessageProperty httpResponseProperty = new HttpResponseMessageProperty();
httpResponseProperty.Headers.Add("Content-Type", "application/octet-stream");
request.Properties.Add(HttpResponseMessageProperty.Name, httpResponseProperty);
Console.WriteLine("Server is sending back the same image to client");
return request;
}
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:9,代码来源:FileService.cs
注:本文中的System.ServiceModel.Channels.HttpResponseMessageProperty类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论