未找到c#方法异常

未找到c#方法异常,c#,reflection,C#,Reflection,我知道这个问题被问到了,但a找不到我做错了什么。我使用反射在web服务GetProduct和RequestLicense方法上执行方法。 这两种方法非常相似 Web服务中的方法: [WebMethod] public LYS.RegistryService.ProductResponse GetProduct(string productNo) { LYS.RegistryService.ProductResponse r = new LYS.RegistryService.ProductR

我知道这个问题被问到了,但a找不到我做错了什么。我使用反射在web服务GetProduct和RequestLicense方法上执行方法。 这两种方法非常相似

Web服务中的方法:

[WebMethod]
public LYS.RegistryService.ProductResponse GetProduct(string productNo)
{
  LYS.RegistryService.ProductResponse r = new LYS.RegistryService.ProductResponse();
  return r;
}
我用来调用web服务的代码

public ServiceResponseBase GetProduct(string productCode)     
{
   object obj = _WebServiceAssembly.CreateInstance("RegisteryService");
   Type typ = obj.GetType();
   object o = typ.InvokeMember(
      "GetProduct", 
      System.Reflection.BindingFlags.InvokeMethod, 
       null, obj, new object[] { productCode });
   return InstantiateObject<ProductResponse>(o);
}
这两个函数非常相似,web服务中这两个方法的返回类型派生自同一个接口。所以做同样的工作返回同样的对象,但是一个在工作,而另一个不工作


有人能帮我吗?

有几种方法可以尝试:

  • 在调用typ.InvokeMember之前创建对象数组。这将有助于隔离问题的根源

    object[]args=新对象[]{c,productCode,isDemoLicense,isProductLicense}

  • 将args参数传递给type.InvokeMember方法

  • 如果仍不工作,请验证所有参数数据类型是否正确


希望这能有所帮助。

那就是没有其他人可以说什么了。
[WebMethod]
public LYS.RegistryService.ServiceResponse RequestLicence(LYS.BusinesObjects.Customer c, string productCode, bool isDemoLicence, bool isProductLicence)
{
  LYS.RegistryService.ServiceResponse r = new LYS.RegistryService.ServiceResponse();
  return r;
}

public ServiceResponseBase RequestLicence(LYS.BusinesObjects.Customer c, string productCode, bool isDemoLicence, bool isProductLicence)
      {
        object obj = _WebServiceAssembly.CreateInstance("RegisteryService");
        Type typ = obj.GetType();
        object o = typ.InvokeMember("RequestLicence", System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] { c, productCode, isDemoLicence, isProductLicence });
        return InstantiateObject<ServiceResponse>(o);
      }
object o = typ.InvokeMember("RequestLicence", System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] { c, productCode, isDemoLicence, isProductLicence });