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


C# Message.ToHttpRequestMessage方法代码示例

本文整理汇总了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;
 }
开发者ID:ogazitt,项目名称:product,代码行数:7,代码来源:MessageLoggingHelper.cs

示例2: ValidateRequest

 public HttpRequestMessage ValidateRequest(Message request)
 {
     Assert.IsNotNull(request);
     var httpRequest = request.ToHttpRequestMessage();
     Assert.IsNotNull(httpRequest);
     return httpRequest;
 }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:7,代码来源:TestServiceBase.cs

示例3: ArgumentNullException

        string IDispatchOperationSelector.SelectOperation(ref Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            HttpRequestMessage requestMessage = message.ToHttpRequestMessage();
            return this.SelectOperation(requestMessage);
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:10,代码来源:HttpOperationSelector.cs

示例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);
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:30,代码来源:HttpMessageInspector.cs

示例5: BeforeSendRequest

 public object BeforeSendRequest(ref Message request,
     IClientChannel channel)
 {
     request = TraceHttpRequestMessage(request.ToHttpRequestMessage());
     return null;
 }
开发者ID:ogazitt,项目名称:product,代码行数:6,代码来源:MessageLoggingHelper.cs

示例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;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:78,代码来源:HttpMessageEncodingRequestContext.cs

示例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;
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:78,代码来源:HttpMessageEncodingRequestContext.cs


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