本文整理汇总了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;
}
}
示例2: CreateAndSendInvalidAuthenticationRequest
private RequestContext CreateAndSendInvalidAuthenticationRequest(RequestContext requestContext)
{
using (Message responseMessage = authenticationManager.CreateInvalidAuthenticationRequest(requestContext.RequestMessage))
{
requestContext.Reply(responseMessage);
requestContext = null;
return requestContext;
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
}