我知道这个问题被问到但是找不到我做错的地方。我使用反射来执行Web服务GetProduct和RequestLicence方法的方法。 这两种方法非常相似。
Web服务中的方法:
[WebMethod]
public LYS.RegistryService.ProductResponse GetProduct(string productNo)
{
LYS.RegistryService.ProductResponse r = new LYS.RegistryService.ProductResponse();
return r;
}
我用来调用网络服务的代码
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);
}
上面的代码工作正常。这是我得到错误的部分。
[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 });
这两个函数非常相似,Web服务中这两个方法的返回类型来自同一个接口。所以做同样的工作返回相同的对象,但一个工作,但另一个不工作。
有人可以帮助我吗?
答案 0 :(得分:0)
有几件事要尝试:
在调用typ.InvokeMember之前创建对象数组。这将有助于隔离问题的根源。
object [] args = new object [] {c,productCode,isDemoLicence,isProductLicence};
将args参数传递给type.InvokeMember方法
如果仍然无效,请验证所有参数数据类型是否正确。
希望这有帮助。