本文整理汇总了C#中Message.ToHttpRequestMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Message.ToHttpRequestMessage方法的具体用法?C# Message.ToHttpRequestMessage怎么用?C# Message.ToHttpRequestMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.ToHttpRequestMessage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AfterReceiveRequest
public object AfterReceiveRequest(ref Message request,
IClientChannel channel,
InstanceContext instanceContext)
{
request = TraceHttpRequestMessage(request.ToHttpRequestMessage());
return null;
}
示例2: ValidateRequest
public HttpRequestMessage ValidateRequest(Message request)
{
Assert.IsNotNull(request);
var httpRequest = request.ToHttpRequestMessage();
Assert.IsNotNull(httpRequest);
return httpRequest;
}
示例3: ArgumentNullException
string IDispatchOperationSelector.SelectOperation(ref Message message)
{
if (message == null)
{
throw new ArgumentNullException("message");
}
HttpRequestMessage requestMessage = message.ToHttpRequestMessage();
return this.SelectOperation(requestMessage);
}
示例4: InvalidOperationException
/// <summary>
/// Called after an inbound message has been received but before the message
/// is dispatched to the intended operation.
/// </summary>
/// <param name="request">The request message.</param>
/// <param name="channel">The incoming channel.</param>
/// <param name="instanceContext">The current service instance.</param>
/// <returns>The object used to correlate state. This object is passed back
/// in the <see cref="BeforeSendReply(ref Message, Object)"/> method.</returns>
object IDispatchMessageInspector.AfterReceiveRequest(
ref Message request,
IClientChannel channel,
InstanceContext instanceContext)
{
if (request == null)
{
throw Fx.Exception.ArgumentNull("request");
}
HttpRequestMessage httpRequest = request.ToHttpRequestMessage();
if (httpRequest == null)
{
throw Fx.Exception.AsError(
new InvalidOperationException(
SR.HttpMessageInspectorNullMessage(this.GetType().Name, typeof(HttpRequestMessage).Name, "AfterReceiveRequest")));
}
return this.AfterReceiveRequest(httpRequest);
}
示例5: BeforeSendRequest
public object BeforeSendRequest(ref Message request,
IClientChannel channel)
{
request = TraceHttpRequestMessage(request.ToHttpRequestMessage());
return null;
}
示例6: ConfigureRequestMessage
private static Message ConfigureRequestMessage(Message message)
{
if (message == null)
{
return null;
}
HttpRequestMessageProperty requestProperty;
if (!message.Properties.TryGetValue(HttpRequestMessageProperty.Name, out requestProperty))
{
throw Error.InvalidOperation(
SRResources.RequestMissingHttpRequestMessageProperty,
HttpRequestMessageProperty.Name,
typeof(HttpRequestMessageProperty).Name);
}
Uri uri = message.Headers.To;
if (uri == null)
{
throw Error.InvalidOperation(SRResources.RequestMissingToHeader);
}
HttpRequestMessage httpRequestMessage = message.ToHttpRequestMessage();
if (httpRequestMessage == null)
{
if (!message.IsEmpty)
{
throw Error.InvalidOperation(SRResources.NonHttpMessageMustBeEmpty, HttpMessageExtensions.ToHttpRequestMessageMethodName, typeof(HttpMessage).Name);
}
httpRequestMessage = new HttpRequestMessage();
Message oldMessage = message;
message = httpRequestMessage.ToMessage();
message.Properties.CopyProperties(oldMessage.Properties);
oldMessage.Close();
}
else
{
// Clear headers but not properties.
message.Headers.Clear();
}
// Copy message properties to HttpRequestMessage. While it does have the
// risk of allowing properties to get out of sync they in virtually all cases are
// read-only so the risk is low. The downside to not doing it is that it isn't
// possible to access anything from HttpRequestMessage (or OperationContent.Current)
// which is worse.
foreach (KeyValuePair<string, object> kv in message.Properties)
{
httpRequestMessage.Properties.Add(kv.Key, kv.Value);
}
if (httpRequestMessage.Content == null)
{
httpRequestMessage.Content = new ByteArrayContent(new byte[0]);
}
else
{
httpRequestMessage.Content.Headers.Clear();
}
message.Headers.To = uri;
httpRequestMessage.RequestUri = uri;
httpRequestMessage.Method = HttpMethodHelper.GetHttpMethod(requestProperty.Method);
WebHeaderCollection headers = requestProperty.Headers;
foreach (var headerName in headers.AllKeys)
{
string headerValue = headers[headerName];
if (!httpRequestMessage.Headers.TryAddWithoutValidation(headerName, headerValue))
{
httpRequestMessage.Content.Headers.TryAddWithoutValidation(headerName, headerValue);
}
}
return message;
}
示例7: ConfigureRequestMessage
private static Message ConfigureRequestMessage(Message message)
{
if (message == null)
{
return null;
}
HttpRequestMessageProperty requestProperty = message.GetHttpRequestMessageProperty();
if (requestProperty == null)
{
throw Fx.Exception.AsError(
new InvalidOperationException(
SR.RequestMissingHttpRequestMessageProperty(
HttpRequestMessageProperty.Name,
typeof(HttpRequestMessageProperty).FullName)));
}
Uri uri = message.Headers.To;
if (uri == null)
{
throw Fx.Exception.AsError(
new InvalidOperationException(SR.RequestMissingToHeader));
}
// We also need to copy the hosted context so that HttpContext.Current
// will be set up correctly by the MessageRpc.ApplyHostingIntegrationContext()
object hostingProperty = AspNetEnvironment.Current.GetHostingProperty(message);
HttpRequestMessage httpRequestMessage = message.ToHttpRequestMessage();
if (httpRequestMessage == null)
{
if (!message.IsEmpty)
{
throw Fx.Exception.AsError(
new InvalidOperationException(
SR.NonHttpMessageMustBeEmpty(
HttpMessageExtensionMethods.ToHttpRequestMessageMethodName,
HttpMessage.MessageTypeFullName)));
}
httpRequestMessage = new HttpRequestMessage();
message.Close();
message = httpRequestMessage.ToMessage();
}
else
{
message.Headers.Clear();
message.Properties.Clear();
}
if (hostingProperty != null)
{
message.Properties.Add(AspNetEnvironment.HostingMessagePropertyName, hostingProperty);
}
if (httpRequestMessage.Content == null)
{
httpRequestMessage.Content = new ByteArrayContent(new byte[0]);
}
else
{
httpRequestMessage.Content.Headers.Clear();
}
message.Headers.To = uri;
httpRequestMessage.RequestUri = uri;
httpRequestMessage.Method = new HttpMethod(requestProperty.Method);
foreach (var headerName in requestProperty.Headers.AllKeys)
{
AddHeaderToHttpRequestMessageAndHandleExceptions(
httpRequestMessage,
headerName,
requestProperty.Headers[headerName]);
}
return message;
}