} // GetXmlNamespaceForMethodCall /// <include file='doc\Soap.uex' path='docs/doc[@for="SoapServices.GetXmlNamespaceForMethodResponse"]/*' /> public static String GetXmlNamespaceForMethodResponse(MethodBase mb) { SoapMethodAttribute attr = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb); return(attr.ResponseXmlNamespace); } // GetXmlNamespaceForMethodResponse
public static bool IsSoapActionValidForMethodBase(string soapAction, MethodBase mb) { bool flag; RuntimeModule runtimeModule; if (mb == null) { throw new ArgumentNullException("mb"); } if ((soapAction[0] == '"') && (soapAction[soapAction.Length - 1] == '"')) { soapAction = soapAction.Substring(1, soapAction.Length - 2); } SoapMethodAttribute cachedSoapAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); if (string.CompareOrdinal(cachedSoapAttribute.SoapAction, soapAction) == 0) { return(true); } string strA = (string)_methodBaseToSoapAction[mb]; if ((strA != null) && (string.CompareOrdinal(strA, soapAction) == 0)) { return(true); } string[] strArray = soapAction.Split(new char[] { '#' }); if (strArray.Length != 2) { return(false); } string typeNameForSoapActionNamespace = XmlNamespaceEncoder.GetTypeNameForSoapActionNamespace(strArray[0], out flag); if (typeNameForSoapActionNamespace == null) { return(false); } string str3 = strArray[1]; RuntimeMethodInfo info = mb as RuntimeMethodInfo; RuntimeConstructorInfo info2 = mb as RuntimeConstructorInfo; if (info != null) { runtimeModule = info.GetRuntimeModule(); } else { if (info2 == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeReflectionObject")); } runtimeModule = info2.GetRuntimeModule(); } string fullName = mb.DeclaringType.FullName; if (flag) { fullName = fullName + ", " + runtimeModule.GetRuntimeAssembly().GetSimpleName(); } return(fullName.Equals(typeNameForSoapActionNamespace) && mb.Name.Equals(str3)); }
public static void RegisterSoapActionForMethodBase(MethodBase mb) { SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); if (soapMethodAttribute.SoapActionExplicitySet) { SoapServices.RegisterSoapActionForMethodBase(mb, soapMethodAttribute.SoapAction); } }
public static void RegisterSoapActionForMethodBase(MethodBase mb) { SoapMethodAttribute cachedSoapAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute((object)mb); if (!cachedSoapAttribute.SoapActionExplicitySet) { return; } SoapServices.RegisterSoapActionForMethodBase(mb, cachedSoapAttribute.SoapAction); }
public static string GetSoapActionFromMethodBase(MethodBase mb) { string text = (string)SoapServices._methodBaseToSoapAction[mb]; if (text == null) { SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); text = soapMethodAttribute.SoapAction; } return(text); }
public static string GetSoapActionFromMethodBase(MethodBase mb) { string soapAction = (string)_methodBaseToSoapAction[mb]; if (soapAction == null) { SoapMethodAttribute cachedSoapAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); soapAction = cachedSoapAttribute.SoapAction; } return(soapAction); }
static string InternalGetSoapAction(MethodBase mb) { lock (_soapActions.SyncRoot) { string action = (string)_soapActions [mb]; if (action == null) { SoapMethodAttribute att = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); action = att.SoapAction; _soapActions [mb] = action; _soapActionsMethods [action] = mb; } return(action); } }
/// <summary>Gets an appropriate SOAP-related attribute for the specified class member or method parameter. </summary> /// <param name="reflectionObject">A class member or method parameter.</param> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" /> /// </PermissionSet> public static SoapAttribute GetCachedSoapAttribute(object reflectionObject) { object syncRoot = InternalRemotingServices._soapAttributes.SyncRoot; SoapAttribute result; lock (syncRoot) { SoapAttribute soapAttribute = InternalRemotingServices._soapAttributes[reflectionObject] as SoapAttribute; if (soapAttribute != null) { result = soapAttribute; } else { ICustomAttributeProvider customAttributeProvider = (ICustomAttributeProvider)reflectionObject; object[] customAttributes = customAttributeProvider.GetCustomAttributes(typeof(SoapAttribute), true); if (customAttributes.Length > 0) { soapAttribute = (SoapAttribute)customAttributes[0]; } else if (reflectionObject is Type) { soapAttribute = new SoapTypeAttribute(); } else if (reflectionObject is FieldInfo) { soapAttribute = new SoapFieldAttribute(); } else if (reflectionObject is MethodBase) { soapAttribute = new SoapMethodAttribute(); } else if (reflectionObject is ParameterInfo) { soapAttribute = new SoapParameterAttribute(); } soapAttribute.SetReflectionObject(reflectionObject); InternalRemotingServices._soapAttributes[reflectionObject] = soapAttribute; result = soapAttribute; } } return(result); }
private static string InternalGetSoapAction(MethodBase mb) { object syncRoot = SoapServices._soapActions.SyncRoot; string result; lock (syncRoot) { string text = (string)SoapServices._soapActions[mb]; if (text == null) { SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); text = soapMethodAttribute.SoapAction; SoapServices._soapActions[mb] = text; SoapServices._soapActionsMethods[text] = mb; } result = text; } return(result); }
public static SoapAttribute GetCachedSoapAttribute(object reflectionObject) { lock (_soapAttributes.SyncRoot) { SoapAttribute att = _soapAttributes [reflectionObject] as SoapAttribute; if (att != null) { return(att); } ICustomAttributeProvider ap = (ICustomAttributeProvider)reflectionObject; object[] atts = ap.GetCustomAttributes(typeof(SoapAttribute), true); if (atts.Length > 0) { att = (SoapAttribute)atts[0]; } else { if (reflectionObject is Type) { att = new SoapTypeAttribute(); } else if (reflectionObject is FieldInfo) { att = new SoapFieldAttribute(); } else if (reflectionObject is MethodBase) { att = new SoapMethodAttribute(); } else if (reflectionObject is ParameterInfo) { att = new SoapParameterAttribute(); } } att.SetReflectionObject(reflectionObject); _soapAttributes [reflectionObject] = att; return(att); } }
public virtual void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } if ((obj != null) && (obj != _rootObj)) { (new MessageSurrogate(_ss)).GetObjectData(obj, info, context); } else { IMethodReturnMessage msg = obj as IMethodReturnMessage; if (null != msg) { if (msg.Exception == null) { String responseElementName; String responseElementNS; String returnElementName; // obtain response element name namespace MethodBase mb = msg.MethodBase; SoapMethodAttribute attr = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); responseElementName = attr.ResponseXmlElementName; responseElementNS = attr.ResponseXmlNamespace; returnElementName = attr.ReturnXmlElementName; ArgMapper mapper = new ArgMapper(msg, true /*fOut*/); Object[] args = mapper.Args; info.FullTypeName = responseElementName; info.AssemblyName = responseElementNS; Type retType = ((MethodInfo)mb).ReturnType; if (!((retType == null) || (retType == _voidType))) { info.AddValue(returnElementName, msg.ReturnValue, retType); } if (args != null) { Type[] types = mapper.ArgTypes; for (int i = 0; i < args.Length; i++) { String name; name = mapper.GetArgName(i); if ((name == null) || (name.Length == 0)) { name = "__param" + i; } info.AddValue( name, args[i], types[i].IsByRef? types[i].GetElementType():types[i]); } } } else { Object oClientIsClr = CallContext.GetData("__ClientIsClr"); bool bClientIsClr = (oClientIsClr == null) ? true:(bool)oClientIsClr; info.FullTypeName = "FormatterWrapper"; info.AssemblyName = DefaultFakeRecordAssemblyName; Exception ex = msg.Exception; StringBuilder sb = new StringBuilder(); bool bMustUnderstandError = false; while (ex != null) { if (ex.Message.StartsWith("MustUnderstand")) { bMustUnderstandError = true; } sb.Append(" **** "); sb.Append(ex.GetType().FullName); sb.Append(" - "); sb.Append(ex.Message); ex = ex.InnerException; } ServerFault serverFault = null; if (bClientIsClr) { serverFault = new ServerFault(msg.Exception); // Clr is the Client use full exception } else { serverFault = new ServerFault(msg.Exception.GetType().AssemblyQualifiedName, sb.ToString(), msg.Exception.StackTrace); } String faultType = "Server"; if (bMustUnderstandError) { faultType = "MustUnderstand"; } SoapFault soapFault = new SoapFault(faultType, sb.ToString(), null, serverFault); info.AddValue("__WrappedObject", soapFault, _soapFaultType); } } else { IMethodCallMessage mcm = (IMethodCallMessage)obj; // obtain method namespace MethodBase mb = mcm.MethodBase; String methodElementNS = SoapServices.GetXmlNamespaceForMethodCall(mb); Object[] args = mcm.InArgs; String[] names = GetInArgNames(mcm, args.Length); Type[] sig = (Type[])mcm.MethodSignature; info.FullTypeName = mcm.MethodName; info.AssemblyName = methodElementNS; RemotingMethodCachedData cache = (RemotingMethodCachedData)InternalRemotingServices.GetReflectionCachedData(mb); int[] requestArgMap = cache.MarshalRequestArgMap; BCLDebug.Assert( args != null || sig.Length == args.Length, "Signature mismatch"); for (int i = 0; i < args.Length; i++) { String paramName = null; if ((names[i] == null) || (names[i].Length == 0)) { paramName = "__param" + i; } else { paramName = names[i]; } int sigPosition = requestArgMap[i]; Type argType = null; if (sig[sigPosition].IsByRef) { argType = sig[sigPosition].GetElementType(); } else { argType = sig[sigPosition]; } info.AddValue(paramName, args[i], argType); } } } } // GetObjectData
// Get the cached SOAP attribute data for an object. public static SoapAttribute GetCachedSoapAttribute(Object reflectionObject) { // Validate the paramter to ensure that it is a // legitimate reflection object. if (reflectionObject == null) { return(null); } else if (!(reflectionObject is MemberInfo) && !(reflectionObject is ParameterInfo)) { return(null); } lock (typeof(InternalRemotingServices)) { Object attr; Object[] attrs; // Look for a cached value from last time. if (attributeHash == null) { attributeHash = new Hashtable(); } else if ((attr = attributeHash[reflectionObject]) != null) { return(attr as SoapAttribute); } // Get the attribute information from the type. if (reflectionObject is Type) { attrs = ((Type)reflectionObject).GetCustomAttributes (typeof(SoapTypeAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapTypeAttribute(); } else { attr = attrs[0]; } } else if (reflectionObject is MethodBase) { attrs = ((MethodBase)reflectionObject) .GetCustomAttributes (typeof(SoapMethodAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapMethodAttribute(); } else { attr = attrs[0]; } } else if (reflectionObject is FieldInfo) { attrs = ((FieldInfo)reflectionObject) .GetCustomAttributes (typeof(SoapFieldAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapFieldAttribute(); } else { attr = attrs[0]; } } else if (reflectionObject is ParameterInfo) { attrs = ((ParameterInfo)reflectionObject) .GetCustomAttributes (typeof(SoapParameterAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapParameterAttribute(); } else { attr = attrs[0]; } } else { attrs = ((MemberInfo)reflectionObject) .GetCustomAttributes(typeof(SoapAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapAttribute(); } else { attr = attrs[0]; } } ((SoapAttribute)attr).SetReflectInfo(reflectionObject); return((SoapAttribute)attr); } }
[System.Security.SecurityCritical] // auto-generated public static bool IsSoapActionValidForMethodBase(String soapAction, MethodBase mb) { if (mb == null) { throw new ArgumentNullException("mb"); } // remove quotation marks if present if ((soapAction[0] == '"') && (soapAction[soapAction.Length - 1] == '"')) { soapAction = soapAction.Substring(1, soapAction.Length - 2); } // compare this to the soapAction on the method base SoapMethodAttribute attr = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb); if (String.CompareOrdinal(attr.SoapAction, soapAction) == 0) { return(true); } // check to see if a soap action value is registered for this String registeredSoapAction = (String)_methodBaseToSoapAction[mb]; if (registeredSoapAction != null) { if (String.CompareOrdinal(registeredSoapAction, soapAction) == 0) { return(true); } } // otherwise, parse SOAPAction and verify String typeName, methodName; String[] parts = soapAction.Split(new char[1] { '#' }); if (parts.Length == 2) { bool assemblyIncluded; typeName = XmlNamespaceEncoder.GetTypeNameForSoapActionNamespace( parts[0], out assemblyIncluded); if (typeName == null) { return(false); } methodName = parts[1]; // compare to values of method base ( RuntimeMethodInfo rmi = mb as RuntimeMethodInfo; RuntimeConstructorInfo rci = mb as RuntimeConstructorInfo; RuntimeModule rtModule; if (rmi != null) { rtModule = rmi.GetRuntimeModule(); } else if (rci != null) { rtModule = rci.GetRuntimeModule(); } else { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeReflectionObject")); } String actualTypeName = mb.DeclaringType.FullName; if (assemblyIncluded) { actualTypeName += ", " + rtModule.GetRuntimeAssembly().GetSimpleName(); } // return true if type and method name are the same return(actualTypeName.Equals(typeName) && mb.Name.Equals(methodName)); } else { return(false); } } // IsSoapActionValidForMethodBase
public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } if ((obj != null) && (obj != this._rootObj)) { new MessageSurrogate(this._ss).GetObjectData(obj, info, context); } else { IMethodReturnMessage mm = obj as IMethodReturnMessage; if (mm != null) { if (mm.Exception != null) { object data = CallContext.GetData("__ClientIsClr"); bool flag = (data == null) || ((bool)data); info.FullTypeName = "FormatterWrapper"; info.AssemblyName = this.DefaultFakeRecordAssemblyName; Exception innerException = mm.Exception; StringBuilder builder = new StringBuilder(); bool flag2 = false; while (innerException != null) { if (innerException.Message.StartsWith("MustUnderstand", StringComparison.Ordinal)) { flag2 = true; } builder.Append(" **** "); builder.Append(innerException.GetType().FullName); builder.Append(" - "); builder.Append(innerException.Message); innerException = innerException.InnerException; } ServerFault serverFault = null; if (flag) { serverFault = new ServerFault(mm.Exception); } else { serverFault = new ServerFault(mm.Exception.GetType().AssemblyQualifiedName, builder.ToString(), mm.Exception.StackTrace); } string faultCode = "Server"; if (flag2) { faultCode = "MustUnderstand"; } SoapFault fault2 = new SoapFault(faultCode, builder.ToString(), null, serverFault); info.AddValue("__WrappedObject", fault2, _soapFaultType); } else { MethodBase methodBase = mm.MethodBase; SoapMethodAttribute cachedSoapAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(methodBase); string responseXmlElementName = cachedSoapAttribute.ResponseXmlElementName; string responseXmlNamespace = cachedSoapAttribute.ResponseXmlNamespace; string returnXmlElementName = cachedSoapAttribute.ReturnXmlElementName; ArgMapper mapper = new ArgMapper(mm, true); object[] args = mapper.Args; info.FullTypeName = responseXmlElementName; info.AssemblyName = responseXmlNamespace; Type returnType = ((MethodInfo)methodBase).ReturnType; if ((returnType != null) && !(returnType == _voidType)) { info.AddValue(returnXmlElementName, mm.ReturnValue, returnType); } if (args != null) { Type[] argTypes = mapper.ArgTypes; for (int i = 0; i < args.Length; i++) { string argName = mapper.GetArgName(i); if ((argName == null) || (argName.Length == 0)) { argName = "__param" + i; } info.AddValue(argName, args[i], argTypes[i].IsByRef ? argTypes[i].GetElementType() : argTypes[i]); } } } } else { IMethodCallMessage m = (IMethodCallMessage)obj; MethodBase mb = m.MethodBase; string xmlNamespaceForMethodCall = SoapServices.GetXmlNamespaceForMethodCall(mb); object[] inArgs = m.InArgs; string[] inArgNames = this.GetInArgNames(m, inArgs.Length); Type[] methodSignature = (Type[])m.MethodSignature; info.FullTypeName = m.MethodName; info.AssemblyName = xmlNamespaceForMethodCall; int[] marshalRequestArgMap = InternalRemotingServices.GetReflectionCachedData(mb).MarshalRequestArgMap; for (int j = 0; j < inArgs.Length; j++) { string name = null; if ((inArgNames[j] == null) || (inArgNames[j].Length == 0)) { name = "__param" + j; } else { name = inArgNames[j]; } int index = marshalRequestArgMap[j]; Type type = null; if (methodSignature[index].IsByRef) { type = methodSignature[index].GetElementType(); } else { type = methodSignature[index]; } info.AddValue(name, inArgs[j], type); } } } }
public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } if (obj != null && obj != this._rootObj) { new MessageSurrogate(this._ss).GetObjectData(obj, info, context); } else { IMethodReturnMessage methodReturnMessage = obj as IMethodReturnMessage; if (methodReturnMessage != null) { if (methodReturnMessage.Exception == null) { MethodBase methodBase = methodReturnMessage.MethodBase; SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute((object)methodBase); string responseXmlElementName = soapMethodAttribute.ResponseXmlElementName; string responseXmlNamespace = soapMethodAttribute.ResponseXmlNamespace; string returnXmlElementName = soapMethodAttribute.ReturnXmlElementName; ArgMapper argMapper = new ArgMapper((IMethodMessage)methodReturnMessage, true); object[] args = argMapper.Args; info.FullTypeName = responseXmlElementName; info.AssemblyName = responseXmlNamespace; Type returnType = ((MethodInfo)methodBase).ReturnType; if (!(returnType == (Type)null) && !(returnType == SoapMessageSurrogate._voidType)) { info.AddValue(returnXmlElementName, methodReturnMessage.ReturnValue, returnType); } if (args == null) { return; } Type[] argTypes = argMapper.ArgTypes; for (int argNum = 0; argNum < args.Length; ++argNum) { string name = argMapper.GetArgName(argNum); if (name == null || name.Length == 0) { name = "__param" + (object)argNum; } info.AddValue(name, args[argNum], argTypes[argNum].IsByRef ? argTypes[argNum].GetElementType() : argTypes[argNum]); } } else { object data = CallContext.GetData("__ClientIsClr"); bool flag1 = data == null || (bool)data; info.FullTypeName = "FormatterWrapper"; info.AssemblyName = this.DefaultFakeRecordAssemblyName; Exception exception = methodReturnMessage.Exception; StringBuilder stringBuilder = new StringBuilder(); bool flag2 = false; for (; exception != null; exception = exception.InnerException) { if (exception.Message.StartsWith("MustUnderstand", StringComparison.Ordinal)) { flag2 = true; } stringBuilder.Append(" **** "); stringBuilder.Append(exception.GetType().FullName); stringBuilder.Append(" - "); stringBuilder.Append(exception.Message); } ServerFault serverFault = !flag1 ? new ServerFault(methodReturnMessage.Exception.GetType().AssemblyQualifiedName, stringBuilder.ToString(), methodReturnMessage.Exception.StackTrace) : new ServerFault(methodReturnMessage.Exception); string faultCode = "Server"; if (flag2) { faultCode = "MustUnderstand"; } SoapFault soapFault = new SoapFault(faultCode, stringBuilder.ToString(), (string)null, serverFault); info.AddValue("__WrappedObject", (object)soapFault, SoapMessageSurrogate._soapFaultType); } } else { IMethodCallMessage m = (IMethodCallMessage)obj; MethodBase methodBase = m.MethodBase; string namespaceForMethodCall = SoapServices.GetXmlNamespaceForMethodCall(methodBase); object[] inArgs = m.InArgs; string[] inArgNames = this.GetInArgNames(m, inArgs.Length); Type[] typeArray = (Type[])m.MethodSignature; info.FullTypeName = m.MethodName; info.AssemblyName = namespaceForMethodCall; int[] marshalRequestArgMap = InternalRemotingServices.GetReflectionCachedData(methodBase).MarshalRequestArgMap; for (int index1 = 0; index1 < inArgs.Length; ++index1) { string name = inArgNames[index1] == null || inArgNames[index1].Length == 0 ? "__param" + (object)index1 : inArgNames[index1]; int index2 = marshalRequestArgMap[index1]; Type type = !typeArray[index2].IsByRef ? typeArray[index2] : typeArray[index2].GetElementType(); info.AddValue(name, inArgs[index1], type); } } } }
public static string GetXmlNamespaceForMethodCall(MethodBase mb) { SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); return(soapMethodAttribute.XmlNamespace); }
} // GetSoapActionFromMethodBase /// <include file='doc\Soap.uex' path='docs/doc[@for="SoapServices.IsSoapActionValidForMethodBase"]/*' /> public static bool IsSoapActionValidForMethodBase(String soapAction, MethodBase mb) { // remove quotation marks if present if ((soapAction[0] == '"') && (soapAction[soapAction.Length - 1] == '"')) { soapAction = soapAction.Substring(1, soapAction.Length - 2); } // compare this to the soapAction on the method base SoapMethodAttribute attr = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb); if (String.CompareOrdinal(attr.SoapAction, soapAction) == 0) { return(true); } // check to see if a soap action value is registered for this String registeredSoapAction = (String)_methodBaseToSoapAction[mb]; if (registeredSoapAction != null) { if (String.CompareOrdinal(registeredSoapAction, soapAction) == 0) { return(true); } } // otherwise, parse SOAPAction and verify String typeName, methodName; String[] parts = soapAction.Split(new char[1] { '#' }); if (parts.Length == 2) { bool assemblyIncluded; typeName = XmlNamespaceEncoder.GetTypeNameForSoapActionNamespace( parts[0], out assemblyIncluded); if (typeName == null) { return(false); } methodName = parts[1]; // compare to values of method base (FUTURE: Use more direct method for this) Type type = mb.DeclaringType; String actualTypeName = type.FullName; if (assemblyIncluded) { actualTypeName += ", " + type.Module.Assembly.nGetSimpleName(); } // return true if type and method name are the same return(actualTypeName.Equals(typeName) && mb.Name.Equals(methodName)); } else { return(false); } } // IsSoapActionValidForMethodBase