/// <summary> /// When the SOAP extension is accessed for the first time, the XML Web /// service method it is applied to is accessed to store the file /// name passed in, using the corresponding SoapExtensionAttribute. /// </summary> /// <param name="methodInfo">The method being called.</param> /// <param name="attribute">Decorating attribute for the method.</param> /// <returns>An initializer object.</returns> /// <exception cref="ArgumentNullException">Thrown if /// <paramref name="methodInfo"/> is null.</exception> public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { if (methodInfo == null) { throw new ArgumentNullException("methodInfo"); } return methodInfo.DeclaringType; }
public SoapServerMethod(Type serverType, LogicalMethodInfo methodInfo) { this.methodInfo = methodInfo; // // Set up the XmlImporter, the SoapImporter, and acquire // the ServiceAttribute on the serverType for use in // creating a SoapReflectedMethod. // WebServiceAttribute serviceAttribute = WebServiceReflector.GetAttribute(serverType); string serviceNamespace = serviceAttribute.Namespace; bool serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(serverType); SoapReflectionImporter soapImporter = SoapReflector.CreateSoapImporter(serviceNamespace, serviceDefaultIsEncoded); XmlReflectionImporter xmlImporter = SoapReflector.CreateXmlImporter(serviceNamespace, serviceDefaultIsEncoded); // // Add some types relating to the methodInfo into the two importers // SoapReflector.IncludeTypes(methodInfo, soapImporter); WebMethodReflector.IncludeTypes(methodInfo, xmlImporter); // // Create a SoapReflectedMethod by reflecting on the // LogicalMethodInfo passed to us. // SoapReflectedMethod soapMethod = SoapReflector.ReflectMethod(methodInfo, false, xmlImporter, soapImporter, serviceNamespace); // // Most of the fields in this class are ----ed in from the reflected information // ImportReflectedMethod(soapMethod); ImportSerializers(soapMethod, GetServerTypeEvidence(serverType)); ImportHeaderSerializers(soapMethod); }
internal static string GetSoapMethodBinding(LogicalMethodInfo method) { string binding; object[] customAttributes = method.GetCustomAttributes(typeof(SoapDocumentMethodAttribute)); if (customAttributes.Length == 0) { customAttributes = method.GetCustomAttributes(typeof(SoapRpcMethodAttribute)); if (customAttributes.Length == 0) { binding = string.Empty; } else { binding = ((SoapRpcMethodAttribute) customAttributes[0]).Binding; } } else { binding = ((SoapDocumentMethodAttribute) customAttributes[0]).Binding; } if (method.Binding == null) { return binding; } if ((binding.Length > 0) && (binding != method.Binding.Name)) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebInvalidBindingName", new object[] { binding, method.Binding.Name })); } return method.Binding.Name; }
protected override MethodStubInfo CreateMethodStubInfo(TypeStubInfo parent, LogicalMethodInfo lmi, bool isClientProxy) { SoapMethodStubInfo res = null; object [] ats = lmi.GetCustomAttributes(typeof(SoapDocumentMethodAttribute)); if (ats.Length == 0) { ats = lmi.GetCustomAttributes(typeof(SoapRpcMethodAttribute)); } if (ats.Length == 0 && isClientProxy) { return(null); } else if (ats.Length == 0) { res = new SoapMethodStubInfo(parent, lmi, null, xmlImporter, soapImporter); } else { res = new SoapMethodStubInfo(parent, lmi, ats[0], xmlImporter, soapImporter); } methods_byaction [res.Action] = res; return(res); }
public override object GetInitializer (LogicalMethodInfo methodInfo) { LogicalTypeInfo sti = TypeStubManager.GetLogicalTypeInfo (methodInfo.DeclaringType); object[] ats = methodInfo.ReturnTypeCustomAttributeProvider.GetCustomAttributes (typeof(XmlRootAttribute), true); XmlRootAttribute root = ats.Length > 0 ? ats[0] as XmlRootAttribute : null; return new XmlSerializer (methodInfo.ReturnType, null, null, root, sti.GetWebServiceLiteralNamespace (sti.WebServiceNamespace)); }
internal static WebServiceBindingAttribute GetAttribute(LogicalMethodInfo methodInfo, string binding) { if (methodInfo.Binding != null) { if ((binding.Length > 0) && (methodInfo.Binding.Name != binding)) { throw new InvalidOperationException(Res.GetString("WebInvalidBindingName", new object[] { binding, methodInfo.Binding.Name })); } return methodInfo.Binding; } Type declaringType = methodInfo.DeclaringType; object[] customAttributes = declaringType.GetCustomAttributes(typeof(WebServiceBindingAttribute), false); WebServiceBindingAttribute attribute = null; foreach (WebServiceBindingAttribute attribute2 in customAttributes) { if (attribute2.Name == binding) { if (attribute != null) { throw new ArgumentException(Res.GetString("MultipleBindingsWithSameName2", new object[] { declaringType.FullName, binding, "methodInfo" })); } attribute = attribute2; } } if (((attribute == null) && (binding != null)) && (binding.Length > 0)) { throw new ArgumentException(Res.GetString("TypeIsMissingWebServiceBindingAttributeThat2", new object[] { declaringType.FullName, binding }), "methodInfo"); } return attribute; }
internal static object[] GetInitializers(LogicalMethodInfo[] methodInfos) { if (methodInfos.Length == 0) { return new object[0]; } WebServiceAttribute attribute = WebServiceReflector.GetAttribute(methodInfos); bool serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(WebServiceReflector.GetMostDerivedType(methodInfos)); XmlReflectionImporter importer = SoapReflector.CreateXmlImporter(attribute.Namespace, serviceDefaultIsEncoded); WebMethodReflector.IncludeTypes(methodInfos, importer); ArrayList list = new ArrayList(); bool[] flagArray = new bool[methodInfos.Length]; for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; Type returnType = methodInfo.ReturnType; if (IsSupported(returnType) && HttpServerProtocol.AreUrlParametersSupported(methodInfo)) { XmlAttributes attributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider); XmlTypeMapping mapping = importer.ImportTypeMapping(returnType, attributes.XmlRoot); mapping.SetKey(methodInfo.GetKey() + ":Return"); list.Add(mapping); flagArray[i] = true; } } if (list.Count == 0) { return new object[0]; } XmlMapping[] mappings = (XmlMapping[]) list.ToArray(typeof(XmlMapping)); Evidence evidenceForType = GetEvidenceForType(methodInfos[0].DeclaringType); TraceMethod caller = Tracing.On ? new TraceMethod(typeof(XmlReturn), "GetInitializers", methodInfos) : null; if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceCreateSerializer"), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", new object[] { mappings, evidenceForType })); } XmlSerializer[] serializerArray = null; if (AppDomain.CurrentDomain.IsHomogenous) { serializerArray = XmlSerializer.FromMappings(mappings); } else { serializerArray = XmlSerializer.FromMappings(mappings, evidenceForType); } if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceCreateSerializer"), caller); } object[] objArray = new object[methodInfos.Length]; int num2 = 0; for (int j = 0; j < objArray.Length; j++) { if (flagArray[j]) { objArray[j] = serializerArray[num2++]; } } return objArray; }
public SoapServerMethod (Type serverType, LogicalMethodInfo methodInfo) { TypeStubInfo type = TypeStubManager.GetTypeStub (serverType, "Soap"); info = type.GetMethod (methodInfo.Name) as SoapMethodStubInfo; if (info == null) throw new InvalidOperationException ("Argument methodInfo does not seem to be a member of the server type."); }
// See comment on the ServerProtocol.IsCacheUnderPressure method for explanation of the excludeSchemeHostPortFromCachingKey logic. internal DocumentationServerType(Type type, string uri, bool excludeSchemeHostPortFromCachingKey) : base(typeof(DocumentationServerProtocol)) { if (excludeSchemeHostPortFromCachingKey) { this.UriFixups = new List <Action <Uri> >(); } // // parse the uri from a string into a URI object // Uri uriObject = new Uri(uri, true); // // and get rid of the query string if there's one // uri = uriObject.GetLeftPart(UriPartial.Path); methodInfo = new LogicalMethodInfo(typeof(DocumentationServerProtocol).GetMethod("Documentation", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(this.UriFixups); reflector.Reflect(type, uri); schemas = reflector.Schemas; serviceDescriptions = reflector.ServiceDescriptions; schemasWithPost = reflector.SchemasWithPost; serviceDescriptionsWithPost = reflector.ServiceDescriptionsWithPost; }
internal static bool AreUrlParametersSupported(LogicalMethodInfo methodInfo) { if (methodInfo.OutParameters.Length > 0) { return(false); } ParameterInfo[] parameters = methodInfo.InParameters; for (int i = 0; i < parameters.Length; i++) { ParameterInfo parameter = parameters[i]; Type parameterType = parameter.ParameterType; if (parameterType.IsArray) { if (!ScalarFormatter.IsTypeSupported(parameterType.GetElementType())) { return(false); } } else { if (!ScalarFormatter.IsTypeSupported(parameterType)) { return(false); } } } return(true); }
internal static string GetSoapMethodBinding(LogicalMethodInfo method) { string binding; object[] attrs = method.GetCustomAttributes(typeof(SoapDocumentMethodAttribute)); if (attrs.Length == 0) { attrs = method.GetCustomAttributes(typeof(SoapRpcMethodAttribute)); if (attrs.Length == 0) { binding = string.Empty; } else { binding = ((SoapRpcMethodAttribute)attrs[0]).Binding; } } else { binding = ((SoapDocumentMethodAttribute)attrs[0]).Binding; } if (method.Binding != null) { if (binding.Length > 0 && binding != method.Binding.Name) { throw new InvalidOperationException(Res.GetString(Res.WebInvalidBindingName, binding, method.Binding.Name)); } return(method.Binding.Name); } return(binding); }
internal static void GenerateXmlMappings(Type type, ArrayList soapMethodList, string serviceNamespace, bool serviceDefaultIsEncoded, ArrayList mappings) { LogicalMethodInfo[] methodInfos = LogicalMethodInfo.Create(type.GetMethods(BindingFlags.Public | BindingFlags.Instance), LogicalMethodTypes.Sync); SoapReflectionImporter soapImporter = SoapReflector.CreateSoapImporter(serviceNamespace, serviceDefaultIsEncoded); XmlReflectionImporter xmlImporter = SoapReflector.CreateXmlImporter(serviceNamespace, serviceDefaultIsEncoded); WebMethodReflector.IncludeTypes(methodInfos, xmlImporter); SoapReflector.IncludeTypes(methodInfos, soapImporter); for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; SoapReflectedMethod soapMethod = SoapReflector.ReflectMethod(methodInfo, true, xmlImporter, soapImporter, serviceNamespace); if (soapMethod == null) { continue; } soapMethodList.Add(soapMethod); mappings.Add(soapMethod.requestMappings); if (soapMethod.responseMappings != null) { mappings.Add(soapMethod.responseMappings); } mappings.Add(soapMethod.inHeaderMappings); if (soapMethod.outHeaderMappings != null) { mappings.Add(soapMethod.outHeaderMappings); } } }
internal static string GetSoapMethodBinding(LogicalMethodInfo method) { string binding; object[] customAttributes = method.GetCustomAttributes(typeof(SoapDocumentMethodAttribute)); if (customAttributes.Length == 0) { customAttributes = method.GetCustomAttributes(typeof(SoapRpcMethodAttribute)); if (customAttributes.Length == 0) { binding = string.Empty; } else { binding = ((SoapRpcMethodAttribute)customAttributes[0]).Binding; } } else { binding = ((SoapDocumentMethodAttribute)customAttributes[0]).Binding; } if (method.Binding == null) { return(binding); } if ((binding.Length > 0) && (binding != method.Binding.Name)) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebInvalidBindingName", new object[] { binding, method.Binding.Name })); } return(method.Binding.Name); }
object Invoke(LogicalMethodInfo method, object[] parameters) { try { object server = CreateServerInstance(); try { object[] res = method.Invoke(server, parameters); if (!method.IsVoid) { return(res[0]); } else { return(null); } } finally { IDisposable disp = server as IDisposable; if (disp != null) { disp.Dispose(); } } } catch (TargetInvocationException ex) { throw ex.InnerException; } }
void BuildInitializers(FormatterKind formatter) { Hashtable types = new Hashtable(); foreach (HttpSimpleMethodStubInfo met in Methods) { AddType(types, met.GetFormatterInfo(formatter).Type, met); } foreach (DictionaryEntry ent in types) { Type t = (Type)ent.Key; ArrayList list = (ArrayList)ent.Value; LogicalMethodInfo[] mets = new LogicalMethodInfo [list.Count]; for (int n = 0; n < list.Count; n++) { mets[n] = ((MethodStubInfo)list[n]).MethodInfo; } object[] inits = MimeFormatter.GetInitializers(t, mets); for (int n = 0; n < list.Count; n++) { ((HttpSimpleMethodStubInfo)list[n]).GetFormatterInfo(formatter).Initializer = inits[n]; } } }
internal static WebServiceAttribute GetAttribute(LogicalMethodInfo[] methodInfos) { if (methodInfos.Length == 0) { return new WebServiceAttribute(); } return GetAttribute(GetMostDerivedType(methodInfos)); }
public override object GetInitializer(LogicalMethodInfo methodInfo) { if (methodInfo.IsVoid) { return(null); } return(this); }
public override object GetInitializer(LogicalMethodInfo methodInfo) { if (!IsSupported(methodInfo)) { return null; } return methodInfo.InParameters; }
public override object GetInitializer(LogicalMethodInfo methodInfo) { if (!ValueCollectionParameterReader.IsSupported(methodInfo)) { return null; } return methodInfo.InParameters; }
public virtual object[] GetInitializers (LogicalMethodInfo[] methodInfos) { object[] initializers = new object [methodInfos.Length]; for (int n=0; n<methodInfos.Length; n++) initializers [n] = GetInitializer (methodInfos[n]); return initializers; }
/// <include file='doc\ValueCollectionParameterReader.uex' path='docs/doc[@for="ValueCollectionParameterReader.GetInitializer"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override object GetInitializer(LogicalMethodInfo methodInfo) { if (!IsSupported(methodInfo)) { return(null); } return(methodInfo.InParameters); }
public override object GetInitializer(LogicalMethodInfo methodInfo) { if (methodInfo.IsVoid) { return null; } return this; }
internal static void IncludeTypes(LogicalMethodInfo[] methods, SoapReflectionImporter importer) { for (int i = 0; i < methods.Length; i++) { LogicalMethodInfo method = methods[i]; IncludeTypes(method, importer); } }
internal static object[] GetInitializers(LogicalMethodInfo methodInfo, SoapReflectedExtension[] extensions) { object[] objArray = new object[extensions.Length]; for (int i = 0; i < objArray.Length; i++) { objArray[i] = extensions[i].GetInitializer(methodInfo); } return(objArray); }
public override object GetInitializer(LogicalMethodInfo methodInfo) { LogicalTypeInfo sti = TypeStubManager.GetLogicalTypeInfo(methodInfo.DeclaringType); object[] ats = methodInfo.ReturnTypeCustomAttributeProvider.GetCustomAttributes(typeof(XmlRootAttribute), true); XmlRootAttribute root = ats.Length > 0 ? ats[0] as XmlRootAttribute : null; return(new XmlSerializer(methodInfo.ReturnType, null, null, root, sti.GetWebServiceLiteralNamespace(sti.WebServiceNamespace))); }
internal static void IncludeTypes(LogicalMethodInfo[] methods, SoapReflectionImporter importer) { for (int i = 0; i < methods.Length; i++) { LogicalMethodInfo method = methods[i]; importer.IncludeTypes(method.DeclaringType); importer.IncludeTypes(method.CustomAttributeProvider); } }
/// <include file='doc\ValueCollectionParameterReader.uex' path='docs/doc[@for="ValueCollectionParameterReader.IsSupported"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> static public bool IsSupported(LogicalMethodInfo methodInfo) { if (methodInfo.OutParameters.Length > 0) return false; ParameterInfo[] paramInfos = methodInfo.InParameters; for (int i = 0; i < paramInfos.Length; i++) if (!IsSupported(paramInfos[i])) return false; return true; }
public virtual object[] GetInitializers(LogicalMethodInfo[] methodInfos) { object[] objArray = new object[methodInfos.Length]; for (int i = 0; i < objArray.Length; i++) { objArray[i] = this.GetInitializer(methodInfos[i]); } return objArray; }
internal static object[] GetInitializers(LogicalMethodInfo methodInfo, SoapReflectedExtension[] extensions) { object[] objArray = new object[extensions.Length]; for (int i = 0; i < objArray.Length; i++) { objArray[i] = extensions[i].GetInitializer(methodInfo); } return objArray; }
/// <include file='doc\LogicalMethodInfo.uex' path='docs/doc[@for="LogicalMethodInfo.Create1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public static LogicalMethodInfo[] Create(MethodInfo[] methodInfos, LogicalMethodTypes types) { ArrayList begins = (types & LogicalMethodTypes.Async) != 0 ? new ArrayList() : null; Hashtable ends = (types & LogicalMethodTypes.Async) != 0 ? new Hashtable() : null; ArrayList syncs = (types & LogicalMethodTypes.Sync) != 0 ? new ArrayList() : null; for (int i = 0; i < methodInfos.Length; i++) { MethodInfo methodInfo = methodInfos[i]; if (IsBeginMethod(methodInfo)) { if (begins != null) { begins.Add(methodInfo); } } else if (IsEndMethod(methodInfo)) { if (ends != null) { ends.Add(methodInfo.Name, methodInfo); } } else { if (syncs != null) { syncs.Add(methodInfo); } } } int beginsCount = begins == null ? 0 : begins.Count; int syncsCount = syncs == null ? 0 : syncs.Count; int count = syncsCount + beginsCount; LogicalMethodInfo[] methods = new LogicalMethodInfo[count]; count = 0; for (int i = 0; i < syncsCount; i++) { methods[count++] = new LogicalMethodInfo((MethodInfo)syncs[i]); } for (int i = 0; i < beginsCount; i++) { MethodInfo beginMethodInfo = (MethodInfo)begins[i]; string endName = "End" + beginMethodInfo.Name.Substring(5); MethodInfo endMethodInfo = (MethodInfo)ends[endName]; if (endMethodInfo == null) { throw new InvalidOperationException(Res.GetString(Res.WebAsyncMissingEnd, beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, endName)); } methods[count++] = new LogicalMethodInfo(beginMethodInfo, endMethodInfo); } return(methods); }
internal HttpClientType(Type type) { LogicalMethodInfo[] methodInfos = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync); Hashtable formatterTypes = new Hashtable(); for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; try { object[] attributes = methodInfo.GetCustomAttributes(typeof(HttpMethodAttribute)); if (attributes.Length == 0) { continue; } HttpMethodAttribute attribute = (HttpMethodAttribute)attributes[0]; HttpClientMethod method = new HttpClientMethod(); method.readerType = attribute.ReturnFormatter; method.writerType = attribute.ParameterFormatter; method.methodInfo = methodInfo; AddFormatter(formatterTypes, method.readerType, method); AddFormatter(formatterTypes, method.writerType, method); methods.Add(methodInfo.Name, method); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } throw new InvalidOperationException(Res.GetString(Res.WebReflectionError, methodInfo.DeclaringType.FullName, methodInfo.Name), e); } } foreach (Type t in formatterTypes.Keys) { ArrayList list = (ArrayList)formatterTypes[t]; LogicalMethodInfo[] m = new LogicalMethodInfo[list.Count]; for (int j = 0; j < list.Count; j++) { m[j] = ((HttpClientMethod)list[j]).methodInfo; } object[] initializers = MimeFormatter.GetInitializers(t, m); bool isWriter = typeof(MimeParameterWriter).IsAssignableFrom(t); for (int j = 0; j < list.Count; j++) { if (isWriter) { ((HttpClientMethod)list[j]).writerInitializer = initializers[j]; } else { ((HttpClientMethod)list[j]).readerInitializer = initializers[j]; } } } }
internal static LogicalMethodInfo[] Create(System.Reflection.MethodInfo[] methodInfos, LogicalMethodTypes types, Hashtable declarations) { ArrayList list = ((types & LogicalMethodTypes.Async) != ((LogicalMethodTypes)0)) ? new ArrayList() : null; Hashtable hashtable = ((types & LogicalMethodTypes.Async) != ((LogicalMethodTypes)0)) ? new Hashtable() : null; ArrayList list2 = ((types & LogicalMethodTypes.Sync) != ((LogicalMethodTypes)0)) ? new ArrayList() : null; for (int i = 0; i < methodInfos.Length; i++) { System.Reflection.MethodInfo methodInfo = methodInfos[i]; if (IsBeginMethod(methodInfo)) { if (list != null) { list.Add(methodInfo); } } else if (IsEndMethod(methodInfo)) { if (hashtable != null) { hashtable.Add(methodInfo.Name, methodInfo); } } else if (list2 != null) { list2.Add(methodInfo); } } int num2 = (list == null) ? 0 : list.Count; int num3 = (list2 == null) ? 0 : list2.Count; int index = num3 + num2; LogicalMethodInfo[] infoArray = new LogicalMethodInfo[index]; index = 0; for (int j = 0; j < num3; j++) { System.Reflection.MethodInfo info2 = (System.Reflection.MethodInfo)list2[j]; WebMethod webMethod = (declarations == null) ? null : ((WebMethod)declarations[info2]); infoArray[index] = new LogicalMethodInfo(info2, webMethod); infoArray[index].CheckContractOverride(); index++; } for (int k = 0; k < num2; k++) { System.Reflection.MethodInfo beginMethodInfo = (System.Reflection.MethodInfo)list[k]; string str = "End" + beginMethodInfo.Name.Substring(5); System.Reflection.MethodInfo endMethodInfo = (System.Reflection.MethodInfo)hashtable[str]; if (endMethodInfo == null) { throw new InvalidOperationException(Res.GetString("WebAsyncMissingEnd", new object[] { beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, str })); } WebMethod method2 = (declarations == null) ? null : ((WebMethod)declarations[beginMethodInfo]); infoArray[index++] = new LogicalMethodInfo(beginMethodInfo, endMethodInfo, method2); } return(infoArray); }
internal HttpClientType(Type type) { LogicalMethodInfo[] infoArray = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync); Hashtable formatterTypes = new Hashtable(); for (int i = 0; i < infoArray.Length; i++) { LogicalMethodInfo info = infoArray[i]; try { object[] customAttributes = info.GetCustomAttributes(typeof(HttpMethodAttribute)); if (customAttributes.Length != 0) { HttpMethodAttribute attribute = (HttpMethodAttribute)customAttributes[0]; HttpClientMethod method = new HttpClientMethod { readerType = attribute.ReturnFormatter, writerType = attribute.ParameterFormatter, methodInfo = info }; AddFormatter(formatterTypes, method.readerType, method); AddFormatter(formatterTypes, method.writerType, method); this.methods.Add(info.Name, method); } } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } throw new InvalidOperationException(Res.GetString("WebReflectionError", new object[] { info.DeclaringType.FullName, info.Name }), exception); } } foreach (Type type2 in formatterTypes.Keys) { ArrayList list = (ArrayList)formatterTypes[type2]; LogicalMethodInfo[] methodInfos = new LogicalMethodInfo[list.Count]; for (int j = 0; j < list.Count; j++) { methodInfos[j] = ((HttpClientMethod)list[j]).methodInfo; } object[] initializers = MimeFormatter.GetInitializers(type2, methodInfos); bool flag = typeof(MimeParameterWriter).IsAssignableFrom(type2); for (int k = 0; k < list.Count; k++) { if (flag) { ((HttpClientMethod)list[k]).writerInitializer = initializers[k]; } else { ((HttpClientMethod)list[k]).readerInitializer = initializers[k]; } } } }
internal static void IncludeTypes(LogicalMethodInfo method, SoapReflectionImporter importer) { if (method.Declaration != null) { importer.IncludeTypes(method.Declaration.DeclaringType); importer.IncludeTypes(method.Declaration); } importer.IncludeTypes(method.DeclaringType); importer.IncludeTypes(method.CustomAttributeProvider); }
public SoapServerMethod(Type serverType, LogicalMethodInfo methodInfo) { TypeStubInfo type = TypeStubManager.GetTypeStub(serverType, "Soap"); info = type.GetMethod(methodInfo.Name) as SoapMethodStubInfo; if (info == null) { throw new InvalidOperationException("Argument methodInfo does not seem to be a member of the server type."); } }
internal HttpClientType(Type type) { LogicalMethodInfo[] infoArray = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync); Hashtable formatterTypes = new Hashtable(); for (int i = 0; i < infoArray.Length; i++) { LogicalMethodInfo info = infoArray[i]; try { object[] customAttributes = info.GetCustomAttributes(typeof(HttpMethodAttribute)); if (customAttributes.Length != 0) { HttpMethodAttribute attribute = (HttpMethodAttribute) customAttributes[0]; HttpClientMethod method = new HttpClientMethod { readerType = attribute.ReturnFormatter, writerType = attribute.ParameterFormatter, methodInfo = info }; AddFormatter(formatterTypes, method.readerType, method); AddFormatter(formatterTypes, method.writerType, method); this.methods.Add(info.Name, method); } } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } throw new InvalidOperationException(Res.GetString("WebReflectionError", new object[] { info.DeclaringType.FullName, info.Name }), exception); } } foreach (Type type2 in formatterTypes.Keys) { ArrayList list = (ArrayList) formatterTypes[type2]; LogicalMethodInfo[] methodInfos = new LogicalMethodInfo[list.Count]; for (int j = 0; j < list.Count; j++) { methodInfos[j] = ((HttpClientMethod) list[j]).methodInfo; } object[] initializers = MimeFormatter.GetInitializers(type2, methodInfos); bool flag = typeof(MimeParameterWriter).IsAssignableFrom(type2); for (int k = 0; k < list.Count; k++) { if (flag) { ((HttpClientMethod) list[k]).writerInitializer = initializers[k]; } else { ((HttpClientMethod) list[k]).readerInitializer = initializers[k]; } } } }
public override object GetInitializer(LogicalMethodInfo methodInfo) { if (methodInfo.OutParameters.Length > 0) { return(null); } else { return(methodInfo.Parameters); } }
internal DocumentationServerType(Type type, string uri) : base(typeof(DocumentationServerProtocol)) { uri = new Uri(uri, true).GetLeftPart(UriPartial.Path); this.methodInfo = new LogicalMethodInfo(typeof(DocumentationServerProtocol).GetMethod("Documentation", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)); ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(); reflector.Reflect(type, uri); this.schemas = reflector.Schemas; this.serviceDescriptions = reflector.ServiceDescriptions; this.schemasWithPost = reflector.SchemasWithPost; this.serviceDescriptionsWithPost = reflector.ServiceDescriptionsWithPost; }
public static bool IsSupported(LogicalMethodInfo methodInfo) { foreach (ParameterInfo param in methodInfo.Parameters) { if (!IsSupported(param)) { return(false); } } return(true); }
public override object GetInitializer (LogicalMethodInfo methodInfo) { LogicalTypeInfo sti = TypeStubManager.GetLogicalTypeInfo (methodInfo.DeclaringType); object[] ats = methodInfo.ReturnTypeCustomAttributeProvider.GetCustomAttributes (typeof(XmlRootAttribute), true); XmlRootAttribute root = ats.Length > 0 ? ats[0] as XmlRootAttribute : null; XmlReflectionImporter importer = new XmlReflectionImporter (); importer.IncludeTypes (methodInfo.CustomAttributeProvider); XmlTypeMapping map = importer.ImportTypeMapping (methodInfo.ReturnType, root, sti.GetWebServiceLiteralNamespace (sti.WebServiceNamespace)); return new XmlSerializer (map); }
private static string GetDefaultAction(string defaultNs, LogicalMethodInfo methodInfo) { string messageName = methodInfo.MethodAttribute.MessageName; if (messageName.Length == 0) { messageName = methodInfo.Name; } if (defaultNs.EndsWith("/", StringComparison.Ordinal)) { return (defaultNs + messageName); } return (defaultNs + "/" + messageName); }
public SoapServerMethod(Type serverType, LogicalMethodInfo methodInfo) { this.methodInfo = methodInfo; string defaultNs = WebServiceReflector.GetAttribute(serverType).Namespace; bool serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(serverType); SoapReflectionImporter importer = SoapReflector.CreateSoapImporter(defaultNs, serviceDefaultIsEncoded); XmlReflectionImporter importer2 = SoapReflector.CreateXmlImporter(defaultNs, serviceDefaultIsEncoded); SoapReflector.IncludeTypes(methodInfo, importer); WebMethodReflector.IncludeTypes(methodInfo, importer2); SoapReflectedMethod soapMethod = SoapReflector.ReflectMethod(methodInfo, false, importer2, importer, defaultNs); this.ImportReflectedMethod(soapMethod); this.ImportSerializers(soapMethod, this.GetServerTypeEvidence(serverType)); this.ImportHeaderSerializers(soapMethod); }
public override object GetInitializer(LogicalMethodInfo methodInfo) { LogicalTypeInfo sti = TypeStubManager.GetLogicalTypeInfo(methodInfo.DeclaringType); object[] ats = methodInfo.ReturnTypeCustomAttributeProvider.GetCustomAttributes(typeof(XmlRootAttribute), true); XmlRootAttribute root = ats.Length > 0 ? ats[0] as XmlRootAttribute : null; XmlReflectionImporter importer = new XmlReflectionImporter(); importer.IncludeTypes(methodInfo.CustomAttributeProvider); XmlTypeMapping map = importer.ImportTypeMapping(methodInfo.ReturnType, root, sti.GetWebServiceLiteralNamespace(sti.WebServiceNamespace)); return(new XmlSerializer(map)); }
internal static object[] GetInitializers(LogicalMethodInfo[] methodInfos) { if (methodInfos.Length == 0) return new object[0]; WebServiceAttribute serviceAttribute = WebServiceReflector.GetAttribute(methodInfos); bool serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(WebServiceReflector.GetMostDerivedType(methodInfos)); XmlReflectionImporter importer = SoapReflector.CreateXmlImporter(serviceAttribute.Namespace, serviceDefaultIsEncoded); WebMethodReflector.IncludeTypes(methodInfos, importer); ArrayList mappings = new ArrayList(); bool[] supported = new bool[methodInfos.Length]; for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; Type type = methodInfo.ReturnType; if (IsSupported(type) && HttpServerProtocol.AreUrlParametersSupported(methodInfo)) { XmlAttributes a = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider); XmlTypeMapping mapping = importer.ImportTypeMapping(type, a.XmlRoot); mapping.SetKey(methodInfo.GetKey() + ":Return"); mappings.Add(mapping); supported[i] = true; } } if (mappings.Count == 0) return new object[0]; XmlMapping[] xmlMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping)); Evidence evidence = GetEvidenceForType(methodInfos[0].DeclaringType); TraceMethod caller = Tracing.On ? new TraceMethod(typeof(XmlReturn), "GetInitializers", methodInfos) : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceCreateSerializer), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", xmlMappings, evidence)); XmlSerializer[] serializers = null; if (AppDomain.CurrentDomain.IsHomogenous) { serializers = XmlSerializer.FromMappings(xmlMappings); } else { #pragma warning disable 618 // If we're in a non-homogenous domain, legacy CAS mode is enabled, so passing through evidence will not fail serializers = XmlSerializer.FromMappings(xmlMappings, evidence); #pragma warning restore 618 } if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceCreateSerializer), caller); object[] initializers = new object[methodInfos.Length]; int count = 0; for (int i = 0; i < initializers.Length; i++) { if (supported[i]) { initializers[i] = serializers[count++]; } } return initializers; }
private static string GetDefaultAction(string defaultNs, LogicalMethodInfo methodInfo) { string messageName = methodInfo.MethodAttribute.MessageName; if (messageName.Length == 0) { messageName = methodInfo.Name; } if (defaultNs.EndsWith("/", StringComparison.Ordinal)) { return(defaultNs + messageName); } return(defaultNs + "/" + messageName); }
public HttpSimpleMethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source): base (parent, source) { object[] atts = source.CustomAttributeProvider.GetCustomAttributes (typeof(HttpMethodAttribute), true); if (atts.Length > 0) { HttpMethodAttribute at = (HttpMethodAttribute) atts[0]; ParameterWriterType = new MimeFormatterInfo (at.ParameterFormatter); ReturnReaderType = new MimeFormatterInfo (at.ReturnFormatter); } if (ReturnReaderType == null) { if (source.IsVoid) ReturnReaderType = new MimeFormatterInfo (typeof(NopReturnReader)); else ReturnReaderType = new MimeFormatterInfo (typeof(XmlReturnReader)); } }
static string GetDefaultAction(string defaultNs, LogicalMethodInfo methodInfo) { WebMethodAttribute methodAttribute = WebMethodReflector.GetAttribute(methodInfo); string messageName = methodAttribute.MessageName; if (messageName.Length == 0) { messageName = methodInfo.Name; } if (defaultNs.EndsWith("/")) { return(defaultNs + messageName); } return(defaultNs + "/" + messageName); }
// // Constructor // public MethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source) { TypeStub = parent; MethodInfo = source; object [] o = source.GetCustomAttributes (typeof (WebMethodAttribute)); if (o.Length > 0) { MethodAttribute = (WebMethodAttribute) o [0]; Name = MethodAttribute.MessageName; if (Name == "") Name = source.Name; } else Name = source.Name; }
/// <include file='doc\ValueCollectionParameterReader.uex' path='docs/doc[@for="ValueCollectionParameterReader.IsSupported"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> static public bool IsSupported(LogicalMethodInfo methodInfo) { if (methodInfo.OutParameters.Length > 0) { return(false); } ParameterInfo[] paramInfos = methodInfo.InParameters; for (int i = 0; i < paramInfos.Length; i++) { if (!IsSupported(paramInfos[i])) { return(false); } } return(true); }
public static bool IsSupported(LogicalMethodInfo methodInfo) { if (methodInfo.OutParameters.Length > 0) { return false; } ParameterInfo[] inParameters = methodInfo.InParameters; for (int i = 0; i < inParameters.Length; i++) { if (!IsSupported(inParameters[i])) { return false; } } return true; }
internal static string GetSoapMethodBinding(LogicalMethodInfo method) { object[] attrs = method.GetCustomAttributes(typeof(SoapDocumentMethodAttribute)); if (attrs.Length == 0) { attrs = method.GetCustomAttributes(typeof(SoapRpcMethodAttribute)); if (attrs.Length == 0) { return(string.Empty); } return(((SoapRpcMethodAttribute)attrs[0]).Binding); } else { return(((SoapDocumentMethodAttribute)attrs[0]).Binding); } }
internal static Type GetMostDerivedType(LogicalMethodInfo[] methodInfos) { if (methodInfos.Length == 0) { return null; } Type declaringType = methodInfos[0].DeclaringType; for (int i = 1; i < methodInfos.Length; i++) { Type type2 = methodInfos[i].DeclaringType; if (type2.IsSubclassOf(declaringType)) { declaringType = type2; } } return declaringType; }
internal static object GetSoapMethodAttribute(LogicalMethodInfo methodInfo) { object[] customAttributes = methodInfo.GetCustomAttributes(typeof(SoapRpcMethodAttribute)); object[] objArray2 = methodInfo.GetCustomAttributes(typeof(SoapDocumentMethodAttribute)); if (customAttributes.Length > 0) { if (objArray2.Length > 0) { throw new ArgumentException(System.Web.Services.Res.GetString("WebBothMethodAttrs"), "methodInfo"); } return customAttributes[0]; } if (objArray2.Length > 0) { return objArray2[0]; } return null; }
internal HttpClientType(Type type) { LogicalMethodInfo[] methodInfos = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync); Hashtable formatterTypes = new Hashtable(); for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; try { object[] attributes = methodInfo.GetCustomAttributes(typeof(HttpMethodAttribute)); if (attributes.Length == 0) continue; HttpMethodAttribute attribute = (HttpMethodAttribute)attributes[0]; HttpClientMethod method = new HttpClientMethod(); method.readerType = attribute.ReturnFormatter; method.writerType = attribute.ParameterFormatter; method.methodInfo = methodInfo; AddFormatter(formatterTypes, method.readerType, method); AddFormatter(formatterTypes, method.writerType, method); methods.Add(methodInfo.Name, method); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } throw new InvalidOperationException(Res.GetString(Res.WebReflectionError, methodInfo.DeclaringType.FullName, methodInfo.Name), e); } } foreach (Type t in formatterTypes.Keys) { ArrayList list = (ArrayList)formatterTypes[t]; LogicalMethodInfo[] m = new LogicalMethodInfo[list.Count]; for (int j = 0; j < list.Count; j++) m[j] = ((HttpClientMethod)list[j]).methodInfo; object[] initializers = MimeFormatter.GetInitializers(t, m); bool isWriter = typeof(MimeParameterWriter).IsAssignableFrom(t); for (int j = 0; j < list.Count; j++) { if (isWriter) { ((HttpClientMethod)list[j]).writerInitializer = initializers[j]; } else { ((HttpClientMethod)list[j]).readerInitializer = initializers[j]; } } } }
private void CheckForDuplicateMethods(LogicalMethodInfo[] methods) { Hashtable hashtable = new Hashtable(); foreach (LogicalMethodInfo info in methods) { string messageName = info.MethodAttribute.MessageName; if (messageName.Length == 0) { messageName = info.Name; } string key = (info.Binding == null) ? messageName : (info.Binding.Name + "." + messageName); LogicalMethodInfo info2 = (LogicalMethodInfo) hashtable[key]; if (info2 != null) { throw new InvalidOperationException(System.Web.Services.Res.GetString("BothAndUseTheMessageNameUseTheMessageName3", new object[] { info, info2, XmlConvert.EncodeLocalName(messageName) })); } hashtable.Add(key, info); } }
public override object[] GetInitializers (LogicalMethodInfo[] methodInfos) { XmlReflectionImporter importer = new XmlReflectionImporter (); XmlMapping[] sers = new XmlMapping [methodInfos.Length]; for (int n=0; n<sers.Length; n++) { LogicalMethodInfo metinfo = methodInfos[n]; if (metinfo.IsVoid) sers[n] = null; else { LogicalTypeInfo sti = TypeStubManager.GetLogicalTypeInfo (metinfo.DeclaringType); object[] ats = methodInfos[n].ReturnTypeCustomAttributeProvider.GetCustomAttributes (typeof(XmlRootAttribute), true); XmlRootAttribute root = ats.Length > 0 ? ats[0] as XmlRootAttribute : null; sers[n] = importer.ImportTypeMapping (methodInfos[n].ReturnType, root, sti.GetWebServiceLiteralNamespace (sti.WebServiceNamespace)); } } return XmlSerializer.FromMappings (sers); }
internal DiscoveryServerType(Type type, string uri) : base(typeof(DiscoveryServerProtocol)) { this.schemaTable = new Hashtable(); this.wsdlTable = new Hashtable(); uri = new Uri(uri, true).GetLeftPart(UriPartial.Path); this.methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)); ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(); reflector.Reflect(type, uri); XmlSchemas schemas = reflector.Schemas; this.description = reflector.ServiceDescription; XmlSerializer serializer = ServiceDescription.Serializer; this.AddSchemaImports(schemas, uri, reflector.ServiceDescriptions); for (int i = 1; i < reflector.ServiceDescriptions.Count; i++) { ServiceDescription description = reflector.ServiceDescriptions[i]; Import import = new Import { Namespace = description.TargetNamespace }; string key = "wsdl" + i.ToString(CultureInfo.InvariantCulture); import.Location = uri + "?wsdl=" + key; reflector.ServiceDescription.Imports.Add(import); this.wsdlTable.Add(key, description); } this.discoDoc = new DiscoveryDocument(); this.discoDoc.References.Add(new ContractReference(uri + "?wsdl", uri)); foreach (Service service in reflector.ServiceDescription.Services) { foreach (Port port in service.Ports) { SoapAddressBinding binding = (SoapAddressBinding) port.Extensions.Find(typeof(SoapAddressBinding)); if (binding != null) { System.Web.Services.Discovery.SoapBinding binding2 = new System.Web.Services.Discovery.SoapBinding { Binding = port.Binding, Address = binding.Location }; this.discoDoc.References.Add(binding2); } } } }