soapservices.cs

来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 878 行 · 第 1/2 页

CS
878
字号
				String assemblyName;				if(!DecodeXmlNamespaceForClrTypeNamespace						(name, out typeName, out assemblyName))				{					hasAssembly = false;					return null;				}				if(assemblyName == null || assemblyName.Length == 0)				{					if(name.StartsWith(XmlNsForClrTypeWithNs))					{						hasAssembly = true;						return typeName + ", mscorlib";					}					else					{						hasAssembly = false;						return typeName;					}				}				else				{					hasAssembly = true;					return typeName + ", " + assemblyName;				}			}	// Get type and method information from a SOAP action.	public static bool GetTypeAndMethodNameFromSoapAction				(String soapAction, out String typeName, out String methodName)			{				int index;				bool hasAssembly;				// Remove quotes from the action name.				if(soapAction[0] == '"' && soapAction.EndsWith("\""))				{					soapAction = soapAction.Substring						(1, soapAction.Length - 2);				}				// Look in the registered action table.				lock(typeof(SoapServices))				{					if(actionToMethod != null)					{						MethodBase mb =							(MethodBase)(actionToMethod[soapAction]);						if(mb != null)						{							String assembly =								mb.DeclaringType.Module.Assembly.FullName;							index = assembly.IndexOf(',');							if(index != -1)							{								assembly = assembly.Substring(0, index);							}							typeName = mb.DeclaringType.FullName +								", " + assembly;							methodName = mb.Name;							return true;						}					}				}				// Split the action into type and method name.				index = soapAction.IndexOf('#');				if(index != -1)				{					typeName = ExtractTypeName						(soapAction.Substring(0, index), out hasAssembly);					if(typeName != null)					{						methodName = soapAction.Substring(index + 1);						return true;					}				}				// Unable to determine the type and method names.				typeName = null;				methodName = null;				return false;			}	// Get the XML element information for serializing a type.	public static bool GetXmlElementForInteropType				(Type type, out String xmlElement, out String xmlNamespace)			{				// Look in the registered element table first.				lock(typeof(SoapServices))				{					if(typeToElement != null)					{						String key = (String)(typeToElement[type]);						if(key != null)						{							XmlKeyExpand(key, out xmlElement,										 out xmlNamespace);							return true;						}					}				}				// Check the attribute on the type.				SoapTypeAttribute tattr = (SoapTypeAttribute)					InternalRemotingServices.GetCachedSoapAttribute(type);				if(tattr.xmlElementWasSet)				{					xmlElement = tattr.XmlElementName;					xmlNamespace = tattr.XmlNamespace;					return true;				}				// We were unable to determine the XML element information.				xmlElement = null;				xmlNamespace = null;				return false;			}	// Get the namespace to use for a method call.	public static String GetXmlNamespaceForMethodCall(MethodBase mb)			{				return ((SoapMethodAttribute)					InternalRemotingServices.GetCachedSoapAttribute(mb))						.XmlNamespace;			}	// Get the namespace to use for a method response.	public static String GetXmlNamespaceForMethodResponse(MethodBase mb)			{				return ((SoapMethodAttribute)					InternalRemotingServices.GetCachedSoapAttribute(mb))						.ResponseXmlNamespace;			}	// Get XML type information for a type.	public static bool GetXmlTypeForInteropType				(Type type, out String xmlType, out String xmlTypeNamespace)			{				// Look in the registered type table first.				lock(typeof(SoapServices))				{					if(typeToXmlType != null)					{						String key = (String)(typeToXmlType[type]);						if(key != null)						{							XmlKeyExpand(key, out xmlType,										 out xmlTypeNamespace);							return true;						}					}				}				// Check the attribute on the type.				SoapTypeAttribute tattr = (SoapTypeAttribute)					InternalRemotingServices.GetCachedSoapAttribute(type);				if(tattr.xmlTypeWasSet)				{					xmlType = tattr.XmlTypeName;					xmlTypeNamespace = tattr.XmlTypeNamespace;					return true;				}				// We were unable to determine the XML element information.				xmlType = null;				xmlTypeNamespace = null;				return false;			}	// Determine if a namespace indicates CLR information.	public static bool IsClrTypeNamespace(String namespaceString)			{				if(namespaceString != null)				{					return namespaceString.StartsWith						("http://schemas.microsoft.com/clr/");				}				else				{					return false;				}			}	// Determine if a SOAP action is valid for a method.	public static bool IsSoapActionValidForMethodBase				(String soapAction, MethodBase mb)			{				SoapMethodAttribute mattr;				int index, index2;				String typeName;				String mbTypeName;				String assembly;				bool hasAssembly;				// Remove quotes from the action name.				if(soapAction[0] == '"' && soapAction.EndsWith("\""))				{					soapAction = soapAction.Substring						(1, soapAction.Length - 2);				}				// If the action matches the attribute, then return true.				mattr = (SoapMethodAttribute)					InternalRemotingServices.GetCachedSoapAttribute(mb);				if(mattr.SoapAction == soapAction)				{					return true;				}				// Determine if the action matches the one registered				// with the method.				lock(typeof(SoapServices))				{					if(methodToAction != null)					{						String temp = (String)(methodToAction[mb]);						if(temp != null && temp == soapAction)						{							return true;						}					}				}				// Pull apart the action and check its components.				index = soapAction.IndexOf('#');				if(index != -1)				{					typeName = ExtractTypeName						(soapAction.Substring(0, index), out hasAssembly);					if(typeName != null)					{						if(hasAssembly)						{							assembly = mb.DeclaringType.Module								.Assembly.FullName;							index2 = assembly.IndexOf(',');							if(index2 != -1)							{								assembly = assembly.Substring(0, index2);							}							mbTypeName = mb.DeclaringType.FullName +								", " + assembly;						}						else						{							mbTypeName = mb.DeclaringType.FullName;						}						if(typeName == mbTypeName)						{							return (mb.Name == soapAction.Substring(index + 1));						}					}				}				// The action string is not valid.				return false;			}	// Preload SOAP handling information.	public static void PreLoad(Assembly assembly)			{				foreach(Type type in assembly.GetTypes())				{					PreLoad(type);				}			}	public static void PreLoad(Type type)			{				// Register soap actions for the methods in the type.				foreach(MethodInfo method in type.GetMethods())				{					RegisterSoapActionForMethodBase(method);				}				// Register XML tags for the type, if specified.				SoapTypeAttribute tattr = (SoapTypeAttribute)					InternalRemotingServices.GetCachedSoapAttribute(type);				if(tattr.xmlElementWasSet)				{					RegisterInteropXmlElement						(tattr.XmlElementName, tattr.XmlNamespace, type);				}				if(tattr.xmlTypeWasSet)				{					RegisterInteropXmlType						(tattr.XmlTypeName, tattr.XmlTypeNamespace, type);				}				// Load and register the field mapping information.				lock(typeof(SoapServices))				{					if(fields == null)					{						fields = new Hashtable();					}					TypeFieldInfo typeInfo = new TypeFieldInfo();					foreach(FieldInfo field in type.GetFields())					{						SoapFieldAttribute fattr = (SoapFieldAttribute)							InternalRemotingServices.GetCachedSoapAttribute								(field);						if(fattr.IsInteropXmlElement())						{							if(fattr.UseAttribute)							{								typeInfo.StoreAttribute									(XmlKey(fattr.XmlElementName,											fattr.XmlNamespace),								 	 field.Name, field.FieldType);							}							else							{								typeInfo.StoreElement									(XmlKey(fattr.XmlElementName,											fattr.XmlNamespace),								 	 field.Name, field.FieldType);							}						}					}					if(typeInfo.IsPopulated)					{						fields[type] = typeInfo;					}				}			}	// Build a key value for looking up XML element information.	private static String XmlKey(String name, String nspace)			{				if(nspace != null)				{					return name + "\uFFFF" + nspace;				}				else				{					return name;				}			}	// Convert an XML element key value back into its name and namespace.	private static void XmlKeyExpand(String key, out String name,									 out String nspace)			{				int index = key.IndexOf('\uFFFF');				if(index == -1)				{					name = key;					nspace = null;				}				else				{					name = key.Substring(0, index);					nspace = key.Substring(index + 1);				}			}	// Register an XML element name with a type.	public static void RegisterInteropXmlElement				(String xmlElement, String xmlNamespace, Type type)			{				lock(typeof(SoapServices))				{					// Create the mapping tables if necessary.					if(elementToType == null)					{						elementToType = new Hashtable();						typeToElement = new Hashtable();					}					// Add the element to type and type to element mappings.					String key = XmlKey(xmlElement, xmlNamespace);					elementToType[key] = type;					typeToElement[type] = key;				}			}	// Register an XML type name with a type.	public static void RegisterInteropXmlType				(String xmlType, String xmlTypeNamespace, Type type)			{				lock(typeof(SoapServices))				{					// Create the mapping tables if necessary.					if(elementToType == null)					{						xmlTypeToType = new Hashtable();						typeToXmlType = new Hashtable();					}					// Add the element to type and type to element mappings.					String key = XmlKey(xmlType, xmlTypeNamespace);					xmlTypeToType[key] = type;					typeToXmlType[type] = key;				}			}	// Register a SOAP action for a method.	public static void RegisterSoapActionForMethodBase(MethodBase mb)			{				// Fetch the action from the method base.				SoapMethodAttribute mattr;				mattr = (SoapMethodAttribute)					InternalRemotingServices.GetCachedSoapAttribute(mb);				if(mattr.soapActionWasSet)				{					RegisterSoapActionForMethodBase(mb, mattr.SoapAction);				}			}	public static void RegisterSoapActionForMethodBase				(MethodBase mb, String soapAction)			{				if(soapAction == null)				{					return;				}				lock(typeof(SoapServices))				{					// Make sure that the tables have been created.					if(methodToAction == null)					{						methodToAction = new Hashtable();						actionToMethod = new Hashtable();					}					// Register the method to action mapping.					methodToAction[mb] = soapAction;					// Register the action to method mapping.					actionToMethod[soapAction] = mb;				}			}}; // class SoapServices#endif // CONFIG_SERIALIZATION}; // namespace System.Runtime.Remoting

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?