// makes sure that appropriate HTTP level headers are included in the received Message Exception ProcessHttpAddressing(Message message) { Exception result = null; AddProperties(message); // check if user is receiving WS-1 messages if (message.Version.Addressing == AddressingVersion.None) { bool actionAbsent = false; try { actionAbsent = (message.Headers.Action == null); } catch (XmlException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } catch (CommunicationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } if (!actionAbsent) { result = new ProtocolException(SR.GetString(SR.HttpAddressingNoneHeaderOnWire, XD.AddressingDictionary.Action.Value)); } bool toAbsent = false; try { toAbsent = (message.Headers.To == null); } catch (XmlException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } catch (CommunicationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } if (!toAbsent) { result = new ProtocolException(SR.GetString(SR.HttpAddressingNoneHeaderOnWire, XD.AddressingDictionary.To.Value)); } message.Headers.To = message.Properties.Via; } if (isRequest) { string action = null; if (message.Version.Envelope == EnvelopeVersion.Soap11) { action = SoapActionHeader; } else if (message.Version.Envelope == EnvelopeVersion.Soap12 && !String.IsNullOrEmpty(ContentType)) { ContentType parsedContentType = new ContentType(ContentType); if (parsedContentType.MediaType == multipartRelatedMediaType && parsedContentType.Parameters.ContainsKey(startInfoHeaderParam)) { // fix to grab action from start-info as stated in RFC2387 action = new ContentType(parsedContentType.Parameters[startInfoHeaderParam]).Parameters["action"]; } if (action == null) { // only if we can't find an action inside start-info action = parsedContentType.Parameters["action"]; } } if (action != null) { action = UrlUtility.UrlDecode(action, Encoding.UTF8); if (action.Length >= 2 && action[0] == '"' && action[action.Length - 1] == '"') { action = action.Substring(1, action.Length - 2); } if (message.Version.Addressing == AddressingVersion.None) { message.Headers.Action = action; } try { if (action.Length > 0 && string.Compare(message.Headers.Action, action, StringComparison.Ordinal) != 0) { result = new ActionMismatchAddressingException(SR.GetString(SR.HttpSoapActionMismatchFault, message.Headers.Action, action), message.Headers.Action, action); } } catch (XmlException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } catch (CommunicationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } } } ApplyChannelBinding(message); if (DiagnosticUtility.ShouldUseActivity) { TraceUtility.TransferFromTransport(message); } if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.MessageReceived, SR.GetString(SR.TraceCodeMessageReceived), MessageTransmitTraceRecord.CreateReceiveTraceRecord(message), this, null, message); } // MessageLogger doesn't log AddressingVersion.None in the encoder since we want to make sure we log // as much of the message as possible. Here we log after stamping the addressing information if (MessageLogger.LoggingEnabled && message.Version.Addressing == AddressingVersion.None) { MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive | MessageLoggingSource.LastChance); } return result; }
internal static ProtocolException CreateHttpProtocolException(string message, HttpStatusCode statusCode, string statusDescription, Exception innerException) { ProtocolException exception = new ProtocolException(message, innerException); exception.Data.Add(HttpChannelUtilities.HttpStatusCodeExceptionKey, statusCode); if (statusDescription != null && statusDescription.Length > 0) { exception.Data.Add(HttpChannelUtilities.HttpStatusDescriptionExceptionKey, statusDescription); } return exception; }
void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached) { lock (ThisLock) { if (isDisposed) return; this.connectionReaders.Remove(modeReader); } bool closeReader = true; try { FramingMode framingMode; try { framingMode = modeReader.GetConnectionMode(); } catch (CommunicationException exception) { TraceEventType eventType = modeReader.Connection.ExceptionEventType; DiagnosticUtility.TraceHandledException(exception, eventType); return; } catch (TimeoutException exception) { if (!isCached) { exception = new TimeoutException(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout), exception); System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception); } if (TD.ChannelInitializationTimeoutIsEnabled()) { TD.ChannelInitializationTimeout(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout)); } TraceEventType eventType = modeReader.Connection.ExceptionEventType; DiagnosticUtility.TraceHandledException(exception, eventType); return; } switch (framingMode) { case FramingMode.Duplex: OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout()); break; case FramingMode.Singleton: OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout()); break; default: { Exception inner = new InvalidDataException(SR.GetString( SR.FramingModeNotSupported, framingMode)); Exception exception = new ProtocolException(inner.Message, inner); FramingEncodingString.AddFaultString(exception, FramingEncodingString.UnsupportedModeFault); System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception); return; } } closeReader = false; } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (!ExceptionHandler.HandleTransportExceptionHelper(e)) { throw; } // containment -- the reader is aborted, no need for additional containment } finally { if (closeReader) { modeReader.Dispose(); } } }