【问题标题】:Dynamically call method name from string value using proxy class for web service使用 Web 服务的代理类从字符串值动态调用方法名称
【发布时间】:2015-07-13 11:35:24
【问题描述】:

我在我的项目中创建了代理网络服务。我想从参数中调用方法名称作为字符串,我需要从这些方法中获取响应,但它仅作为字符串返回。所以请任何人帮助我。

这里我需要传递 MethodName。

例如:

string response = mut.MethodName(RequestData);

[WebMethod]
public string CALLPROXY(string MethodName, string RequestData)
{

    WebReference.IMPSMethods mut = new WebReference.IMPSMethods();
    mut.Url = "http://xxxxxxxxxxx.asmx?wsdl";
    mut.Credentials = System.Net.CredentialCache.DefaultCredentials;
    //string response = mut.LOGIN(RequestData);
    string response = mut + "." + MethodName + "(" + RequestData + ")";
    return response;

}

【问题讨论】:

    标签: c# asp.net web-services


    【解决方案1】:

    试试这个

    string response = typeof(WebReference.IMPSMethods)
                         .GetMethod(MethodName)
                         .Invoke(mut, new object[] { RequestData })
    

    如果您的类 IMPSMethods 有重载,您将需要使用重载的 .GetMethod() 调用来缩小范围(查找特定的参数类型等)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多