private LogicalMethodInfo(System.Reflection.MethodInfo beginMethodInfo, System.Reflection.MethodInfo endMethodInfo, WebMethod webMethod) { this.methodInfo = beginMethodInfo; this.endMethodInfo = endMethodInfo; this.methodName = beginMethodInfo.Name.Substring(5); if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } ParameterInfo[] parameters = beginMethodInfo.GetParameters(); if (((parameters.Length < 2) || (parameters[parameters.Length - 1].ParameterType != typeof(object))) || (parameters[parameters.Length - 2].ParameterType != typeof(AsyncCallback))) { throw new InvalidOperationException(Res.GetString("WebMethodMissingParams", new object[] { beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, typeof(AsyncCallback).FullName, typeof(object).FullName })); } this.stateParam = parameters[parameters.Length - 1]; this.callbackParam = parameters[parameters.Length - 2]; this.inParams = GetInParameters(beginMethodInfo, parameters, 0, parameters.Length - 2, true); ParameterInfo[] paramInfos = endMethodInfo.GetParameters(); this.resultParam = paramInfos[0]; this.outParams = GetOutParameters(endMethodInfo, paramInfos, 1, paramInfos.Length - 1, true); this.parameters = new ParameterInfo[this.inParams.Length + this.outParams.Length]; this.inParams.CopyTo(this.parameters, 0); this.outParams.CopyTo(this.parameters, this.inParams.Length); this.retType = endMethodInfo.ReturnType; this.isVoid = this.retType == typeof(void); this.attributes = new Hashtable(); }
protected override bool ReflectMethod() { soapMethod = ReflectionContext[Method] as SoapReflectedMethod; if (soapMethod == null) { soapMethod = SoapReflector.ReflectMethod(Method, false, ReflectionImporter, SoapImporter, DefaultNamespace); ReflectionContext[Method] = soapMethod; soapMethod.portType = Binding != null ? Binding.Type : null; } WebMethodAttribute methodAttr = WebMethodReflector.GetAttribute(Method); OperationBinding.Extensions.Add(CreateSoapOperationBinding(soapMethod.rpc ? SoapBindingStyle.Rpc : SoapBindingStyle.Document, soapMethod.action)); CreateMessage(soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, InputMessage, OperationBinding.Input, soapMethod.requestMappings); if (!soapMethod.oneWay) { CreateMessage(soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, OutputMessage, OperationBinding.Output, soapMethod.responseMappings); } CreateHeaderMessages(soapMethod.name, soapMethod.use, soapMethod.inHeaderMappings, soapMethod.outHeaderMappings, soapMethod.headers); if (soapMethod.rpc && soapMethod.methodInfo.OutParameters.Length > 0) { Operation.ParameterOrder = GetParameterOrder(soapMethod.methodInfo); } AllowExtensionsToReflectMethod(); return(true); }
public LogicalMethodInfo(LogicalTypeInfo typeInfo, MethodInfo method) { _typeInfo = typeInfo; _methodInfo = method; _wma = (WebMethodAttribute)Attribute.GetCustomAttribute(method, typeof(WebMethodAttribute)); _sma = (ScriptMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ScriptMethodAttribute)); if (_sma == null) { _sma = ScriptMethodAttribute.Default; } _params = MethodInfo.GetParameters(); if (HasParameters) { _paramMap = new Dictionary <string, int> (_params.Length, StringComparer.Ordinal); for (int i = 0; i < _params.Length; i++) { _paramMap.Add(_params[i].Name, i); } } if (ScriptMethod.ResponseFormat == ResponseFormat.Xml && MethodInfo.ReturnType != typeof(void)) { Type retType = MethodInfo.ReturnType; if (Type.GetTypeCode(retType) != TypeCode.String || ScriptMethod.XmlSerializeString) { _xmlSer = new XmlSerializer(retType); } } }
protected override bool ReflectMethod() { this.soapMethod = base.ReflectionContext[base.Method] as SoapReflectedMethod; if (this.soapMethod == null) { this.soapMethod = SoapReflector.ReflectMethod(base.Method, false, base.ReflectionImporter, this.SoapImporter, base.DefaultNamespace); base.ReflectionContext[base.Method] = this.soapMethod; this.soapMethod.portType = (base.Binding != null) ? base.Binding.Type : null; } WebMethodAttribute methodAttribute = base.Method.MethodAttribute; base.OperationBinding.Extensions.Add(this.CreateSoapOperationBinding(this.soapMethod.rpc ? SoapBindingStyle.Rpc : SoapBindingStyle.Document, this.soapMethod.action)); this.CreateMessage(this.soapMethod.rpc, this.soapMethod.use, this.soapMethod.paramStyle, base.InputMessage, base.OperationBinding.Input, this.soapMethod.requestMappings); if (!this.soapMethod.oneWay) { this.CreateMessage(this.soapMethod.rpc, this.soapMethod.use, this.soapMethod.paramStyle, base.OutputMessage, base.OperationBinding.Output, this.soapMethod.responseMappings); } this.CreateHeaderMessages(this.soapMethod.name, this.soapMethod.use, this.soapMethod.inHeaderMappings, this.soapMethod.outHeaderMappings, this.soapMethod.headers, this.soapMethod.rpc); if ((this.soapMethod.rpc && (this.soapMethod.use == SoapBindingUse.Encoded)) && (this.soapMethod.methodInfo.OutParameters.Length > 0)) { base.Operation.ParameterOrder = GetParameterOrder(this.soapMethod.methodInfo); } this.AllowExtensionsToReflectMethod(); return(true); }
public virtual WebMethodContract ResolveMethod(MethodInfo method) { if (_contracts.ContainsKey(method)) { return(_contracts[method] as WebMethodContract); } WebMethodAttribute attribute = method.GetCustomAttribute <WebMethodAttribute>() ?? new WebMethodAttribute(); ParameterInfo[] parameters = method.GetParameters(); WebMethodContract contract = new WebMethodContract(method) { Method = attribute.Method, Name = string.IsNullOrWhiteSpace(attribute.Name) ? method.Name : attribute.Name, Version = attribute.Version, Return = ResolveReturn(method.ReturnParameter), Parameters = method.GetParameters().Select(p => ResolveParameter(p)).ToArray(), RequiresKey = attribute.RequireKey, HasOptions = parameters.LastOrDefault()?.ParameterType == typeof(RequestOptions) || (parameters.LastOrDefault()?.ParameterType?.IsSubclassOf(typeof(RequestOptions)) ?? false), CanInvoke = method.ReturnType == typeof(void) || method.ReturnType == typeof(Task) || method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>) }; _contracts[method] = contract; return(contract); }
/// <summary> /// Initializes the current context and sets various members to the values supplied in parameters /// Also checks whether the app token is valid and whether the current user is authorized to access the called web method /// </summary> /// <param name="appToken">Application token supplied by the client</param> /// <param name="userToken">User token supplied by the client</param> /// <param name="userName">Current user name</param> /// <param name="failInNoApp">Whether to throw an exception if no approved application is found to match the token</param> /// public static void Initialize(string appToken, string userToken) { if (Current != null) { return; } using (ApplicationDataContext dataContext = new ApplicationDataContext()) { Current = new BrokerContext(); Current.ActivityId = Guid.NewGuid(); Current.ApplicationToken = appToken; Current.UserToken = userToken; Current.UserName = Security.CurrentUser; Application currentApplication = dataContext.Applications.SingleOrDefault(app => app.Token == appToken && app.IsApproved == true); if (currentApplication != null) { Current.ApplicationId = currentApplication.ApplicationId; Current.ApplicationName = currentApplication.Name; } else { throw new InvalidTokenException(appToken, userToken); } // Now find if current user is authorized to access the current method if (System.Web.HttpContext.Current != null) { var ctx = System.Web.HttpContext.Current; // Search up the stack to find the Method's message name System.Reflection.MethodBase method = null; for (int i = 1; true; i++) { StackFrame stackFrame = new StackFrame(i); method = stackFrame.GetMethod(); if (method == null || method.IsDefined(typeof(WebMethodAttribute), false) && method.DeclaringType.IsSubclassOf(typeof(System.Web.Services.WebService))) { break; } } if (method != null) { // Now get the method's message name WebMethodAttribute webMethodAttribute = (from attr in method.GetCustomAttributes(typeof(WebMethodAttribute), false) select attr).First() as WebMethodAttribute; Current.WebMethodMessageName = string.IsNullOrEmpty(webMethodAttribute.MessageName) ? method.Name : webMethodAttribute.MessageName; bool isAuthorized = System.Web.Security.UrlAuthorizationModule.CheckUrlAccessForPrincipal( string.Format("{0}/{1}", System.Web.HttpContext.Current.Request.Path, Current.WebMethodMessageName), System.Web.HttpContext.Current.User, "GET" ); if (!isAuthorized) { Console.Write("not authoriced exception" + Current.WebMethodMessageName); throw new System.Security.Authentication.AuthenticationException(); } } } } }
public WebMethodDef(WebServiceDef wsDef, MethodInfo method, WebMethodAttribute wmAttribute, ScriptMethodAttribute smAttribute, TransactionalMethodAttribute tmAttribute, ETagMethodAttribute emAttribute) { this.MethodType = method; this.WebMethodAtt = wmAttribute; this.ScriptMethodAtt = smAttribute; this.TransactionAtt = tmAttribute; if (null != emAttribute) { this.IsETagEnabled = emAttribute.Enabled; } if (wmAttribute != null && !string.IsNullOrEmpty(wmAttribute.MessageName)) { this.MethodName = wmAttribute.MessageName; } else { this.MethodName = method.Name; } // HTTP GET method is allowed only when there's a [ScriptMethod] attribute and UseHttpGet is true this.IsGetAllowed = (this.ScriptMethodAtt != null && this.ScriptMethodAtt.UseHttpGet); this.ResponseFormat = (this.ScriptMethodAtt != null ? this.ScriptMethodAtt.ResponseFormat : ResponseFormat.Json); MethodInfo beginMethod = wsDef.WSType.GetMethod("Begin" + method.Name, BINDING_FLAGS); if (null != beginMethod) { // The BeginXXX method must have the [ScriptMethod] attribute object[] scriptMethodAttributes = beginMethod.GetCustomAttributes(typeof(ScriptMethodAttribute), false); if (scriptMethodAttributes.Length > 0) { // Asynchronous methods found for the function this.HasAsyncMethods = true; this.BeginMethod = new WebMethodDef(wsDef, beginMethod, null, null, null, null); MethodInfo endMethod = wsDef.WSType.GetMethod("End" + method.Name, BINDING_FLAGS); this.EndMethod = new WebMethodDef(wsDef, endMethod, null, null, null, null); // get all parameters of begin web method and then leave last two parameters in the input parameters list because // last two parameters are for AsyncCallback and Async State ParameterInfo[] allParameters = beginMethod.GetParameters(); ParameterInfo[] inputParameters = new ParameterInfo[allParameters.Length - 2]; Array.Copy(allParameters, inputParameters, allParameters.Length - 2); this.BeginMethod.InputParameters = new List <ParameterInfo>(inputParameters); this.BeginMethod.InputParametersWithAsyc = new List <ParameterInfo>(allParameters); } } this.InputParameters = new List <ParameterInfo>(method.GetParameters()); }
// Methods internal WebServiceMethodData(WebServiceData owner, MethodInfo methodInfo, WebMethodAttribute webMethodAttribute, ScriptMethodAttribute scriptMethodAttribute) { this._owner = owner; this._methodInfo = methodInfo; this._webMethodAttribute = webMethodAttribute; this._methodName = this._webMethodAttribute.MessageName; this._scriptMethodAttribute = scriptMethodAttribute; if (string.IsNullOrEmpty(this._methodName)) { this._methodName = methodInfo.Name; } }
internal WebServiceMethodData(WebServiceData owner, MethodInfo methodInfo, WebMethodAttribute webMethodAttribute, ScriptMethodAttribute scriptMethodAttribute) { _owner = owner; _methodInfo = methodInfo; _webMethodAttribute = webMethodAttribute; _methodName = _webMethodAttribute.MessageName; _scriptMethodAttribute = scriptMethodAttribute; if (String.IsNullOrEmpty(_methodName)) { _methodName = methodInfo.Name; } }
public void TestConstructors() { WebMethodAttribute attribute; attribute = new WebMethodAttribute(); Assert.AreEqual(true, attribute.BufferResponse); Assert.AreEqual(0, attribute.CacheDuration); Assert.AreEqual(String.Empty, attribute.Description); Assert.AreEqual(false, attribute.EnableSession); Assert.AreEqual(String.Empty, attribute.MessageName); Assert.AreEqual(TransactionOption.Disabled, attribute.TransactionOption); }
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); }
static string GetDefaultAction(string defaultNs, LogicalMethodInfo methodInfo) { WebMethodAttribute methodAttribute = methodInfo.MethodAttribute; string messageName = methodAttribute.MessageName; if (messageName.Length == 0) { messageName = methodInfo.Name; } if (defaultNs.EndsWith("/", StringComparison.Ordinal)) { return(defaultNs + messageName); } return(defaultNs + "/" + messageName); }
public void UsesExistingWebMethodAttributeWithDecoratedMethod() { wse.ObjectName = "UsesExistingWebMethodAttributeWithDecoratedMethod"; wse.TargetName = "decoratedService"; wse.AfterPropertiesSet(); Type proxyType = wse.GetExportedType(); MethodInfo method = proxyType.GetMethod("SomeMethod"); Assert.IsNotNull(method); object[] attrs = method.GetCustomAttributes(typeof(WebMethodAttribute), true); Assert.IsNotEmpty(attrs); Assert.AreEqual(1, attrs.Length); WebMethodAttribute wma = attrs[0] as WebMethodAttribute; Assert.AreEqual("SomeMethod description", wma.Description); }
/// <summary> /// 获取web函数 /// </summary> /// <param name="type"></param> /// <returns></returns> public void Load(Type type) { Dictionary <string, FastInvokeHandler> dic = new Dictionary <string, FastInvokeHandler>(StringComparer.OrdinalIgnoreCase); MethodInfo[] methods = type.GetMethods(FastValueGetSet.AllBindingFlags); foreach (MethodInfo info in methods) { string key = GetMethodInfoKey(info); WebMethodAttribute att = info.GetCustomAttribute(typeof(WebMethodAttribute)) as WebMethodAttribute; if (att != null) { FastInvokeHandler handle = FastInvoke.GetMethodInvoker(info); dic[key] = handle; } } _dicMethods = dic; }
public void OverridesExistingWebMethodAttributeWithDecoratedMethod() { wse.ObjectName = "OverridesExistingWebMethodAttributeWithDecoratedMethod"; wse.TargetName = "decoratedService"; wse.MemberAttributes.Add("SomeMethod", new WebMethodAttribute(true)); // default value is false wse.AfterPropertiesSet(); Type proxyType = wse.GetExportedType(); MethodInfo method = proxyType.GetMethod("SomeMethod"); Assert.IsNotNull(method); object[] attrs = method.GetCustomAttributes(typeof(WebMethodAttribute), true); Assert.IsNotEmpty(attrs); Assert.AreEqual(1, attrs.Length); WebMethodAttribute wma = attrs[0] as WebMethodAttribute; Assert.AreEqual(true, wma.EnableSession); }
void CheckForDuplicateMethods(LogicalMethodInfo[] methods) { Hashtable messageNames = new Hashtable(); foreach (LogicalMethodInfo method in methods) { WebMethodAttribute attribute = WebMethodReflector.GetAttribute(method); string messageName = attribute.MessageName; if (messageName.Length == 0) { messageName = method.Name; } LogicalMethodInfo existingMethod = (LogicalMethodInfo)messageNames[messageName]; if (existingMethod != null) { throw new InvalidOperationException(Res.GetString(Res.BothAndUseTheMessageNameUseTheMessageName3, method, existingMethod, messageName)); } messageNames.Add(messageName, method); } }
// // 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; } }
void CheckForDuplicateMethods(LogicalMethodInfo[] methods) { Hashtable messageNames = new Hashtable(); foreach (LogicalMethodInfo method in methods) { WebMethodAttribute attribute = method.MethodAttribute; string messageName = attribute.MessageName; if (messageName.Length == 0) { messageName = method.Name; } string key = method.Binding == null ? messageName : method.Binding.Name + "." + messageName; LogicalMethodInfo existingMethod = (LogicalMethodInfo)messageNames[key]; if (existingMethod != null) { throw new InvalidOperationException(Res.GetString(Res.BothAndUseTheMessageNameUseTheMessageName3, method, existingMethod, XmlConvert.EncodeLocalName(messageName))); } messageNames.Add(key, method); } }
internal LogicalMethodInfo(System.Reflection.MethodInfo methodInfo, WebMethod webMethod) { if (methodInfo.IsStatic) { throw new InvalidOperationException(Res.GetString("WebMethodStatic", new object[] { methodInfo.Name })); } this.methodInfo = methodInfo; if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } System.Reflection.MethodInfo info = (this.declaration != null) ? this.declaration : methodInfo; this.parameters = info.GetParameters(); this.inParams = GetInParameters(info, this.parameters, 0, this.parameters.Length, false); this.outParams = GetOutParameters(info, this.parameters, 0, this.parameters.Length, false); this.retType = info.ReturnType; this.isVoid = this.retType == typeof(void); this.methodName = info.Name; this.attributes = new Hashtable(); }
public AsmxLogicalMethodInfo(LogicalTypeInfo typeInfo, MethodInfo method) : base(typeInfo, method) { _typeInfo = typeInfo; _wma = (WebMethodAttribute)Attribute.GetCustomAttribute(method, typeof(WebMethodAttribute)); _sma = (ScriptMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ScriptMethodAttribute)); if (_sma == null) { _sma = ScriptMethodAttribute.Default; } if (ScriptMethod.ResponseFormat == ResponseFormat.Xml && MethodInfo.ReturnType != typeof(void)) { Type retType = MethodInfo.ReturnType; if (Type.GetTypeCode(retType) != TypeCode.String || ScriptMethod.XmlSerializeString) { _xmlSer = new XmlSerializer(retType); } } }
LogicalMethodInfo(MethodInfo beginMethodInfo, MethodInfo endMethodInfo, WebMethod webMethod) { this.methodInfo = beginMethodInfo; this.endMethodInfo = endMethodInfo; methodName = beginMethodInfo.Name.Substring(5); if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } ParameterInfo[] beginParamInfos = beginMethodInfo.GetParameters(); if (beginParamInfos.Length < 2 || beginParamInfos[beginParamInfos.Length - 1].ParameterType != typeof(object) || beginParamInfos[beginParamInfos.Length - 2].ParameterType != typeof(AsyncCallback)) { throw new InvalidOperationException(Res.GetString(Res.WebMethodMissingParams, beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, typeof(AsyncCallback).FullName, typeof(object).FullName)); } stateParam = beginParamInfos[beginParamInfos.Length - 1]; callbackParam = beginParamInfos[beginParamInfos.Length - 2]; inParams = GetInParameters(beginMethodInfo, beginParamInfos, 0, beginParamInfos.Length - 2, true); ParameterInfo[] endParamInfos = endMethodInfo.GetParameters(); resultParam = endParamInfos[0]; outParams = GetOutParameters(endMethodInfo, endParamInfos, 1, endParamInfos.Length - 1, true); parameters = new ParameterInfo[inParams.Length + outParams.Length]; inParams.CopyTo(parameters, 0); outParams.CopyTo(parameters, inParams.Length); retType = endMethodInfo.ReturnType; isVoid = retType == typeof(void); attributes = new Hashtable(); }
internal LogicalMethodInfo(MethodInfo methodInfo, WebMethod webMethod) { if (methodInfo.IsStatic) { throw new InvalidOperationException(Res.GetString(Res.WebMethodStatic, methodInfo.Name)); } this.methodInfo = methodInfo; if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } MethodInfo methodDefinition = declaration != null ? declaration : methodInfo; parameters = methodDefinition.GetParameters(); inParams = GetInParameters(methodDefinition, parameters, 0, parameters.Length, false); outParams = GetOutParameters(methodDefinition, parameters, 0, parameters.Length, false); retType = methodDefinition.ReturnType; isVoid = retType == typeof(void); methodName = methodDefinition.Name; attributes = new Hashtable(); }
private static void MethodHandler(this ExpressApplication app, string urlPrefix, Func <object> serviceInstance, MethodInfo method, WebMethodAttribute meta) { // TODO support WebMethodAttribute options (caching, etc) var invoke = DynamicMethods.CompileMethod(method.DeclaringType, method); var parameters = method.GetParameters(); if (parameters.Length == 0) { app.Get( Combine(urlPrefix, method.Name), req => { req.SetContext(); var result = invoke(serviceInstance(), new object[0]); req.Json(result); }); } else { app.Get( Combine(urlPrefix, method.Name), req => { req.SetContext(); var args = ParseQueryArgs(req, parameters); var result = invoke(serviceInstance(), args); req.Json(result); }); app.Post( Combine(urlPrefix, method.Name), req => { req.SetContext(); var args = ParseArgs(req, parameters); var result = invoke(serviceInstance(), args); req.Json(result); }); } }
void MoveToMethod(LogicalMethodInfo method) { this.method = method; this.methodAttr = WebMethodReflector.GetAttribute(method); }
private void MoveToMethod(LogicalMethodInfo method) { this.method = method; this.methodAttr = method.MethodAttribute; }
internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs) { try { SoapReflectedMethod soapMethod = new SoapReflectedMethod(); MethodAttribute methodAttribute = new MethodAttribute(); object serviceAttr = GetSoapServiceAttribute(methodInfo.DeclaringType); bool serviceDefaultIsEncoded = ServiceDefaultIsEncoded(serviceAttr); object methodAttr = GetSoapMethodAttribute(methodInfo); if (methodAttr == null) { if (client) { return(null); // method attribute required on the client } if (serviceAttr is SoapRpcServiceAttribute) { methodAttr = new SoapRpcMethodAttribute(); } else { methodAttr = new SoapDocumentMethodAttribute(); } } if (methodAttr is SoapRpcMethodAttribute) { SoapRpcMethodAttribute attr = (SoapRpcMethodAttribute)methodAttr; soapMethod.rpc = true; soapMethod.use = SoapBindingUse.Encoded; soapMethod.oneWay = attr.OneWay; methodAttribute.action = attr.Action; methodAttribute.binding = attr.Binding; methodAttribute.requestName = attr.RequestElementName; methodAttribute.requestNs = attr.RequestNamespace; methodAttribute.responseName = attr.ResponseElementName; methodAttribute.responseNs = attr.ResponseNamespace; } else { SoapDocumentMethodAttribute attr = (SoapDocumentMethodAttribute)methodAttr; soapMethod.rpc = false; soapMethod.use = attr.Use; soapMethod.paramStyle = attr.ParameterStyle; soapMethod.oneWay = attr.OneWay; methodAttribute.action = attr.Action; methodAttribute.binding = attr.Binding; methodAttribute.requestName = attr.RequestElementName; methodAttribute.requestNs = attr.RequestNamespace; methodAttribute.responseName = attr.ResponseElementName; methodAttribute.responseNs = attr.ResponseNamespace; if (soapMethod.use == SoapBindingUse.Default) { if (serviceAttr is SoapDocumentServiceAttribute) { soapMethod.use = ((SoapDocumentServiceAttribute)serviceAttr).Use; } if (soapMethod.use == SoapBindingUse.Default) { soapMethod.use = SoapBindingUse.Literal; } } if (soapMethod.paramStyle == SoapParameterStyle.Default) { if (serviceAttr is SoapDocumentServiceAttribute) { soapMethod.paramStyle = ((SoapDocumentServiceAttribute)serviceAttr).ParameterStyle; } if (soapMethod.paramStyle == SoapParameterStyle.Default) { soapMethod.paramStyle = SoapParameterStyle.Wrapped; } } } if (methodAttribute.binding.Length > 0) { if (client) { throw new InvalidOperationException(Res.GetString(Res.WebInvalidBindingPlacement, methodAttr.GetType().Name)); } soapMethod.binding = WebServiceBindingReflector.GetAttribute(methodInfo, methodAttribute.binding); } WebMethodAttribute webMethodAttribute = WebMethodReflector.GetAttribute(methodInfo); soapMethod.name = webMethodAttribute.MessageName; if (soapMethod.name.Length == 0) { soapMethod.name = methodInfo.Name; } string requestElementName; if (soapMethod.rpc) { requestElementName = methodInfo.Name; } else { requestElementName = methodAttribute.requestName.Length == 0 ? soapMethod.name : methodAttribute.requestName; } string requestNamespace = methodAttribute.requestNs; if (requestNamespace == null) { if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0) { requestNamespace = soapMethod.binding.Namespace; } else { requestNamespace = defaultNs; } } string responseElementName = methodAttribute.responseName.Length == 0 ? soapMethod.name + "Response": methodAttribute.responseName; string responseNamespace = methodAttribute.responseNs; if (responseNamespace == null) { if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0) { responseNamespace = soapMethod.binding.Namespace; } else { responseNamespace = defaultNs; } } SoapParameterInfo[] inParameters = ReflectParameters(methodInfo.InParameters, requestNamespace); SoapParameterInfo[] outParameters = ReflectParameters(methodInfo.OutParameters, responseNamespace); soapMethod.action = methodAttribute.action; if (soapMethod.action == null) { soapMethod.action = GetDefaultAction(defaultNs, methodInfo); } soapMethod.methodInfo = methodInfo; if (soapMethod.oneWay) { if (outParameters.Length > 0) { throw new ArgumentException(Res.GetString(Res.WebOneWayOutParameters), "methodInfo"); } if (methodInfo.ReturnType != typeof(void)) { throw new ArgumentException(Res.GetString(Res.WebOneWayReturnValue), "methodInfo"); } } XmlReflectionMember[] members = new XmlReflectionMember[inParameters.Length]; for (int i = 0; i < members.Length; i++) { SoapParameterInfo soapParamInfo = inParameters[i]; XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = soapParamInfo.parameterInfo.Name; member.MemberType = soapParamInfo.parameterInfo.ParameterType; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } member.XmlAttributes = soapParamInfo.xmlAttributes; member.SoapAttributes = soapParamInfo.soapAttributes; members[i] = member; } soapMethod.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, requestElementName, requestNamespace, methodAttribute.requestNs == null, members, true); if (GetSoapServiceRoutingStyle(serviceAttr) == SoapServiceRoutingStyle.RequestElement && soapMethod.paramStyle == SoapParameterStyle.Bare && soapMethod.requestMappings.Count != 1) { throw new ArgumentException(Res.GetString(Res.WhenUsingAMessageStyleOfParametersAsDocument0), "methodInfo"); } string elementName = ""; string elementNamespace = ""; if (soapMethod.paramStyle == SoapParameterStyle.Bare) { if (soapMethod.requestMappings.Count == 1) { elementName = soapMethod.requestMappings[0].ElementName; elementNamespace = soapMethod.requestMappings[0].Namespace; } // else: can't route on request element -- we match on an empty qname, // normal rules apply for duplicates } else { elementName = soapMethod.requestMappings.ElementName; elementNamespace = soapMethod.requestMappings.Namespace; } soapMethod.requestElementName = new XmlQualifiedName(elementName, elementNamespace); if (!soapMethod.oneWay) { int numOutParams = outParameters.Length; int count = 0; CodeIdentifiers identifiers = null; if (methodInfo.ReturnType != typeof(void)) { numOutParams++; count = 1; identifiers = new CodeIdentifiers(); } members = new XmlReflectionMember[numOutParams]; for (int i = 0; i < outParameters.Length; i++) { SoapParameterInfo soapParamInfo = outParameters[i]; XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = soapParamInfo.parameterInfo.Name; member.MemberType = soapParamInfo.parameterInfo.ParameterType; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } member.XmlAttributes = soapParamInfo.xmlAttributes; member.SoapAttributes = soapParamInfo.soapAttributes; members[count++] = member; if (identifiers != null) { identifiers.Add(member.MemberName, null); } } if (methodInfo.ReturnType != typeof(void)) { XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = identifiers.MakeUnique(soapMethod.name + "Result"); member.MemberType = methodInfo.ReturnType; member.IsReturnValue = true; member.XmlAttributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider); member.XmlAttributes.XmlRoot = null; // Ignore XmlRoot attribute used by get/post member.SoapAttributes = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider); members[0] = member; } soapMethod.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, responseElementName, responseNamespace, methodAttribute.responseNs == null, members, false); } SoapExtensionAttribute[] extensionAttributes = (SoapExtensionAttribute[])methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute)); soapMethod.extensions = new SoapReflectedExtension[extensionAttributes.Length]; for (int i = 0; i < extensionAttributes.Length; i++) { soapMethod.extensions[i] = new SoapReflectedExtension(extensionAttributes[i].ExtensionType, extensionAttributes[i]); } Array.Sort(soapMethod.extensions); SoapHeaderAttribute[] headerAttributes = (SoapHeaderAttribute[])methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute)); Array.Sort(headerAttributes, new SoapHeaderAttributeComparer()); Hashtable headerTypes = new Hashtable(); soapMethod.headers = new SoapReflectedHeader[headerAttributes.Length]; int front = 0; int back = soapMethod.headers.Length; ArrayList inHeaders = new ArrayList(); ArrayList outHeaders = new ArrayList(); for (int i = 0; i < soapMethod.headers.Length; i++) { SoapHeaderAttribute headerAttribute = headerAttributes[i]; SoapReflectedHeader soapHeader = new SoapReflectedHeader(); Type declaringType = methodInfo.DeclaringType; if ((soapHeader.memberInfo = declaringType.GetField(headerAttribute.MemberName)) != null) { soapHeader.headerType = ((FieldInfo)soapHeader.memberInfo).FieldType; } else if ((soapHeader.memberInfo = declaringType.GetProperty(headerAttribute.MemberName)) != null) { soapHeader.headerType = ((PropertyInfo)soapHeader.memberInfo).PropertyType; } else { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderMissing); } if (soapHeader.headerType.IsArray) { soapHeader.headerType = soapHeader.headerType.GetElementType(); soapHeader.repeats = true; if (soapHeader.headerType != typeof(SoapUnknownHeader) && soapHeader.headerType != typeof(SoapHeader)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType); } } if (MemberHelper.IsStatic(soapHeader.memberInfo)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderStatic); } if (!MemberHelper.CanRead(soapHeader.memberInfo)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderRead); } if (!MemberHelper.CanWrite(soapHeader.memberInfo)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderWrite); } if (!typeof(SoapHeader).IsAssignableFrom(soapHeader.headerType)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType); } SoapHeaderDirection direction = headerAttribute.Direction; if (soapMethod.oneWay && (direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderOneWayOut); } if (headerTypes.Contains(soapHeader.headerType)) { SoapHeaderDirection prevDirection = (SoapHeaderDirection)headerTypes[soapHeader.headerType]; if ((prevDirection & direction) != 0) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebMultiplyDeclaredHeaderTypes); } headerTypes[soapHeader.headerType] = direction | prevDirection; } else { headerTypes[soapHeader.headerType] = direction; } if (soapHeader.headerType != typeof(SoapHeader) && soapHeader.headerType != typeof(SoapUnknownHeader)) { XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = soapHeader.headerType.Name; member.MemberType = soapHeader.headerType; member.OverrideIsNullable = true; if ((direction & SoapHeaderDirection.In) != 0) { inHeaders.Add(member); } if ((direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0) { outHeaders.Add(member); } soapHeader.custom = true; } soapHeader.direction = direction; // Put generic header mappings at the end of the list so they are found last during header processing if (!soapHeader.custom) { soapMethod.headers[--back] = soapHeader; } else { soapMethod.headers[front++] = soapHeader; } } soapMethod.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, "InHeaders", defaultNs, true, (XmlReflectionMember[])inHeaders.ToArray(typeof(XmlReflectionMember)), false); if (!soapMethod.oneWay) { soapMethod.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, "OutHeaders", defaultNs, true, (XmlReflectionMember[])outHeaders.ToArray(typeof(XmlReflectionMember)), false); } return(soapMethod); } catch (Exception e) { throw new InvalidOperationException(Res.GetString(Res.WebReflectionErrorMethod, methodInfo.DeclaringType.Name, methodInfo.Name), e); } }
internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs) { SoapReflectedMethod method2; try { string str2; string str4; string key = methodInfo.GetKey(); SoapReflectedMethod method = new SoapReflectedMethod(); MethodAttribute attribute = new MethodAttribute(); object soapServiceAttribute = GetSoapServiceAttribute(methodInfo.DeclaringType); bool serviceDefaultIsEncoded = ServiceDefaultIsEncoded(soapServiceAttribute); object soapMethodAttribute = GetSoapMethodAttribute(methodInfo); if (soapMethodAttribute == null) { if (client) { return(null); } if (soapServiceAttribute is SoapRpcServiceAttribute) { SoapRpcMethodAttribute attribute2 = new SoapRpcMethodAttribute { Use = ((SoapRpcServiceAttribute)soapServiceAttribute).Use }; soapMethodAttribute = attribute2; } else if (soapServiceAttribute is SoapDocumentServiceAttribute) { SoapDocumentMethodAttribute attribute3 = new SoapDocumentMethodAttribute { Use = ((SoapDocumentServiceAttribute)soapServiceAttribute).Use }; soapMethodAttribute = attribute3; } else { soapMethodAttribute = new SoapDocumentMethodAttribute(); } } if (soapMethodAttribute is SoapRpcMethodAttribute) { SoapRpcMethodAttribute attribute4 = (SoapRpcMethodAttribute)soapMethodAttribute; method.rpc = true; method.use = attribute4.Use; method.oneWay = attribute4.OneWay; attribute.action = attribute4.Action; attribute.binding = attribute4.Binding; attribute.requestName = attribute4.RequestElementName; attribute.requestNs = attribute4.RequestNamespace; attribute.responseName = attribute4.ResponseElementName; attribute.responseNs = attribute4.ResponseNamespace; } else { SoapDocumentMethodAttribute attribute5 = (SoapDocumentMethodAttribute)soapMethodAttribute; method.rpc = false; method.use = attribute5.Use; method.paramStyle = attribute5.ParameterStyle; method.oneWay = attribute5.OneWay; attribute.action = attribute5.Action; attribute.binding = attribute5.Binding; attribute.requestName = attribute5.RequestElementName; attribute.requestNs = attribute5.RequestNamespace; attribute.responseName = attribute5.ResponseElementName; attribute.responseNs = attribute5.ResponseNamespace; if (method.use == SoapBindingUse.Default) { if (soapServiceAttribute is SoapDocumentServiceAttribute) { method.use = ((SoapDocumentServiceAttribute)soapServiceAttribute).Use; } if (method.use == SoapBindingUse.Default) { method.use = SoapBindingUse.Literal; } } if (method.paramStyle == SoapParameterStyle.Default) { if (soapServiceAttribute is SoapDocumentServiceAttribute) { method.paramStyle = ((SoapDocumentServiceAttribute)soapServiceAttribute).ParameterStyle; } if (method.paramStyle == SoapParameterStyle.Default) { method.paramStyle = SoapParameterStyle.Wrapped; } } } if (attribute.binding.Length > 0) { if (client) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebInvalidBindingPlacement", new object[] { soapMethodAttribute.GetType().Name })); } method.binding = WebServiceBindingReflector.GetAttribute(methodInfo, attribute.binding); } WebMethodAttribute methodAttribute = methodInfo.MethodAttribute; method.name = methodAttribute.MessageName; if (method.name.Length == 0) { method.name = methodInfo.Name; } if (method.rpc) { str2 = ((attribute.requestName.Length == 0) || !client) ? methodInfo.Name : attribute.requestName; } else { str2 = (attribute.requestName.Length == 0) ? method.name : attribute.requestName; } string requestNs = attribute.requestNs; if (requestNs == null) { if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0)) { requestNs = method.binding.Namespace; } else { requestNs = defaultNs; } } if (method.rpc && (method.use != SoapBindingUse.Encoded)) { str4 = methodInfo.Name + "Response"; } else { str4 = (attribute.responseName.Length == 0) ? (method.name + "Response") : attribute.responseName; } string responseNs = attribute.responseNs; if (responseNs == null) { if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0)) { responseNs = method.binding.Namespace; } else { responseNs = defaultNs; } } SoapParameterInfo[] infoArray = ReflectParameters(methodInfo.InParameters, requestNs); SoapParameterInfo[] infoArray2 = ReflectParameters(methodInfo.OutParameters, responseNs); method.action = attribute.action; if (method.action == null) { method.action = GetDefaultAction(defaultNs, methodInfo); } method.methodInfo = methodInfo; if (method.oneWay) { if (infoArray2.Length > 0) { throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayOutParameters"), "methodInfo"); } if (methodInfo.ReturnType != typeof(void)) { throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayReturnValue"), "methodInfo"); } } XmlReflectionMember[] members = new XmlReflectionMember[infoArray.Length]; for (int i = 0; i < members.Length; i++) { SoapParameterInfo info = infoArray[i]; XmlReflectionMember member = new XmlReflectionMember { MemberName = info.parameterInfo.Name, MemberType = info.parameterInfo.ParameterType }; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } member.XmlAttributes = info.xmlAttributes; member.SoapAttributes = info.soapAttributes; members[i] = member; } method.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str2, requestNs, attribute.requestNs == null, members, true, false, key, client); if (((GetSoapServiceRoutingStyle(soapServiceAttribute) == SoapServiceRoutingStyle.RequestElement) && (method.paramStyle == SoapParameterStyle.Bare)) && (method.requestMappings.Count != 1)) { throw new ArgumentException(System.Web.Services.Res.GetString("WhenUsingAMessageStyleOfParametersAsDocument0"), "methodInfo"); } string name = ""; string ns = ""; if (method.paramStyle == SoapParameterStyle.Bare) { if (method.requestMappings.Count == 1) { name = method.requestMappings[0].XsdElementName; ns = method.requestMappings[0].Namespace; } } else { name = method.requestMappings.XsdElementName; ns = method.requestMappings.Namespace; } method.requestElementName = new XmlQualifiedName(name, ns); if (!method.oneWay) { int num2 = infoArray2.Length; int num3 = 0; CodeIdentifiers identifiers = null; if (methodInfo.ReturnType != typeof(void)) { num2++; num3 = 1; identifiers = new CodeIdentifiers(); } members = new XmlReflectionMember[num2]; for (int m = 0; m < infoArray2.Length; m++) { SoapParameterInfo info2 = infoArray2[m]; XmlReflectionMember member2 = new XmlReflectionMember { MemberName = info2.parameterInfo.Name, MemberType = info2.parameterInfo.ParameterType }; if (member2.MemberType.IsByRef) { member2.MemberType = member2.MemberType.GetElementType(); } member2.XmlAttributes = info2.xmlAttributes; member2.SoapAttributes = info2.soapAttributes; members[num3++] = member2; if (identifiers != null) { identifiers.Add(member2.MemberName, null); } } if (methodInfo.ReturnType != typeof(void)) { XmlReflectionMember member3 = new XmlReflectionMember { MemberName = identifiers.MakeUnique(method.name + "Result"), MemberType = methodInfo.ReturnType, IsReturnValue = true, XmlAttributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider) }; member3.XmlAttributes.XmlRoot = null; member3.SoapAttributes = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider); members[0] = member3; } method.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str4, responseNs, attribute.responseNs == null, members, false, false, key + ":Response", !client); } SoapExtensionAttribute[] customAttributes = (SoapExtensionAttribute[])methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute)); method.extensions = new SoapReflectedExtension[customAttributes.Length]; for (int j = 0; j < customAttributes.Length; j++) { method.extensions[j] = new SoapReflectedExtension(customAttributes[j].ExtensionType, customAttributes[j]); } Array.Sort <SoapReflectedExtension>(method.extensions); SoapHeaderAttribute[] array = (SoapHeaderAttribute[])methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute)); Array.Sort(array, new SoapHeaderAttributeComparer()); Hashtable hashtable = new Hashtable(); method.headers = new SoapReflectedHeader[array.Length]; int num6 = 0; int length = method.headers.Length; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); for (int k = 0; k < method.headers.Length; k++) { SoapHeaderAttribute attribute7 = array[k]; SoapReflectedHeader header = new SoapReflectedHeader(); Type declaringType = methodInfo.DeclaringType; header.memberInfo = declaringType.GetField(attribute7.MemberName); if (header.memberInfo != null) { header.headerType = ((FieldInfo)header.memberInfo).FieldType; } else { header.memberInfo = declaringType.GetProperty(attribute7.MemberName); if (header.memberInfo == null) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderMissing"); } header.headerType = ((PropertyInfo)header.memberInfo).PropertyType; } if (header.headerType.IsArray) { header.headerType = header.headerType.GetElementType(); header.repeats = true; if ((header.headerType != typeof(SoapUnknownHeader)) && (header.headerType != typeof(SoapHeader))) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType"); } } if (MemberHelper.IsStatic(header.memberInfo)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderStatic"); } if (!MemberHelper.CanRead(header.memberInfo)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderRead"); } if (!MemberHelper.CanWrite(header.memberInfo)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderWrite"); } if (!typeof(SoapHeader).IsAssignableFrom(header.headerType)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType"); } SoapHeaderDirection direction = attribute7.Direction; if (method.oneWay && ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderOneWayOut"); } if (hashtable.Contains(header.headerType)) { SoapHeaderDirection direction2 = (SoapHeaderDirection)hashtable[header.headerType]; if ((direction2 & direction) != 0) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebMultiplyDeclaredHeaderTypes"); } hashtable[header.headerType] = direction | direction2; } else { hashtable[header.headerType] = direction; } if ((header.headerType != typeof(SoapHeader)) && (header.headerType != typeof(SoapUnknownHeader))) { XmlReflectionMember member4 = new XmlReflectionMember { MemberName = header.headerType.Name, MemberType = header.headerType }; XmlAttributes attributes = new XmlAttributes(header.headerType); if (attributes.XmlRoot != null) { member4.XmlAttributes = new XmlAttributes(); XmlElementAttribute attribute8 = new XmlElementAttribute { ElementName = attributes.XmlRoot.ElementName, Namespace = attributes.XmlRoot.Namespace }; member4.XmlAttributes.XmlElements.Add(attribute8); } member4.OverrideIsNullable = true; if ((direction & SoapHeaderDirection.In) != 0) { list.Add(member4); } if ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0) { list2.Add(member4); } header.custom = true; } header.direction = direction; if (!header.custom) { method.headers[--length] = header; } else { method.headers[num6++] = header; } } method.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str2 + "InHeaders", defaultNs, true, (XmlReflectionMember[])list.ToArray(typeof(XmlReflectionMember)), false, true, key + ":InHeaders", client); if (!method.oneWay) { method.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str4 + "OutHeaders", defaultNs, true, (XmlReflectionMember[])list2.ToArray(typeof(XmlReflectionMember)), false, true, key + ":OutHeaders", !client); } method2 = method; } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } throw new InvalidOperationException(System.Web.Services.Res.GetString("WebReflectionErrorMethod", new object[] { methodInfo.DeclaringType.Name, methodInfo.Name }), exception); } return(method2); }
internal HttpServerType(Type type) : base(type) { WebServicesSection config = WebServicesSection.Current; Type[] returnWriterTypes = config.ReturnWriterTypes; Type[] parameterReaderTypes = config.ParameterReaderTypes; LogicalMethodInfo[] methodInfos = WebMethodReflector.GetMethods(type); HttpServerMethod[] methods = new HttpServerMethod[methodInfos.Length]; object[] initializersByType = new object[returnWriterTypes.Length]; for (int i = 0; i < initializersByType.Length; i++) { initializersByType[i] = MimeFormatter.GetInitializers(returnWriterTypes[i], methodInfos); } for (int i = 0; i < methodInfos.Length; i++) { LogicalMethodInfo methodInfo = methodInfos[i]; HttpServerMethod method = null; if (methodInfo.ReturnType == typeof(void)) { method = new HttpServerMethod(); } else { for (int j = 0; j < returnWriterTypes.Length; j++) { object[] initializers = (object[])initializersByType[j]; if (initializers[i] != null) { method = new HttpServerMethod(); method.writerInitializer = initializers[i]; method.writerType = returnWriterTypes[j]; break; } } } if (method != null) { method.methodInfo = methodInfo; methods[i] = method; } } initializersByType = new object[parameterReaderTypes.Length]; for (int i = 0; i < initializersByType.Length; i++) { initializersByType[i] = MimeFormatter.GetInitializers(parameterReaderTypes[i], methodInfos); } for (int i = 0; i < methodInfos.Length; i++) { HttpServerMethod method = methods[i]; if (method == null) { continue; } LogicalMethodInfo methodInfo = methodInfos[i]; if (methodInfo.InParameters.Length > 0) { int count = 0; for (int j = 0; j < parameterReaderTypes.Length; j++) { object[] initializers = (object[])initializersByType[j]; if (initializers[i] != null) { count++; } } if (count == 0) { methods[i] = null; } else { method.readerTypes = new Type[count]; method.readerInitializers = new object[count]; count = 0; for (int j = 0; j < parameterReaderTypes.Length; j++) { object[] initializers = (object[])initializersByType[j]; if (initializers[i] != null) { method.readerTypes[count] = parameterReaderTypes[j]; method.readerInitializers[count] = initializers[i]; count++; } } } } } for (int i = 0; i < methods.Length; i++) { HttpServerMethod method = methods[i]; if (method != null) { WebMethodAttribute methodAttribute = method.methodInfo.MethodAttribute; method.name = methodAttribute.MessageName; if (method.name.Length == 0) { method.name = method.methodInfo.Name; } this.methods.Add(method.name, method); } } }
internal HttpServerType(Type type) : base(type) { this.methods = new Hashtable(); WebServicesSection current = WebServicesSection.Current; Type[] returnWriterTypes = current.ReturnWriterTypes; Type[] parameterReaderTypes = current.ParameterReaderTypes; LogicalMethodInfo[] methods = WebMethodReflector.GetMethods(type); HttpServerMethod[] methodArray = new HttpServerMethod[methods.Length]; object[] objArray = new object[returnWriterTypes.Length]; for (int i = 0; i < objArray.Length; i++) { objArray[i] = MimeFormatter.GetInitializers(returnWriterTypes[i], methods); } for (int j = 0; j < methods.Length; j++) { LogicalMethodInfo info = methods[j]; HttpServerMethod method = null; if (info.ReturnType == typeof(void)) { method = new HttpServerMethod(); } else { for (int num3 = 0; num3 < returnWriterTypes.Length; num3++) { object[] objArray2 = (object[])objArray[num3]; if (objArray2[j] != null) { method = new HttpServerMethod { writerInitializer = objArray2[j], writerType = returnWriterTypes[num3] }; break; } } } if (method != null) { method.methodInfo = info; methodArray[j] = method; } } objArray = new object[parameterReaderTypes.Length]; for (int k = 0; k < objArray.Length; k++) { objArray[k] = MimeFormatter.GetInitializers(parameterReaderTypes[k], methods); } for (int m = 0; m < methods.Length; m++) { HttpServerMethod method2 = methodArray[m]; if (method2 != null) { LogicalMethodInfo info2 = methods[m]; if (info2.InParameters.Length > 0) { int index = 0; for (int num7 = 0; num7 < parameterReaderTypes.Length; num7++) { object[] objArray3 = (object[])objArray[num7]; if (objArray3[m] != null) { index++; } } if (index == 0) { methodArray[m] = null; } else { method2.readerTypes = new Type[index]; method2.readerInitializers = new object[index]; index = 0; for (int num8 = 0; num8 < parameterReaderTypes.Length; num8++) { object[] objArray4 = (object[])objArray[num8]; if (objArray4[m] != null) { method2.readerTypes[index] = parameterReaderTypes[num8]; method2.readerInitializers[index] = objArray4[m]; index++; } } } } } } for (int n = 0; n < methodArray.Length; n++) { HttpServerMethod method3 = methodArray[n]; if (method3 != null) { WebMethodAttribute methodAttribute = method3.methodInfo.MethodAttribute; method3.name = methodAttribute.MessageName; if (method3.name.Length == 0) { method3.name = method3.methodInfo.Name; } this.methods.Add(method3.name, method3); } } }