Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Dispatcher / HttpUnhandledOperationInvoker.cs / 1305376 / HttpUnhandledOperationInvoker.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- #pragma warning disable 1634, 1691 namespace System.ServiceModel.Dispatcher { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Net; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Diagnostics; using System.ServiceModel.Web; using System.ServiceModel.Syndication; using System.Xml.Linq; using System.ServiceModel.Description; internal class HttpUnhandledOperationInvoker : IOperationInvoker { const string HtmlContentType = "text/html; charset=UTF-8"; public bool IsSynchronous { get { return true; } } public object[] AllocateInputs() { return new object[1]; } public Uri HelpUri { get; set; } [SuppressMessage("Reliability", "Reliability104:CaughtAndHandledExceptionsRule", Justification = "The exception is thrown for tracing purposes")] public object Invoke(object instance, object[] inputs, out object[] outputs) { Message message = inputs[0] as Message; outputs = null; #pragma warning disable 56506 // [....], message.Properties is never null if (message == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR2.GetString(SR2.HttpUnhandledOperationInvokerCalledWithoutMessage))); } // We might be here because we desire a redirect... Uri newLocation = null; Uri to = message.Headers.To; if (message.Properties.ContainsKey(WebHttpDispatchOperationSelector.RedirectPropertyName)) { newLocation = message.Properties[WebHttpDispatchOperationSelector.RedirectPropertyName] as Uri; } if (newLocation != null && to != null) { // ...redirect Message redirectResult = WebOperationContext.Current.CreateStreamResponse(s => HelpHtmlBuilder.CreateTransferRedirectPage(to.AbsoluteUri, newLocation.AbsoluteUri).Save(s, SaveOptions.OmitDuplicateNamespaces), Atom10Constants.HtmlMediaType); WebOperationContext.Current.OutgoingResponse.Location = newLocation.AbsoluteUri; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.TemporaryRedirect; WebOperationContext.Current.OutgoingResponse.ContentType = HtmlContentType; // Note that no exception is thrown along this path, even if the debugger is attached if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.WebRequestRedirect, SR2.GetString(SR2.TraceCodeWebRequestRedirect, to, newLocation)); } return redirectResult; } // otherwise we are here to issue either a 404 or a 405 bool uriMatched = false; if (message.Properties.ContainsKey(WebHttpDispatchOperationSelector.HttpOperationSelectorUriMatchedPropertyName)) { uriMatched = (bool) message.Properties[WebHttpDispatchOperationSelector.HttpOperationSelectorUriMatchedPropertyName]; } #pragma warning enable 56506 Message result = null; Uri helpUri = this.HelpUri != null ? UriTemplate.RewriteUri(this.HelpUri, WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.Host]) : null; if (uriMatched) { WebHttpDispatchOperationSelectorData allowedMethodsData = null; if (message.Properties.TryGetValue(WebHttpDispatchOperationSelector.HttpOperationSelectorDataPropertyName, out allowedMethodsData)) { WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.Allow] = allowedMethodsData.AllowHeader; } result = WebOperationContext.Current.CreateStreamResponse(s => HelpHtmlBuilder.CreateMethodNotAllowedPage(helpUri).Save(s, SaveOptions.OmitDuplicateNamespaces), Atom10Constants.HtmlMediaType); } else { result = WebOperationContext.Current.CreateStreamResponse(s => HelpHtmlBuilder.CreateEndpointNotFound(helpUri).Save(s, SaveOptions.OmitDuplicateNamespaces), Atom10Constants.HtmlMediaType); } WebOperationContext.Current.OutgoingResponse.StatusCode = uriMatched ? HttpStatusCode.MethodNotAllowed : HttpStatusCode.NotFound; WebOperationContext.Current.OutgoingResponse.ContentType = HtmlContentType; try { if (!uriMatched) { if (Debugger.IsAttached) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.WebRequestDidNotMatchOperation, OperationContext.Current.IncomingMessageHeaders.To))); } else { if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(new InvalidOperationException(SR2.GetString(SR2.WebRequestDidNotMatchOperation, OperationContext.Current.IncomingMessageHeaders.To)), TraceEventType.Warning); } } } else { if (Debugger.IsAttached) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.WebRequestDidNotMatchMethod, WebOperationContext.Current.IncomingRequest.Method, OperationContext.Current.IncomingMessageHeaders.To))); } else { if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(new InvalidOperationException(SR2.GetString(SR2.WebRequestDidNotMatchMethod, WebOperationContext.Current.IncomingRequest.Method, OperationContext.Current.IncomingMessageHeaders.To)), TraceEventType.Warning); } } } } catch (InvalidOperationException) { // catch the exception - its only used for tracing } return result; } public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EnumUnknown.cs
- BuildProviderCollection.cs
- SiteMapPath.cs
- ViewBox.cs
- GridViewSelectEventArgs.cs
- IWorkflowDebuggerService.cs
- SmiRecordBuffer.cs
- InvokeSchedule.cs
- DataGridViewRowHeaderCell.cs
- ReceiveMessageAndVerifySecurityAsyncResultBase.cs
- GeneralTransform3DGroup.cs
- ListSortDescription.cs
- WebPartEditorApplyVerb.cs
- Size.cs
- CompilationRelaxations.cs
- MobileListItem.cs
- SkewTransform.cs
- Vector3D.cs
- WinCategoryAttribute.cs
- TableCell.cs
- Ref.cs
- SerializationObjectManager.cs
- KeyTimeConverter.cs
- PropertyItem.cs
- ObjectViewEntityCollectionData.cs
- OneOfTypeConst.cs
- GridViewHeaderRowPresenter.cs
- SoapElementAttribute.cs
- MetadataImporter.cs
- ProjectionCamera.cs
- TrustLevel.cs
- PageParserFilter.cs
- SubMenuStyleCollection.cs
- DataRow.cs
- SelectedGridItemChangedEvent.cs
- HtmlSelect.cs
- BitmapInitialize.cs
- PageCatalogPart.cs
- MeasurementDCInfo.cs
- Binding.cs
- BaseConfigurationRecord.cs
- MatrixCamera.cs
- ObjectResult.cs
- DataControlFieldCell.cs
- StorageAssociationSetMapping.cs
- XmlTextReader.cs
- COM2ICategorizePropertiesHandler.cs
- PropertyToken.cs
- RangeValuePattern.cs
- WaitHandle.cs
- RightsManagementPermission.cs
- BinaryExpression.cs
- SwitchAttribute.cs
- EventManager.cs
- ResourcePermissionBaseEntry.cs
- RichTextBoxContextMenu.cs
- DeleteWorkflowOwnerCommand.cs
- DataRowView.cs
- CopyOnWriteList.cs
- Control.cs
- XmlUTF8TextReader.cs
- ChangeConflicts.cs
- OperationContextScope.cs
- AvTraceFormat.cs
- CacheForPrimitiveTypes.cs
- AuthenticationConfig.cs
- Pair.cs
- DiagnosticsConfigurationHandler.cs
- Transform3DCollection.cs
- ReflectionTypeLoadException.cs
- CodeArgumentReferenceExpression.cs
- FormViewPagerRow.cs
- TextElementEnumerator.cs
- NamespaceList.cs
- LineVisual.cs
- UTF7Encoding.cs
- EnumType.cs
- XmlnsCache.cs
- BinaryMethodMessage.cs
- TypedTableHandler.cs
- DivideByZeroException.cs
- DesignerAttribute.cs
- TdsParserHelperClasses.cs
- AccessDataSourceView.cs
- ConnectionOrientedTransportElement.cs
- SystemFonts.cs
- DebugView.cs
- FileDetails.cs
- PowerModeChangedEventArgs.cs
- EmptyElement.cs
- Pens.cs
- TdsParserHelperClasses.cs
- SqlClientWrapperSmiStream.cs
- RegexParser.cs
- OutputCacheProfileCollection.cs
- SimpleHandlerFactory.cs
- JsonServiceDocumentSerializer.cs
- Viewport2DVisual3D.cs
- ProviderConnectionPointCollection.cs
- PasswordTextNavigator.cs