soapservices.cs
来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 878 行 · 第 1/2 页
CS
878 行
/* * SoapServices.cs - Implementation of the * "System.Runtime.Remoting.SoapServices" class. * * Copyright (C) 2003 Southern Storm Software, Pty Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */namespace System.Runtime.Remoting{#if CONFIG_SERIALIZATIONusing System.Collections;using System.Reflection;using System.Runtime.Remoting.Metadata;using System.Text;public class SoapServices{ // Internal state. private static Hashtable methodToAction; private static Hashtable actionToMethod; private static Hashtable elementToType; private static Hashtable typeToElement; private static Hashtable xmlTypeToType; private static Hashtable typeToXmlType; private static Hashtable fields; // Information about a field name and type. private sealed class FieldNameAndTypeInfo { // Internal state. public String name; public Type type; // Constructor. public FieldNameAndTypeInfo(String name, Type type) { this.name = name; this.type = type; } }; // class FieldNameAndTypeInfo // Information that is stored about a type's fields. private sealed class TypeFieldInfo { // Internal state. public Hashtable fieldAttrs; public Hashtable fieldElements; // Constructor. public TypeFieldInfo() { fieldAttrs = new Hashtable(); fieldElements = new Hashtable(); } // Determine if this object contains items. public bool IsPopulated { get { return (fieldAttrs.Count > 0 || fieldElements.Count > 0); } } // Store attribute information for a field. public void StoreAttribute(String key, String name, Type type) { fieldAttrs[key] = new FieldNameAndTypeInfo(name, type); } // Store element information for a field. public void StoreElement(String key, String name, Type type) { fieldElements[key] = new FieldNameAndTypeInfo(name, type); } // Get attribute information for a field. public FieldNameAndTypeInfo GetAttribute(String key) { return (FieldNameAndTypeInfo)(fieldAttrs[key]); } // Get element information for a field. public FieldNameAndTypeInfo GetElement(String key) { return (FieldNameAndTypeInfo)(fieldElements[key]); } }; // class TypeFieldInfo // Cannot create instances of this class. private SoapServices() {} // Standard namespace prefixes, defined by Microsoft. public static String XmlNsForClrType { get { return "http://schemas.microsoft.com/clr/"; } } public static String XmlNsForClrTypeWithAssembly { get { return "http://schemas.microsoft.com/clr/assem/"; } } public static String XmlNsForClrTypeWithNs { get { return "http://schemas.microsoft.com/clr/ns/"; } } public static String XmlNsForClrTypeWithNsAndAssembly { get { return "http://schemas.microsoft.com/clr/nsassem/"; } } // Encode SOAP names. public static String CodeXmlNamespaceForClrTypeNamespace (String typeNamespace, String assemblyName) { StringBuilder builder = new StringBuilder(); // Add the URI prefix and type name to the builder. if(typeNamespace != null && typeNamespace.Length > 0) { if(assemblyName != null && assemblyName.Length > 0) { // We have both type and assembly names. builder.Append(XmlNsForClrTypeWithNsAndAssembly); if(typeNamespace[0] != '.') { builder.Append(typeNamespace); } else { // Strip a leading ".", if present. builder.Append(typeNamespace, 1, typeNamespace.Length - 1); } builder.Append(typeNamespace); builder.Append('/'); } else { // We have only a type name. builder.Append(XmlNsForClrTypeWithNs); builder.Append(typeNamespace); return builder.ToString(); } } else if(assemblyName != null && assemblyName.Length > 0) { // We have only an assembly name. builder.Append(XmlNsForClrTypeWithAssembly); } else { // Neither name was supplied. throw new ArgumentNullException ("typeNamespace & assemblyName"); } // Encode the assembly name and add it to the builder. foreach(char ch in assemblyName) { if(ch == ' ' || ch == '=' || ch == ',' || ch == '%') { builder.Append('%'); BitConverter.AppendHex(builder, (int)ch); } else { builder.Append(ch); } } // Return the final string to the caller. return builder.ToString(); } // Decode SOAP names. public static bool DecodeXmlNamespaceForClrTypeNamespace (String inNamespace, out String typeNamespace, out String assemblyName) { String suffix; int index; StringBuilder builder; char ch; int temp; // Validate the parameter. if(inNamespace == null || inNamespace.Length == 0) { throw new ArgumentNullException("inNamespace"); } // Clear the return values before we start, in case // we have to bail out early. typeNamespace = String.Empty; assemblyName = null; // Determine what form of URI we are dealing with. if(inNamespace.StartsWith(XmlNsForClrTypeWithNsAndAssembly)) { // Type and assembly names. suffix = inNamespace.Substring (XmlNsForClrTypeWithNsAndAssembly.Length); index = suffix.IndexOf('/'); if(index == -1) { return false; } typeNamespace = suffix.Substring(0, index); suffix = suffix.Substring(index + 1); } else if(inNamespace.StartsWith(XmlNsForClrTypeWithNs)) { // Just the type name. typeNamespace = inNamespace.Substring (XmlNsForClrTypeWithNs.Length); return true; } else if(inNamespace.StartsWith(XmlNsForClrTypeWithAssembly)) { // Just the assembly name. suffix = inNamespace.Substring (XmlNsForClrTypeWithAssembly.Length); } else { // This form of URI is not recognised. return false; } // Decode the suffix into an assembly name. builder = new StringBuilder(); index = 0; while(index < suffix.Length) { ch = suffix[index++]; if(ch == '%') { if((index + 1) >= suffix.Length) { return false; } ch = suffix[index++]; if(ch >= '0' && ch <= '9') { temp = (ch - '0') << 4; } else if(ch >= 'A' && ch <= 'F') { temp = (ch - 'A' + 10) << 4; } else if(ch >= 'a' && ch <= 'f') { temp = (ch - 'a' + 10) << 4; } else { return false; } ch = suffix[index++]; if(ch >= '0' && ch <= '9') { temp += ch - '0'; } else if(ch >= 'A' && ch <= 'F') { temp += ch - 'A' + 10; } else if(ch >= 'a' && ch <= 'f') { temp += ch - 'a' + 10; } else { return false; } builder.Append((char)temp); } else { builder.Append(ch); } } assemblyName = builder.ToString(); return true; } // Get field information from SOAP data. public static void GetInteropFieldTypeAndNameFromXmlAttribute (Type containingType, String xmlAttribute, String xmlNamespace, out Type type, out String name) { TypeFieldInfo typeInfo; FieldNameAndTypeInfo info; if(containingType != null) { lock(typeof(SoapServices)) { if(fields != null) { typeInfo = (TypeFieldInfo)(fields[containingType]); if(typeInfo != null) { info = typeInfo.GetAttribute (XmlKey(xmlAttribute, xmlNamespace)); if(info != null) { name = info.name; type = info.type; return; } } } } } type = null; name = null; } public static void GetInteropFieldTypeAndNameFromXmlElement (Type containingType, String xmlElement, String xmlNamespace, out Type type, out String name) { TypeFieldInfo typeInfo; FieldNameAndTypeInfo info; if(containingType != null) { lock(typeof(SoapServices)) { if(fields != null) { typeInfo = (TypeFieldInfo)(fields[containingType]); if(typeInfo != null) { info = typeInfo.GetElement (XmlKey(xmlElement, xmlNamespace)); if(info != null) { name = info.name; type = info.type; return; } } } } } type = null; name = null; } // Get type information from SOAP data. public static Type GetInteropTypeFromXmlElement (String xmlElement, String xmlNamespace) { lock(typeof(SoapServices)) { if(elementToType != null) { return (Type)(elementToType [XmlKey(xmlElement, xmlNamespace)]); } else { return null; } } } public static Type GetInteropTypeFromXmlType (String xmlType, String xmlTypeNamespace) { lock(typeof(SoapServices)) { if(elementToType != null) { return (Type)(xmlTypeToType [XmlKey(xmlType, xmlTypeNamespace)]); } else { return null; } } } // Get the SOAP action associated with a method. public static String GetSoapActionFromMethodBase(MethodBase mb) { // See if we have a registered action first. lock(typeof(SoapServices)) { if(methodToAction != null) { String temp = (String)(methodToAction[mb]); if(temp != null) { return temp; } } } // Get the action from the method itself. return ((SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb)) .SoapAction; } // Extract the type name from an XML namespace indication. private static String ExtractTypeName(String name, out bool hasAssembly) { String typeName;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?