39 |
{ |
{ |
40 |
int error; |
int error; |
41 |
|
|
42 |
try |
// Load in requested dll |
|
{ |
|
|
// Load in requested dll |
|
|
// |
|
|
assembly = LoadFromMemory( assemblyName, out error ); |
|
|
} |
|
|
catch( Exception xcpt ) |
|
|
{ |
|
|
throw new Exception("Could not load dll " + assemblyName, xcpt ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal WebMethodAttribute GetAttribute(MethodInfo method) |
|
|
{ |
|
|
Attribute[] attrs = Attribute.GetCustomAttributes(method, |
|
|
typeof(WebMethodAttribute), false); |
|
|
|
|
|
if( attrs == null || attrs.Length != 1 ) return null; |
|
|
|
|
|
return (WebMethodAttribute)attrs[0]; |
|
|
} |
|
|
|
|
|
|
|
|
internal MethodInfo FindMethod( Type type, String methodname ) |
|
|
{ |
|
|
MethodInfo []methods = type.GetMethods(); |
|
|
//type.GetMethods(BindingFlags.Public | BindingFlags.Static); |
|
|
|
|
|
// Scan methods in class, looking for the requested |
|
43 |
// |
// |
44 |
foreach(MethodInfo method in methods) { |
assembly = LoadFromMemory( assemblyName, out error ); |
|
//Console.WriteLine( "Method: {0}", method.Name ); |
|
45 |
|
|
46 |
if( method.Name != methodname ) continue; |
if( assembly == null || error > 0 ) |
47 |
// See if method is a Webservice (indicated by attribute) |
throw new Exception("Could not load dll " + assemblyName + " - Error: " + error.ToString() ); |
|
// |
|
|
Attribute attr = GetAttribute(method); |
|
|
if(attr != null) { |
|
|
// Found required MethodInfo |
|
|
// |
|
|
return method; |
|
|
} |
|
|
} |
|
|
|
|
|
return null; |
|
48 |
} |
} |
|
|
|
|
internal MethodInfo ResolveMethod( String typeName, String methodName ) |
|
|
{ |
|
|
MethodInfo minfo = null; |
|
|
|
|
|
// Get array of classes |
|
|
// |
|
|
Type[] types=assembly.GetTypes(); |
|
|
|
|
|
foreach(Type type in types) { |
|
|
Console.WriteLine( "Type: {0}", type.ToString() ); |
|
|
|
|
|
if( type.ToString() == typeName ) minfo = FindMethod(type,methodName); |
|
|
if( minfo != null ) break; |
|
|
} |
|
49 |
|
|
|
return minfo; |
|
|
} |
|
|
|
|
50 |
public Assembly assembly = null; |
public Assembly assembly = null; |
51 |
} |
} |
52 |
} |
} |