internal bool CanCastToXmlType(string xmlTypeName, string xmlTypeNamespace) { Type interopTypeFromXmlType = SoapServices.GetInteropTypeFromXmlType(xmlTypeName, xmlTypeNamespace); if (interopTypeFromXmlType == null) { string str; string str2; string str3; if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlTypeNamespace, out str, out str2)) { return(false); } if ((str != null) && (str.Length > 0)) { str3 = str + "." + xmlTypeName; } else { str3 = xmlTypeName; } try { interopTypeFromXmlType = Assembly.Load(str2).GetType(str3, false, false); } catch { return(false); } } return((interopTypeFromXmlType != null) && interopTypeFromXmlType.IsAssignableFrom(base.GetType())); }
internal bool CanCastToXmlType(string xmlTypeName, string xmlTypeNamespace) { Type type = SoapServices.GetInteropTypeFromXmlType(xmlTypeName, xmlTypeNamespace); if (type == null) { string text; string assemblyString; if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlTypeNamespace, out text, out assemblyString)) { return(false); } string name; if (text != null && text.Length > 0) { name = text + "." + xmlTypeName; } else { name = xmlTypeName; } try { Assembly assembly = Assembly.Load(assemblyString); type = assembly.GetType(name, false, false); } catch { return(false); } } return(type != null && type.IsAssignableFrom(base.GetType())); }
internal bool CanCastToXmlType(string xmlTypeName, string xmlTypeNamespace) { Type type = SoapServices.GetInteropTypeFromXmlType(xmlTypeName, xmlTypeNamespace); if (type == (Type)null) { string typeNamespace; string assemblyName; if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlTypeNamespace, out typeNamespace, out assemblyName)) { return(false); } string name = typeNamespace == null || typeNamespace.Length <= 0 ? xmlTypeName : typeNamespace + "." + xmlTypeName; try { type = Assembly.Load(assemblyName).GetType(name, false, false); } catch { return(false); } } if (type != (Type)null) { return(type.IsAssignableFrom(this.GetType())); } return(false); }
/* public Type this [Element element] * { * } */ public Type GetType(string xmlName, string xmlNamespace) { Type type = null; string localName = XmlConvert.DecodeName(xmlName); string namespaceURI = XmlConvert.DecodeName(xmlNamespace); string typeNamespace, assemblyName; #if FIXED SoapServices.DecodeXmlNamespaceForClrTypeNamespace( xmlNamespace, out typeNamespace, out assemblyName); #else typeNamespace = null; assemblyName = null; #endif string typeName = (typeNamespace == null || typeNamespace == String.Empty) ? localName : typeNamespace + Type.Delimiter + localName; if (assemblyName != null && assemblyName != string.Empty && _binder != null) { type = _binder.BindToType(assemblyName, typeName); } if (type == null) { string assemblyQualifiedName = (string)xmlNodeToTypeTable[GetKey(xmlName, xmlNamespace)]; if (assemblyQualifiedName != null) { type = Type.GetType(assemblyQualifiedName); } else { type = Type.GetType(typeName); if (type == null) { if (assemblyName == null || assemblyName == String.Empty) { throw new SerializationException( String.Format("Parse Error, no assembly associated with XML key {0} {1}", localName, namespaceURI)); } type = FormatterServices.GetTypeFromAssembly( Assembly.Load(assemblyName), typeName); } } if (type == null) { throw new SerializationException(); } } return(type); }
string DecodeNamespace(string xmlNamespace) { string tns, tasm; if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlNamespace, out tns, out tasm)) { tns = xmlNamespace; } return(tns); }
[System.Security.SecuritySafeCritical] // auto-generated internal bool CanCastToXmlType(String xmlTypeName, String xmlTypeNamespace) { Type castType = SoapServices.GetInteropTypeFromXmlType(xmlTypeName, xmlTypeNamespace); if (castType == null) { String typeNamespace; String assemblyName; if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlTypeNamespace, out typeNamespace, out assemblyName)) { return(false); } String typeName; if ((typeNamespace != null) && (typeNamespace.Length > 0)) { typeName = typeNamespace + "." + xmlTypeName; } else { typeName = xmlTypeName; } try { Assembly asm = Assembly.Load(assemblyName); castType = asm.GetType(typeName, false, false); } catch { return(false); } } if (castType != null) { return(castType.IsAssignableFrom(this.GetType())); } return(false); } // CanCastToXmlType
private bool DeserializeMessage(ISoapMessage message) { string typeNamespace, assemblyName; if (xmlReader.Name == SoapTypeMapper.SoapEnvelopePrefix + ":Fault") { Deserialize(); return(false); } #if FIXED SoapServices.DecodeXmlNamespaceForClrTypeNamespace( xmlReader.NamespaceURI, out typeNamespace, out assemblyName); #endif message.MethodName = xmlReader.LocalName; message.XmlNameSpace = xmlReader.NamespaceURI; ArrayList paramNames = new ArrayList(); ArrayList paramValues = new ArrayList(); long paramValuesId = NextAvailableId; int[] indices = new int[1]; if (!xmlReader.IsEmptyElement) { int initialDepth = xmlReader.Depth; xmlReader.Read(); int i = 0; while (xmlReader.Depth > initialDepth) { long paramId, paramHref; object objParam = null; paramNames.Add(xmlReader.Name); Type paramType = null; if (message.ParamTypes != null) { if (i >= message.ParamTypes.Length) { throw new SerializationException("Not enough parameter types in SoapMessages"); } paramType = message.ParamTypes [i]; } indices[0] = i; objParam = DeserializeComponent( paramType, out paramId, out paramHref, paramValuesId, null, indices); indices[0] = paramValues.Add(objParam); if (paramHref != 0) { RecordFixup(paramValuesId, paramHref, paramValues.ToArray(), null, null, null, indices); } else if (paramId != 0) { // RegisterObject(paramId, objParam, null, paramValuesId, null, indices); } else { } i++; } xmlReader.ReadEndElement(); } else { xmlReader.Read(); } message.ParamNames = (string[])paramNames.ToArray(typeof(string)); message.ParamValues = paramValues.ToArray(); RegisterObject(paramValuesId, message.ParamValues, null, 0, null, null); return(true); }
// used by the server internal IMessage BuildMethodCallFromSoapMessage(SoapMessage soapMessage, string uri) { ArrayList headersList = new ArrayList(); Type[] signature = null; headersList.Add(new Header("__Uri", uri)); headersList.Add(new Header("__MethodName", soapMessage.MethodName)); string typeNamespace, assemblyName; if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(soapMessage.XmlNameSpace, out typeNamespace, out assemblyName)) { throw new RemotingException("Could not decode SoapMessage"); } // Note that we don't need to validate the type in // this place because MethodCall will do it anyway. if (assemblyName == null) // corlib { _serverType = Type.GetType(typeNamespace, true); } else { _serverType = Type.GetType(typeNamespace + ", " + assemblyName, true); } headersList.Add(new Header("__TypeName", _serverType.FullName, false)); if (soapMessage.Headers != null) { foreach (Header h in soapMessage.Headers) { headersList.Add(h); if (h.Name == "__MethodSignature") { signature = (Type[])h.Value; } } } _xmlNamespace = soapMessage.XmlNameSpace; //RemMessageType messageType; BindingFlags bflags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; if (signature == null) { _methodCallInfo = _serverType.GetMethod(soapMessage.MethodName, bflags); } else { _methodCallInfo = _serverType.GetMethod(soapMessage.MethodName, bflags, null, signature, null); } if (_methodCallInfo == null && (soapMessage.MethodName == "FieldSetter" || soapMessage.MethodName == "FieldGetter")) { _methodCallInfo = typeof(object).GetMethod(soapMessage.MethodName, bflags); } // the *out* parameters aren't serialized // have to add them here _methodCallParameters = _methodCallInfo.GetParameters(); object[] args = new object[_methodCallParameters.Length]; int sn = 0; for (int n = 0; n < _methodCallParameters.Length; n++) { ParameterInfo paramInfo = _methodCallParameters [n]; Type paramType = (paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType); if (paramInfo.IsOut && paramInfo.ParameterType.IsByRef) { args [n] = GetNullValue(paramType); } else { object val = soapMessage.ParamValues[sn++]; if (val is IConvertible) { args [n] = Convert.ChangeType(val, paramType); } else { args [n] = val; } } } headersList.Add(new Header("__Args", args, false)); Header[] headers = (Header[])headersList.ToArray(typeof(Header)); // build the MethodCall from the headers MethodCall mthCall = new MethodCall(headers); return((IMessage)mthCall); }
public static void Main(string[] args) { //<snippet101> // Convert a CLR namespace and assembly name into an XML namespace. string xmlNamespace = SoapServices.CodeXmlNamespaceForClrTypeNamespace( "ExampleNamespace", "AssemblyName"); Console.WriteLine("The name of the XML namespace is {0}.", xmlNamespace); //</snippet101> //<snippet102> // Extract a CLR namespace and assembly name from an XML namespace. string typeNamespace; string assemblyName; SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlNamespace, out typeNamespace, out assemblyName); Console.WriteLine("The name of the CLR namespace is {0}.", typeNamespace); Console.WriteLine("The name of the CLR assembly is {0}.", assemblyName); //</snippet102> //<snippet103> // Get the XML element name and the XML namespace for // an Interop type. string xmlElement; bool isSoapTypeAttribute = SoapServices.GetXmlElementForInteropType( typeof(ExampleNamespace.ExampleClass), out xmlElement, out xmlNamespace); // Print whether the requested value was flagged // with a SoapTypeAttribute. if (isSoapTypeAttribute) { Console.WriteLine( "The requested value was flagged " + "with the SoapTypeAttribute."); } else { Console.WriteLine( "The requested value was not flagged " + "with the SoapTypeAttribute."); } // Print the XML element and the XML namespace. Console.WriteLine( "The XML element for the type " + "ExampleNamespace.ExampleClass is {0}.", xmlElement); Console.WriteLine( "The XML namespace for the type " + "ExampleNamespace.ExampleClass is {0}.", xmlNamespace); //</snippet103> //<snippet104> // Get the XML type name and the XML type namespace for // an Interop type. string xmlTypeName; string xmlTypeNamespace; isSoapTypeAttribute = SoapServices.GetXmlTypeForInteropType( typeof(ExampleNamespace.ExampleClass), out xmlTypeName, out xmlTypeNamespace); // Print whether the requested value was flagged // with a SoapTypeAttribute. if (isSoapTypeAttribute) { Console.WriteLine( "The requested value was flagged " + "with the SoapTypeAttribute."); } else { Console.WriteLine( "The requested value was not flagged " + "with the SoapTypeAttribute."); } // Print the XML type name and the XML type namespace. Console.WriteLine( "The XML type for the type " + "ExampleNamespace.ExampleClass is {0}.", xmlTypeName); Console.WriteLine( "The XML type namespace for the type " + "ExampleNamespace.ExampleClass is {0}.", xmlTypeNamespace); //</snippet104> //<snippet105> // Print the XML namespace for a method invocation and its // response. System.Reflection.MethodBase getHelloMethod = typeof(ExampleNamespace.ExampleClass).GetMethod("GetHello"); string methodCallXmlNamespace = SoapServices.GetXmlNamespaceForMethodCall(getHelloMethod); string methodResponseXmlNamespace = SoapServices.GetXmlNamespaceForMethodResponse(getHelloMethod); Console.WriteLine( "The XML namespace for the invocation of the method " + "GetHello in ExampleClass is {0}.", methodResponseXmlNamespace); Console.WriteLine( "The XML namespace for the response of the method " + "GetHello in ExampleClass is {0}.", methodCallXmlNamespace); //</snippet105> //<snippet106> // Determine whether an XML namespace represents a CLR namespace. string clrNamespace = SoapServices.XmlNsForClrType; if (SoapServices.IsClrTypeNamespace(clrNamespace)) { Console.WriteLine( "The namespace {0} is a CLR namespace.", clrNamespace); } else { Console.WriteLine( "The namespace {0} is not a CLR namespace.", clrNamespace); } //</snippet106> //<snippet130> // Print the XML namespace for the CLR types. Console.WriteLine( "The XML namespace for the CLR types " + "is {0}.", SoapServices.XmlNsForClrType); //</snippet130> //<snippet131> // Print the XML namespace for the CLR types // that have an assembly but no common language runtime namespace. Console.WriteLine( "The XML namespace for the CLR types " + "that have an assembly but no namespace, is {0}.", SoapServices.XmlNsForClrTypeWithAssembly); //</snippet131> //<snippet132> // Print the XML namespace for the CLR types // that are a part of the Mscorlib.dll. Console.WriteLine( "The XML namespace for the CLR types " + "that are part of the Mscorlib.dll, is {0}.", SoapServices.XmlNsForClrTypeWithNs); //</snippet132> //<snippet133> // Print the XML namespace for the CLR types // that have both an assembly and a common language runtime // namespace. Console.WriteLine( "The XML namespace for the CLR types " + "that have both an assembly and a namespace, is {0}.", SoapServices.XmlNsForClrTypeWithNsAndAssembly); //</snippet133> //<snippet140> // Get the SOAP action for the method. System.Reflection.MethodBase getHelloMethodBase = typeof(ExampleNamespace.ExampleClass).GetMethod("GetHello"); string getHelloSoapAction = SoapServices.GetSoapActionFromMethodBase(getHelloMethodBase); Console.WriteLine( "The SOAP action for the method " + "ExampleClass.GetHello is {0}.", getHelloSoapAction); bool isSoapActionValid = SoapServices.IsSoapActionValidForMethodBase( getHelloSoapAction, getHelloMethodBase); if (isSoapActionValid) { Console.WriteLine( "The SOAP action, {0}, " + "is valid for ExampleClass.GetHello", getHelloSoapAction); } else { Console.WriteLine( "The SOAP action, {0}, " + "is not valid for ExampleClass.GetHello", getHelloSoapAction); } // Register the SOAP action for the GetHello method. SoapServices.RegisterSoapActionForMethodBase(getHelloMethodBase); // Get the type and the method names encoded into the SOAP action. string encodedTypeName; string encodedMethodName; SoapServices.GetTypeAndMethodNameFromSoapAction( getHelloSoapAction, out encodedTypeName, out encodedMethodName); Console.WriteLine( "The type name encoded in this SOAP action is {0}.", encodedTypeName); Console.WriteLine( "The method name encoded in this SOAP action is {0}.", encodedMethodName); //</snippet140> //<snippet150> // Get the name and the type of the field using its XML // element name and its XML namespace. For this query to work, // the containing type must be preloaded, and the XML element // name and the XML namespace must be explicitly declared on // the field using a SoapFieldAttribute. // Preload the containing type. SoapServices.PreLoad(typeof(ExampleNamespace.ExampleClass)); // Get the name and the type of a field that will be // serialized as an XML element. Type containingType = typeof(ExampleNamespace.ExampleClass); string xmlElementNamespace = "http://example.org/ExampleFieldNamespace"; string xmlElementName = "ExampleFieldElementName"; Type fieldType; string fieldName; SoapServices.GetInteropFieldTypeAndNameFromXmlElement( containingType, xmlElementName, xmlElementNamespace, out fieldType, out fieldName); Console.WriteLine( "The type of the field is {0}.", fieldType); Console.WriteLine( "The name of the field is {0}.", fieldName); // Get the name and the type of a field that will be // serialized as an XML attribute. string xmlAttributeNamespace = "http://example.org/ExampleAttributeNamespace"; string xmlAttributeName = "ExampleFieldAttributeName"; SoapServices.GetInteropFieldTypeAndNameFromXmlAttribute( containingType, xmlAttributeName, xmlAttributeNamespace, out fieldType, out fieldName); Console.WriteLine( "The type of the field is {0}.", fieldType); Console.WriteLine( "The name of the field is {0}.", fieldName); //</snippet150> //<snippet160> string interopTypeXmlElementName = "ExampleClassElementName"; string interopTypeXmlNamespace = "http://example.org/ExampleXmlNamespace"; Type interopType = SoapServices.GetInteropTypeFromXmlElement( interopTypeXmlElementName, interopTypeXmlNamespace); Console.WriteLine("The interop type is {0}.", interopType); string interopTypeXmlTypeName = "ExampleXmlTypeName"; string interopTypeXmlTypeNamespace = "http://example.org/ExampleXmlTypeNamespace"; interopType = SoapServices.GetInteropTypeFromXmlType( interopTypeXmlTypeName, interopTypeXmlTypeNamespace); Console.WriteLine("The interop type is {0}.", interopType); //</snippet160> //<snippet170> // Get the method base object for the GetHello method. System.Reflection.MethodBase methodBase = typeof(ExampleNamespace.ExampleClass).GetMethod("GetHello"); // Print its current SOAP action. Console.WriteLine( "The SOAP action for the method " + "ExampleClass.GetHello is {0}.", SoapServices.GetSoapActionFromMethodBase(methodBase)); // Set the SOAP action of the GetHello method to a new value. string newSoapAction = "http://example.org/ExampleSoapAction#NewSoapAction"; SoapServices.RegisterSoapActionForMethodBase( methodBase, newSoapAction); Console.WriteLine( "The SOAP action for the method " + "ExampleClass.GetHello is {0}.", SoapServices.GetSoapActionFromMethodBase(methodBase)); // Reset the SOAP action of the GetHello method to its default // value, which is determined using its SoapMethod attribute. SoapServices.RegisterSoapActionForMethodBase(methodBase); Console.WriteLine( "The SOAP action for the method " + "ExampleClass.GetHello is {0}.", SoapServices.GetSoapActionFromMethodBase(methodBase)); //</snippet170> //<snippet120> // Register all types in the assembly with the SoapType attribute. System.Reflection.Assembly executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); SoapServices.PreLoad(executingAssembly); //</snippet120> //<snippet121> // Register a specific type with the SoapType attribute. Type exampleType = typeof(ExampleNamespace.ExampleClass); SoapServices.PreLoad(exampleType); //</snippet121> //<snippet180> // Get the currently registered type for the given XML element // and namespace. string registeredXmlElementName = "ExampleClassElementName"; string registeredXmlNamespace = "http://example.org/ExampleXmlNamespace"; Type registeredType = SoapServices.GetInteropTypeFromXmlElement( registeredXmlElementName, registeredXmlNamespace); Console.WriteLine( "The registered interop type is {0}.", registeredType); // Register a new type for the XML element and namespace. SoapServices.RegisterInteropXmlElement( registeredXmlElementName, registeredXmlNamespace, typeof(String)); // Get the currently registered type for the given XML element // and namespace. registeredType = SoapServices.GetInteropTypeFromXmlElement( registeredXmlElementName, registeredXmlNamespace); Console.WriteLine( "The registered interop type is {0}.", registeredType); //</snippet180> //<snippet190> // Get the currently registered type for the given XML element // and namespace. string registeredXmlTypeName = "ExampleXmlTypeName"; string registeredXmlTypeNamespace = "http://example.org/ExampleXmlTypeNamespace"; registeredType = SoapServices.GetInteropTypeFromXmlType( registeredXmlTypeName, registeredXmlTypeNamespace); Console.WriteLine( "The registered interop type is {0}.", registeredType); // Register a new type for the XML element and namespace. SoapServices.RegisterInteropXmlType( registeredXmlTypeName, registeredXmlTypeNamespace, typeof(String)); // Get the currently registered type for the given XML element // and namespace. registeredType = SoapServices.GetInteropTypeFromXmlType( registeredXmlTypeName, registeredXmlTypeNamespace); Console.WriteLine( "The registered interop type is {0}.", registeredType); //</snippet190> }