c# - 如何通过服务引用发布 Reflection.MethodBase

标签 c# asp.net web-services reflection

我正在使用带有 Lucene 引擎的后端 (.Net C#) 创建一个日志系统,并且我正在记录每个方法请求。

为此,我在后端创建了一个服务引用,WebService 方法参数之一是 Reflection.MethodBase。

在前端,我添加了引用(.Net 创建了一个 Soap 客户端连接器)。 但是,该方法不需要 Reflection.MethodBase,它需要另一个 MethodBase 类 (TestLogger.RefLogger.MethodBase)。

我认为 .Net 为每个不是原语的方法参数创建了一个 Clone 类。

问题是,我无法从 Reflection.MethodBase 转换为 MyLooger.MethodBase,例如:

public static void addLog(MethodBase methodBase, object[] parameters, TestLogger.RefLogger.TipoLog tipoLog)
{
    TestLogger.RefLogger.WSLoggerSoapClient client = new TestLogger.RefLogger.WSLoggerSoapClient();
    client.AddLogNormal(MethodBase.GetCurrentMethod(), parameters, tipoLog);
}

在这里,它向我展示了它无法转换类型,即使我尝试了 Cast:

(TestLogger.RefLogger.MethodBase)MethodBase.GetCurrentMethod()

因此,我尝试创建一个方法来“转换”对象,创建一个新的 MyLogger.MethodBase 并复制值,但它没有构造函数。

TestLogger.RefLogger.MethodBase mDest = new TestLogger.RefLogger.MethodBase();//CANNOT DO THIS

有什么想法吗? 提前致谢。

最佳答案

如果您只需要记录此方法的信息,您可以在前端使用 MethodBase.GetParameters 检索此信息:

String methodName
String[] parametersNames 
String[] parametersValues

要创建 methodName,您可以使用 methodBase.DeclaringType.Namespace + "."+ methodBase.DeclaringType.Name + "."+ 方法库名称。

要创建参数名称,请使用 MethodBase.GetParameters: http://msdn.microsoft.com/pt-br/library/system.reflection.methodbase.getparameters(v=vs.110).aspx

然后您可以将此参数传递给您的后端。

Web 服务可以识别的这种类型。

关于c# - 如何通过服务引用发布 Reflection.MethodBase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26657315/

相关文章:

c# - VS 使用 RAZOR VBHTML 崩溃

spring - 为什么我无法访问 tomcat : HTTP Status 500 - Internal Server Error 中的服务 CXF

c# - 参数类型不匹配 Transforming anonymous Expression<Func<T,U>> to non anonymous Expression<Func<T,U>>

c# - 应用程序在 Linux 上运行时连接到 MSSQL Server 2017 超时

c# - 在 WPF 中,我可以在 2 个按钮之间共享相同的图像资源吗

asp.net - BC30560 : 'ExtensionAttribute' is ambiguous in the namespace 'System.Runtime.CompilerServices'

c# - 在 Html 元素的深层堆栈中获取一个元素

javascript - 您可以从同一个 UserControls Javascript 调用 UserControl 服务器函数吗?

java - 使用 Grizzly 作为 Web 服务引擎

C# - 如何处理 2 "TopMost"表单?