[英]Call functions dynamics of DLL's inside a Web Service C#
I have a Web Service called 'A'. 我有一个名为“ A”的Web服务。
On this WS I want only stay looking the installed folder, in other words, together main DLL file. 在此WS上,我只希望继续查找已安装的文件夹,换句话说就是一起查找主DLL文件。
On this directory I plan to put "modules" of my project and share the functions (Operation Contracts) with my WS. 我计划在此目录中放置项目的“模块”,并与WS共享功能(运营合同)。
For example: 例如:
ModuleOne.dll have the function: ModuleOne.dll具有的功能:
string[] getUsersFromDatabase();
MyService.dll have the function: MyService.dll具有的功能:
object CallEventByName(string eventName, params string parameters);
And I imagine the use: 我想像一下用法:
foreach string file in fileList
// Check if DLL file have the function equal to 'eventName',
// call the function passing your parameters if have
When I create the requisition SOAP, indicate the function name and the parameters. 创建请求SOAP时,请指定函数名称和参数。 My WS need the intelligence to manage this requisition and return the "return" haha. 我的WS需要情报来管理此申请并返回“返回”哈哈。
Who I can to this? 我可以给谁?
Something like this , there may be a problem if dll which you want to load has dependencies , then you have load also this dll 这样的事情,如果您要加载的dll有依赖项,则可能有问题,那么您也加载了该dll
object CallFunction(string[] fileList , string eventName , object[] parameters){
foreach(var file in fileList)
{
Assembly assem = Assembly.LoadFrom(file);
foreach(var t in assem.GetTypes())
{
var methodInfo = t.GetMethod(eventName);
if(methodInfo != null)
{
var obj = Activator.CreateInstance(t);
return methodInfo.Invoke(obj , parameters);
}
}
}
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.