我通过反射创建程序集,然后使用它创建wcf服务客户端的实例。
object obj =
assembly.CreateInstance(
serviceName, true,
BindingFlags.CreateInstance,null,createArgs, null, null);
Type type = obj.GetType();
obj
属于helloworldserviceclient类型。getMethods()有14个methodinfo结果。第一个是{acme.testservice.helloworldresponse helloworld(acme.testservice.helloworldrequest)}
但当我这么做的时候
return (T)type.InvokeMember(
"HelloWorld", BindingFlags.InvokeMethod, null, obj, args);
我收到一个MissingMethodException。
type.containsGenericParameters=假。
args是对象[1],包含单个{acme.testservice.helloworldrequest}。
我非常困惑。有人能帮我吗?
最佳答案
您还可以使用getmethod(methodname)并调用它。
如果您动态创建程序集,我将建议这两个步骤。
这样,您可以先找到该方法,而不是调用它。