Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Web / System / Web / Services / Protocols / XmlReturnReader.cs / 1305376 / XmlReturnReader.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Services.Protocols { using System.IO; using System; using System.Xml.Serialization; using System.Reflection; using System.Collections; using System.Web.Services; using System.Net; using System.Text; using System.Security.Policy; using System.Security; using System.Security.Permissions; using System.Web.Services.Diagnostics; internal class XmlReturn { private XmlReturn() { } internal static object[] GetInitializers(LogicalMethodInfo[] methodInfos) { if (methodInfos.Length == 0) return new object[0]; WebServiceAttribute serviceAttribute = WebServiceReflector.GetAttribute(methodInfos); bool serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(WebServiceReflector.GetMostDerivedType(methodInfos)); XmlReflectionImporter importer = SoapReflector.CreateXmlImporter(serviceAttribute.Namespace, serviceDefaultIsEncoded); WebMethodReflector.IncludeTypes(methodInfos, importer); ArrayList mappings = new ArrayList(); bool[] supported = new bool[methodInfos.Length]; for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; Type type = methodInfo.ReturnType; if (IsSupported(type) && HttpServerProtocol.AreUrlParametersSupported(methodInfo)) { XmlAttributes a = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider); XmlTypeMapping mapping = importer.ImportTypeMapping(type, a.XmlRoot); mapping.SetKey(methodInfo.GetKey() + ":Return"); mappings.Add(mapping); supported[i] = true; } } if (mappings.Count == 0) return new object[0]; XmlMapping[] xmlMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping)); Evidence evidence = GetEvidenceForType(methodInfos[0].DeclaringType); TraceMethod caller = Tracing.On ? new TraceMethod(typeof(XmlReturn), "GetInitializers", methodInfos) : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceCreateSerializer), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", xmlMappings, evidence)); XmlSerializer[] serializers = null; if (AppDomain.CurrentDomain.IsHomogenous) { serializers = XmlSerializer.FromMappings(xmlMappings); } else { #pragma warning disable 618 // If we're in a non-homogenous domain, legacy CAS mode is enabled, so passing through evidence will not fail serializers = XmlSerializer.FromMappings(xmlMappings, evidence); #pragma warning restore 618 } if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceCreateSerializer), caller); object[] initializers = new object[methodInfos.Length]; int count = 0; for (int i = 0; i < initializers.Length; i++) { if (supported[i]) { initializers[i] = serializers[count++]; } } return initializers; } static bool IsSupported(Type returnType) { return returnType != typeof(void); } internal static object GetInitializer(LogicalMethodInfo methodInfo) { return GetInitializers(new LogicalMethodInfo[] { methodInfo }); } // Asserts full-trust permission-set. // Reason: Assembly.Evidence demands SecurityPermission and/or other permissions. // Justification: The type returned is only used to get the GetInitializers method. [PermissionSet(SecurityAction.Assert, Unrestricted = true)] static Evidence GetEvidenceForType(Type type) { return type.Assembly.Evidence; } } ///public class XmlReturnReader : MimeReturnReader { XmlSerializer xmlSerializer; /// public override void Initialize(object o) { xmlSerializer = (XmlSerializer)o; } /// public override object[] GetInitializers(LogicalMethodInfo[] methodInfos) { return XmlReturn.GetInitializers(methodInfos); } /// public override object GetInitializer(LogicalMethodInfo methodInfo) { return XmlReturn.GetInitializer(methodInfo); } /// public override object Read(WebResponse response, Stream responseStream) { try { if (response == null) throw new ArgumentNullException("response"); if (!ContentType.MatchesBase(response.ContentType, ContentType.TextXml)) { throw new InvalidOperationException(Res.GetString(Res.WebResultNotXml)); } Encoding e = RequestResponseUtils.GetEncoding(response.ContentType); StreamReader reader = new StreamReader(responseStream, e, true); TraceMethod caller = Tracing.On ? new TraceMethod(this, "Read") : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceReadResponse), caller, new TraceMethod(xmlSerializer, "Deserialize", reader)); object returnValue = xmlSerializer.Deserialize(reader); if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceReadResponse), caller); return returnValue; } finally { response.Close(); } } } } // 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.IO; using System; using System.Xml.Serialization; using System.Reflection; using System.Collections; using System.Web.Services; using System.Net; using System.Text; using System.Security.Policy; using System.Security; using System.Security.Permissions; using System.Web.Services.Diagnostics; internal class XmlReturn { private XmlReturn() { } internal static object[] GetInitializers(LogicalMethodInfo[] methodInfos) { if (methodInfos.Length == 0) return new object[0]; WebServiceAttribute serviceAttribute = WebServiceReflector.GetAttribute(methodInfos); bool serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(WebServiceReflector.GetMostDerivedType(methodInfos)); XmlReflectionImporter importer = SoapReflector.CreateXmlImporter(serviceAttribute.Namespace, serviceDefaultIsEncoded); WebMethodReflector.IncludeTypes(methodInfos, importer); ArrayList mappings = new ArrayList(); bool[] supported = new bool[methodInfos.Length]; for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; Type type = methodInfo.ReturnType; if (IsSupported(type) && HttpServerProtocol.AreUrlParametersSupported(methodInfo)) { XmlAttributes a = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider); XmlTypeMapping mapping = importer.ImportTypeMapping(type, a.XmlRoot); mapping.SetKey(methodInfo.GetKey() + ":Return"); mappings.Add(mapping); supported[i] = true; } } if (mappings.Count == 0) return new object[0]; XmlMapping[] xmlMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping)); Evidence evidence = GetEvidenceForType(methodInfos[0].DeclaringType); TraceMethod caller = Tracing.On ? new TraceMethod(typeof(XmlReturn), "GetInitializers", methodInfos) : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceCreateSerializer), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", xmlMappings, evidence)); XmlSerializer[] serializers = null; if (AppDomain.CurrentDomain.IsHomogenous) { serializers = XmlSerializer.FromMappings(xmlMappings); } else { #pragma warning disable 618 // If we're in a non-homogenous domain, legacy CAS mode is enabled, so passing through evidence will not fail serializers = XmlSerializer.FromMappings(xmlMappings, evidence); #pragma warning restore 618 } if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceCreateSerializer), caller); object[] initializers = new object[methodInfos.Length]; int count = 0; for (int i = 0; i < initializers.Length; i++) { if (supported[i]) { initializers[i] = serializers[count++]; } } return initializers; } static bool IsSupported(Type returnType) { return returnType != typeof(void); } internal static object GetInitializer(LogicalMethodInfo methodInfo) { return GetInitializers(new LogicalMethodInfo[] { methodInfo }); } // Asserts full-trust permission-set. // Reason: Assembly.Evidence demands SecurityPermission and/or other permissions. // Justification: The type returned is only used to get the GetInitializers method. [PermissionSet(SecurityAction.Assert, Unrestricted = true)] static Evidence GetEvidenceForType(Type type) { return type.Assembly.Evidence; } } ///public class XmlReturnReader : MimeReturnReader { XmlSerializer xmlSerializer; /// public override void Initialize(object o) { xmlSerializer = (XmlSerializer)o; } /// public override object[] GetInitializers(LogicalMethodInfo[] methodInfos) { return XmlReturn.GetInitializers(methodInfos); } /// public override object GetInitializer(LogicalMethodInfo methodInfo) { return XmlReturn.GetInitializer(methodInfo); } /// public override object Read(WebResponse response, Stream responseStream) { try { if (response == null) throw new ArgumentNullException("response"); if (!ContentType.MatchesBase(response.ContentType, ContentType.TextXml)) { throw new InvalidOperationException(Res.GetString(Res.WebResultNotXml)); } Encoding e = RequestResponseUtils.GetEncoding(response.ContentType); StreamReader reader = new StreamReader(responseStream, e, true); TraceMethod caller = Tracing.On ? new TraceMethod(this, "Read") : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceReadResponse), caller, new TraceMethod(xmlSerializer, "Deserialize", reader)); object returnValue = xmlSerializer.Deserialize(reader); if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceReadResponse), caller); return returnValue; } finally { response.Close(); } } } } // 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
- ChangeToolStripParentVerb.cs
- InheritanceRules.cs
- FloatUtil.cs
- M3DUtil.cs
- DockProviderWrapper.cs
- CreateUserWizardStep.cs
- Viewport2DVisual3D.cs
- EastAsianLunisolarCalendar.cs
- Soap12ProtocolImporter.cs
- DbFunctionCommandTree.cs
- ScaleTransform.cs
- Light.cs
- Propagator.JoinPropagator.cs
- DataGridTableCollection.cs
- XmlCharCheckingReader.cs
- MetadataSet.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- ToolStripItemRenderEventArgs.cs
- ConfigXmlElement.cs
- TextLine.cs
- PersonalizationEntry.cs
- XslNumber.cs
- BasicViewGenerator.cs
- InfoCard.cs
- ThreadBehavior.cs
- TextModifier.cs
- Mappings.cs
- NullableIntAverageAggregationOperator.cs
- RootBuilder.cs
- AppSettingsReader.cs
- ListenerConnectionDemuxer.cs
- Monitor.cs
- HttpListenerPrefixCollection.cs
- Aggregates.cs
- Utils.cs
- RepeatBehavior.cs
- MDIWindowDialog.cs
- WinInetCache.cs
- FixedBufferAttribute.cs
- ProxyWebPartConnectionCollection.cs
- ParenthesizePropertyNameAttribute.cs
- ControlBuilderAttribute.cs
- UIPropertyMetadata.cs
- ExceptionCollection.cs
- mil_commands.cs
- SafeRegistryHandle.cs
- RequestQueryProcessor.cs
- AcceleratedTokenAuthenticator.cs
- TraceLog.cs
- ResXDataNode.cs
- WindowsScrollBarBits.cs
- RangeBaseAutomationPeer.cs
- httpserverutility.cs
- TimelineGroup.cs
- shaperfactoryquerycacheentry.cs
- DataServiceQueryException.cs
- RenamedEventArgs.cs
- FixedDocument.cs
- ChainOfDependencies.cs
- RegexInterpreter.cs
- XamlReaderHelper.cs
- ObjectNotFoundException.cs
- DelayDesigner.cs
- RightsManagementInformation.cs
- ParameterBuilder.cs
- InputBuffer.cs
- IRCollection.cs
- DesignerView.Commands.cs
- ColumnHeaderConverter.cs
- BaseDataBoundControl.cs
- BypassElement.cs
- Models.cs
- _Connection.cs
- SmiEventSink_DeferedProcessing.cs
- OdbcConnectionOpen.cs
- UIElementAutomationPeer.cs
- FileDialogCustomPlace.cs
- SystemKeyConverter.cs
- ScrollBarAutomationPeer.cs
- EnumUnknown.cs
- DotAtomReader.cs
- DesignerLabelAdapter.cs
- CryptoApi.cs
- UIElementParaClient.cs
- MessageHeaderDescriptionCollection.cs
- FlowDocumentPageViewerAutomationPeer.cs
- ChtmlTextWriter.cs
- NotSupportedException.cs
- DetailsViewAutoFormat.cs
- BasicDesignerLoader.cs
- WindowsFormsHostPropertyMap.cs
- UpdateException.cs
- DesignerListAdapter.cs
- ListViewInsertionMark.cs
- Action.cs
- _ConnectStream.cs
- Utils.cs
- ReferenceEqualityComparer.cs
- ParallelTimeline.cs
- Pair.cs