SoapServices.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // System.Runtime.Remoting.SoapServices.cs
  3. //
  4. // Author: Jaime Anguiano Olarra ([email protected])
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (c) 2002, Jaime Anguiano Olarra
  8. //
  9. using System;
  10. using System.Runtime.Remoting;
  11. using System.Reflection;
  12. using System.Runtime.InteropServices;
  13. namespace System.Runtime.Remoting {
  14. [Serializable]
  15. [ClassInterface (ClassInterfaceType.AutoDual)]
  16. public class SoapServices
  17. {
  18. // properties
  19. public static string XmlNsForClrType
  20. {
  21. get { return "http://schemas.microsoft.com/clr/"; }
  22. }
  23. public static string XmlNsForClrTypeWithAssembly
  24. {
  25. get { return "http://schemas.microsoft.com/clr/assem/"; }
  26. }
  27. public static string XmlNsForClrTypeWithNs
  28. {
  29. get { return "http://schemas.microsoft.com/clr/ns/"; }
  30. }
  31. public static string XmlNsForClrTypeWithMsAndAssembly
  32. {
  33. get { return "http://schemas.microsoft.com/clr/nsassem/"; }
  34. }
  35. // public methods
  36. public static string CodeXmlNamespaceForClrTypeNamespace (string typeNamespace,
  37. string assemblyName)
  38. {
  39. // If assemblyName is empty, then use the corlib namespace
  40. if (assemblyName == string.Empty)
  41. return XmlNsForClrTypeWithNs + typeNamespace + "/" + assemblyName;
  42. else
  43. return XmlNsForClrTypeWithMsAndAssembly + typeNamespace + "/" + assemblyName;
  44. }
  45. public static bool DecodeXmlNamespaceForClrTypeNamespace (string inNamespace,
  46. out string typeNamespace,
  47. out string assemblyName) {
  48. if (inNamespace == null) throw new ArgumentNullException ("inNamespace");
  49. typeNamespace = null;
  50. assemblyName = null;
  51. if (inNamespace.StartsWith(XmlNsForClrTypeWithMsAndAssembly))
  52. {
  53. int typePos = XmlNsForClrTypeWithMsAndAssembly.Length;
  54. if (typePos >= inNamespace.Length) return false;
  55. int assemPos = inNamespace.IndexOf ('/', typePos+1);
  56. if (assemPos == -1) return false;
  57. typeNamespace = inNamespace.Substring (typePos, assemPos - typePos);
  58. assemblyName = inNamespace.Substring (assemPos+1);
  59. return true;
  60. }
  61. else if (inNamespace.StartsWith(XmlNsForClrTypeWithNs))
  62. {
  63. int typePos = XmlNsForClrTypeWithNs.Length;
  64. typeNamespace = inNamespace.Substring (typePos);
  65. return true;
  66. }
  67. else
  68. return false;
  69. }
  70. [MonoTODO]
  71. public static void GetInteropFieldTypeAndNameFromXmlAttribute (Type containingType,
  72. string xmlAttribute,
  73. string xmlNamespace,
  74. out Type type,
  75. out string name) {
  76. throw new NotImplementedException ();
  77. }
  78. [MonoTODO]
  79. public static void GetInteropFieldTypeAndNameFromXmlElement (Type containingType,
  80. string xmlElement,
  81. string xmlNamespace,
  82. out Type type,
  83. out string name) {
  84. throw new NotImplementedException ();
  85. }
  86. [MonoTODO]
  87. public static Type GetInteropTypeFromXmlElement (string xmlElement, string xmlNamespace) {
  88. throw new NotImplementedException ();
  89. }
  90. [MonoTODO]
  91. public static Type GetInteropTypeFromXmlType (string xmlType, string xmlTypeNamespace) {
  92. throw new NotImplementedException ();
  93. }
  94. private static string GetAssemblyName(MethodBase mb)
  95. {
  96. if (mb.DeclaringType.Assembly == typeof (object).Assembly)
  97. return string.Empty;
  98. else
  99. return mb.DeclaringType.Assembly.GetName().Name;
  100. }
  101. public static string GetSoapActionFromMethodBase (MethodBase mb)
  102. {
  103. string ns = CodeXmlNamespaceForClrTypeNamespace (mb.DeclaringType.Name, GetAssemblyName(mb));
  104. return ns + "#" + mb.Name;
  105. }
  106. [MonoTODO]
  107. public new Type GetType () {
  108. throw new NotImplementedException ();
  109. }
  110. public static bool GetTypeAndMethodNameFromSoapAction (string soapAction,
  111. out string typeName,
  112. out string methodName) {
  113. string type;
  114. string assembly;
  115. typeName = null;
  116. methodName = null;
  117. int i = soapAction.LastIndexOf ('#');
  118. if (i == -1) return false;
  119. methodName = soapAction.Substring (i+1);
  120. if (!DecodeXmlNamespaceForClrTypeNamespace (soapAction.Substring (0,i), out type, out assembly) )
  121. return false;
  122. if (assembly == null)
  123. typeName = type + ", " + typeof (object).Assembly.GetName().Name;
  124. else
  125. typeName = type + ", " + assembly;
  126. return true;
  127. }
  128. [MonoTODO]
  129. public static bool GetXmlElementForInteropType (Type type,
  130. out string xmlElement,
  131. out string xmlNamespace) {
  132. throw new NotImplementedException ();
  133. }
  134. public static string GetXmlNamespaceForMethodCall (MethodBase mb)
  135. {
  136. return CodeXmlNamespaceForClrTypeNamespace (mb.DeclaringType.Name, GetAssemblyName(mb));
  137. }
  138. public static string GetXmlNamespaceForMethodResponse (MethodBase mb)
  139. {
  140. return CodeXmlNamespaceForClrTypeNamespace (mb.DeclaringType.Name, GetAssemblyName(mb));
  141. }
  142. [MonoTODO]
  143. public static bool GetXmlTypeForInteropType (Type type,
  144. out string xmlType,
  145. out string xmlTypeNamespace) {
  146. throw new NotImplementedException ();
  147. }
  148. public static bool IsClrTypeNamespace (string namespaceString)
  149. {
  150. return namespaceString.StartsWith (XmlNsForClrType);
  151. }
  152. public static bool IsSoapActionValidForMethodBase (string soapAction, MethodBase mb)
  153. {
  154. string typeName;
  155. string methodName;
  156. GetTypeAndMethodNameFromSoapAction (soapAction, out typeName, out methodName);
  157. if (methodName != mb.Name) return false;
  158. string methodClassType = mb.DeclaringType.FullName + ", " + mb.DeclaringType.Assembly.GetName().Name;
  159. return typeName == methodClassType;
  160. }
  161. [MonoTODO]
  162. public static void PreLoad (Assembly assembly) {
  163. throw new NotImplementedException ();
  164. }
  165. [MonoTODO]
  166. public static void PreLoad (Type type) {
  167. throw new NotImplementedException ();
  168. }
  169. [MonoTODO]
  170. public static void RegisterInteropXmlElement (string xmlElement,
  171. string xmlNamespace,
  172. Type type) {
  173. throw new NotImplementedException ();
  174. }
  175. [MonoTODO]
  176. public static void RegisterInteropXmlType (string xmlType,
  177. string xmlTypeNamespace,
  178. Type type) {
  179. throw new NotImplementedException ();
  180. }
  181. [MonoTODO]
  182. public static void RegisterSoapActionForMethodBase (MethodBase mb) {
  183. throw new NotImplementedException ();
  184. }
  185. [MonoTODO]
  186. public static void RegisterSoapActionForMethodBase (MethodBase mb, string soapAction) {
  187. throw new NotImplementedException ();
  188. }
  189. }
  190. }