public ClientWebSocketTransportDuplexSessionChannel(HttpChannelFactory<IDuplexSessionChannel> channelFactory, ClientWebSocketFactory connectionFactory, EndpointAddress remoteAddresss, Uri via, ConnectionBufferPool bufferPool) : base(channelFactory, remoteAddresss, via, bufferPool) { Contract.Assert(channelFactory != null, "connection factory must be set"); _channelFactory = channelFactory; _connectionFactory = connectionFactory; }
public static void AddReplySecurityProperty(HttpChannelFactory factory, HttpWebRequest webRequest, HttpWebResponse webResponse, Message replyMessage) { SecurityMessageProperty property = factory.CreateReplySecurityProperty(webRequest, webResponse); if (property != null) { replyMessage.Properties.Security = property; } }
public WebSocketTransportDuplexSessionChannel(HttpChannelFactory<IDuplexSessionChannel> channelFactory, EndpointAddress remoteAddresss, Uri via) : base(channelFactory, channelFactory, EndpointAddress.AnonymousAddress, channelFactory.MessageVersion.Addressing.AnonymousUri, remoteAddresss, via) { Fx.Assert(channelFactory.WebSocketSettings != null, "channelFactory.WebSocketTransportSettings should not be null."); _webSocketSettings = channelFactory.WebSocketSettings; _transferMode = channelFactory.TransferMode; _maxBufferSize = channelFactory.MaxBufferSize; _transportFactorySettings = channelFactory; }
public HttpResponseMessageHelper(HttpResponseMessage httpResponseMessage, HttpChannelFactory<IRequestChannel> factory) { Contract.Assert(httpResponseMessage != null); Contract.Assert(httpResponseMessage.RequestMessage != null); Contract.Assert(factory != null); _httpResponseMessage = httpResponseMessage; _httpRequestMessage = httpResponseMessage.RequestMessage; _factory = factory; _encoder = factory.MessageEncoderFactory.Encoder; }
// only valid response codes are 500 (if it's a fault) or 200 (iff it's a response message) public static HttpInput ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory<IRequestChannel> factory, WebException responseException, ChannelBinding channelBinding) { ValidateAuthentication(request, response, responseException, factory); HttpInput httpInput = null; // We will close the HttpWebResponse if we got an error code betwen 200 and 300 and // 1) an exception was thrown out or // 2) it's an empty message and we are using SOAP. // For responses with status code above 300, System.Net will close the underlying connection so we don't need to worry about that. if ((200 <= (int)response.StatusCode && (int)response.StatusCode < 300) || response.StatusCode == HttpStatusCode.InternalServerError) { if (response.StatusCode == HttpStatusCode.InternalServerError && string.Compare(response.StatusDescription, HttpChannelUtilities.StatusDescriptionStrings.HttpStatusServiceActivationException, StringComparison.OrdinalIgnoreCase) == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ServiceActivationException(SR.GetString(SR.Hosting_ServiceActivationFailed, request.RequestUri))); } else { bool throwing = true; try { if (string.IsNullOrEmpty(response.ContentType)) { if (!ValidateEmptyContent(response)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(TraceResponseException( new ProtocolException( SR.GetString(SR.HttpContentTypeHeaderRequired), responseException))); } } else if (response.ContentLength != 0) { MessageEncoder encoder = factory.MessageEncoderFactory.Encoder; if (!encoder.IsContentTypeSupported(response.ContentType)) { int bytesRead; String responseExcerpt = GetResponseStreamString(response, out bytesRead); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(TraceResponseException( new ProtocolException( SR.GetString( SR.ResponseContentTypeMismatch, response.ContentType, encoder.ContentType, bytesRead, responseExcerpt), responseException))); } httpInput = HttpInput.CreateHttpInput(response, factory, channelBinding); httpInput.WebException = responseException; } throwing = false; } finally { if (throwing) { response.Close(); } } } if (httpInput == null) { if (factory.MessageEncoderFactory.MessageVersion == MessageVersion.None) { httpInput = HttpInput.CreateHttpInput(response, factory, channelBinding); httpInput.WebException = responseException; } else { // In this case, we got a response with // 1) status code between 200 and 300 // 2) Non-empty Content Type string // 3) Zero content length // Since we are trying to use SOAP here, the message seems to be malicious and we should // just close the response directly. response.Close(); } } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedResponseException(responseException, response)); } return httpInput; }
static void ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory<IRequestChannel> factory) { if (response.StatusCode == HttpStatusCode.Unauthorized) { string message = SR.GetString(SR.HttpAuthorizationFailed, factory.AuthenticationScheme, response.Headers[HttpResponseHeader.WwwAuthenticate]); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( TraceResponseException(new MessageSecurityException(message, responseException))); } if (response.StatusCode == HttpStatusCode.Forbidden) { string message = SR.GetString(SR.HttpAuthorizationForbidden, factory.AuthenticationScheme); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( TraceResponseException(new MessageSecurityException(message, responseException))); } if ((request.AuthenticationLevel == AuthenticationLevel.MutualAuthRequired) && !response.IsMutuallyAuthenticated) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( TraceResponseException(new SecurityNegotiationException(SR.GetString(SR.HttpMutualAuthNotSatisfied), responseException))); } }
public ClientWebSocketTransportDuplexSessionChannel(HttpChannelFactory<IDuplexSessionChannel> channelFactory, ClientWebSocketFactory connectionFactory, EndpointAddress remoteAddresss, Uri via, ConnectionBufferPool bufferPool) : base(channelFactory, remoteAddresss, via, bufferPool) { this.channelFactory = channelFactory; this.connectionFactory = connectionFactory; }
internal static HttpContent Create(HttpChannelFactory<IRequestChannel> factory, Message request, TimeoutHelper _timeoutHelper) { if (TransferModeHelper.IsRequestStreamed(factory.TransferMode)) { return new StreamedMessageContent(request, factory.MessageEncoderFactory.Encoder); } else { return new BufferedMessageContent(request, factory.MessageEncoderFactory.Encoder, factory.BufferManager); } }
// Constructor public HttpRequestChannel (HttpChannelFactory<IRequestChannel> factory, EndpointAddress address, Uri via) : base (factory, address, via) { this.source = factory; }
public static HttpInput ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) { ValidateAuthentication(request, response, responseException, factory); HttpInput input = null; if (((HttpStatusCode.OK > response.StatusCode) || (response.StatusCode >= HttpStatusCode.MultipleChoices)) && (response.StatusCode != HttpStatusCode.InternalServerError)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedResponseException(responseException, response)); } if ((response.StatusCode == HttpStatusCode.InternalServerError) && (string.Compare(response.StatusDescription, "System.ServiceModel.ServiceActivationException", StringComparison.OrdinalIgnoreCase) == 0)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ServiceActivationException(System.ServiceModel.SR.GetString("Hosting_ServiceActivationFailed", new object[] { request.RequestUri }))); } if (string.IsNullOrEmpty(response.ContentType)) { if (!ValidateEmptyContent(response)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(TraceResponseException(new ProtocolException(System.ServiceModel.SR.GetString("HttpContentTypeHeaderRequired"), responseException))); } } else if (response.ContentLength != 0L) { MessageEncoder encoder = factory.MessageEncoderFactory.Encoder; if (!encoder.IsContentTypeSupported(response.ContentType)) { int num; string responseStreamString = GetResponseStreamString(response, out num); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(TraceResponseException(new ProtocolException(System.ServiceModel.SR.GetString("ResponseContentTypeMismatch", new object[] { response.ContentType, encoder.ContentType, num, responseStreamString }), responseException))); } input = HttpInput.CreateHttpInput(response, factory, channelBinding); input.WebException = responseException; } if ((input == null) && (factory.MessageEncoderFactory.MessageVersion == MessageVersion.None)) { input = HttpInput.CreateHttpInput(response, factory, channelBinding); input.WebException = responseException; } return input; }
private static void ValidateAuthentication(HttpRequestMessage request, HttpResponseMessage response, HttpRequestException responseException, HttpChannelFactory<IRequestChannel> factory) { if (response.StatusCode == HttpStatusCode.Unauthorized) { string message = SR.Format(SR.HttpAuthorizationFailed, factory.AuthenticationScheme, response.Headers.WwwAuthenticate.ToString()); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( TraceResponseException(new MessageSecurityException(message, responseException))); } if (response.StatusCode == HttpStatusCode.Forbidden) { string message = SR.Format(SR.HttpAuthorizationForbidden, factory.AuthenticationScheme); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( TraceResponseException(new MessageSecurityException(message, responseException))); } }