Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Web / System / Web / Services / Protocols / RuntimeUtils.cs / 1305376 / RuntimeUtils.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Services.Protocols { using System.Web.Services; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using System; using System.Text; using System.IO; using System.ComponentModel; using System.Globalization; using System.Web.Services.Diagnostics; internal class RuntimeUtils { private RuntimeUtils() { } internal static XmlDeserializationEvents GetDeserializationEvents() { XmlDeserializationEvents events = new XmlDeserializationEvents(); events.OnUnknownElement = new XmlElementEventHandler(OnUnknownElement); events.OnUnknownAttribute = new XmlAttributeEventHandler(OnUnknownAttribute); return events; } static void OnUnknownAttribute(object sender, XmlAttributeEventArgs e) { if (e.Attr == null) return; // ignore attributes from known namepsaces if (IsKnownNamespace(e.Attr.NamespaceURI)) return; Tracing.OnUnknownAttribute(sender, e); if (e.ExpectedAttributes == null) throw new InvalidOperationException(Res.GetString(Res.WebUnknownAttribute, e.Attr.Name, e.Attr.Value)); else if (e.ExpectedAttributes.Length == 0) throw new InvalidOperationException(Res.GetString(Res.WebUnknownAttribute2, e.Attr.Name, e.Attr.Value)); else throw new InvalidOperationException(Res.GetString(Res.WebUnknownAttribute3, e.Attr.Name, e.Attr.Value, e.ExpectedAttributes)); } internal static string ElementString(XmlElement element) { StringWriter xml = new StringWriter(CultureInfo.InvariantCulture); xml.Write("<"); xml.Write(element.Name); if (element.NamespaceURI != null && element.NamespaceURI.Length > 0) { xml.Write(" xmlns"); if (element.Prefix != null && element.Prefix.Length > 0) { xml.Write(":"); xml.Write(element.Prefix); } xml.Write("='"); xml.Write(element.NamespaceURI); xml.Write("'"); } xml.Write(">.."); xml.Write(element.Name); xml.Write(">"); return xml.ToString(); } internal static void OnUnknownElement(object sender, XmlElementEventArgs e) { if (e.Element == null) return; string xml = RuntimeUtils.ElementString(e.Element); Tracing.OnUnknownElement(sender, e); if (e.ExpectedElements == null) throw new InvalidOperationException(Res.GetString(Res.WebUnknownElement, xml)); else if (e.ExpectedElements.Length == 0) throw new InvalidOperationException(Res.GetString(Res.WebUnknownElement1, xml)); else throw new InvalidOperationException(Res.GetString(Res.WebUnknownElement2, xml, e.ExpectedElements)); } internal static bool IsKnownNamespace(string ns) { if (ns == XmlSchema.InstanceNamespace) return true; if (ns == Soap.XmlNamespace) return true; if (ns == Soap.Encoding || ns == Soap.Namespace) return true; if (ns == Soap12.Namespace || ns == Soap12.Encoding || ns == Soap12.RpcNamespace) return true; return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Services.Protocols { using System.Web.Services; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using System; using System.Text; using System.IO; using System.ComponentModel; using System.Globalization; using System.Web.Services.Diagnostics; internal class RuntimeUtils { private RuntimeUtils() { } internal static XmlDeserializationEvents GetDeserializationEvents() { XmlDeserializationEvents events = new XmlDeserializationEvents(); events.OnUnknownElement = new XmlElementEventHandler(OnUnknownElement); events.OnUnknownAttribute = new XmlAttributeEventHandler(OnUnknownAttribute); return events; } static void OnUnknownAttribute(object sender, XmlAttributeEventArgs e) { if (e.Attr == null) return; // ignore attributes from known namepsaces if (IsKnownNamespace(e.Attr.NamespaceURI)) return; Tracing.OnUnknownAttribute(sender, e); if (e.ExpectedAttributes == null) throw new InvalidOperationException(Res.GetString(Res.WebUnknownAttribute, e.Attr.Name, e.Attr.Value)); else if (e.ExpectedAttributes.Length == 0) throw new InvalidOperationException(Res.GetString(Res.WebUnknownAttribute2, e.Attr.Name, e.Attr.Value)); else throw new InvalidOperationException(Res.GetString(Res.WebUnknownAttribute3, e.Attr.Name, e.Attr.Value, e.ExpectedAttributes)); } internal static string ElementString(XmlElement element) { StringWriter xml = new StringWriter(CultureInfo.InvariantCulture); xml.Write("<"); xml.Write(element.Name); if (element.NamespaceURI != null && element.NamespaceURI.Length > 0) { xml.Write(" xmlns"); if (element.Prefix != null && element.Prefix.Length > 0) { xml.Write(":"); xml.Write(element.Prefix); } xml.Write("='"); xml.Write(element.NamespaceURI); xml.Write("'"); } xml.Write(">.."); xml.Write(element.Name); xml.Write(">"); return xml.ToString(); } internal static void OnUnknownElement(object sender, XmlElementEventArgs e) { if (e.Element == null) return; string xml = RuntimeUtils.ElementString(e.Element); Tracing.OnUnknownElement(sender, e); if (e.ExpectedElements == null) throw new InvalidOperationException(Res.GetString(Res.WebUnknownElement, xml)); else if (e.ExpectedElements.Length == 0) throw new InvalidOperationException(Res.GetString(Res.WebUnknownElement1, xml)); else throw new InvalidOperationException(Res.GetString(Res.WebUnknownElement2, xml, e.ExpectedElements)); } internal static bool IsKnownNamespace(string ns) { if (ns == XmlSchema.InstanceNamespace) return true; if (ns == Soap.XmlNamespace) return true; if (ns == Soap.Encoding || ns == Soap.Namespace) return true; if (ns == Soap12.Namespace || ns == Soap12.Encoding || ns == Soap12.RpcNamespace) return true; return false; } } } // 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
- CryptoStream.cs
- CharAnimationUsingKeyFrames.cs
- CollectionBase.cs
- SurrogateDataContract.cs
- RestHandlerFactory.cs
- HtmlInputRadioButton.cs
- UInt16Converter.cs
- ChangeInterceptorAttribute.cs
- Lookup.cs
- SubclassTypeValidatorAttribute.cs
- DeobfuscatingStream.cs
- SettingsBase.cs
- SortedList.cs
- TranslateTransform3D.cs
- RequestCacheManager.cs
- TextPatternIdentifiers.cs
- DiagnosticsConfiguration.cs
- CommaDelimitedStringAttributeCollectionConverter.cs
- PropVariant.cs
- ReadOnlyTernaryTree.cs
- XmlTextEncoder.cs
- DataGridViewCellPaintingEventArgs.cs
- xdrvalidator.cs
- _NegoState.cs
- Metafile.cs
- HotSpotCollection.cs
- ObjectCacheSettings.cs
- ControlIdConverter.cs
- XPathDocumentIterator.cs
- RouteItem.cs
- FormViewRow.cs
- DeploymentExceptionMapper.cs
- TextTreeInsertUndoUnit.cs
- SByte.cs
- ParameterCollection.cs
- MatrixAnimationBase.cs
- DBPropSet.cs
- DataSourceCache.cs
- NativeMethods.cs
- CodeTypeMemberCollection.cs
- MulticastIPAddressInformationCollection.cs
- Polyline.cs
- MarkupCompilePass1.cs
- ParameterBuilder.cs
- TableRowsCollectionEditor.cs
- SrgsOneOf.cs
- XmlUrlResolver.cs
- DataBindingExpressionBuilder.cs
- DataServiceStreamProviderWrapper.cs
- XmlSerializerVersionAttribute.cs
- SrgsItemList.cs
- BehaviorEditorPart.cs
- UriSection.cs
- DetailsView.cs
- LinkedResource.cs
- FieldAccessException.cs
- WorkflowNamespace.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- SqlProviderUtilities.cs
- CapabilitiesSection.cs
- ConfigurationManagerInternal.cs
- XmlAnyAttributeAttribute.cs
- ExpandedWrapper.cs
- ScrollData.cs
- MissingManifestResourceException.cs
- AlgoModule.cs
- RefExpr.cs
- DataGridItemEventArgs.cs
- DetailsViewDeleteEventArgs.cs
- IFlowDocumentViewer.cs
- StackBuilderSink.cs
- TransactionalPackage.cs
- ReceiveParametersContent.cs
- WindowsGraphics2.cs
- DragEventArgs.cs
- ObjectViewFactory.cs
- WebPartAuthorizationEventArgs.cs
- PageCatalogPart.cs
- DecoderBestFitFallback.cs
- WebBrowser.cs
- GlobalProxySelection.cs
- PriorityChain.cs
- CompositeActivityCodeGenerator.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- WizardStepCollectionEditor.cs
- DtrList.cs
- InvalidFilterCriteriaException.cs
- HebrewNumber.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- AccessDataSource.cs
- XmlSchemaObjectTable.cs
- TracedNativeMethods.cs
- InputProviderSite.cs
- FragmentQuery.cs
- RootBrowserWindowAutomationPeer.cs
- ComponentDispatcherThread.cs
- ExtenderControl.cs
- FixedSOMTableRow.cs
- ToolStripSplitButton.cs
- SessionSwitchEventArgs.cs