【发布时间】:2011-11-15 11:23:40
【问题描述】:
我正在从 wsdl 生成的代理中读取一些 MethodInfo。
其中一个方法有三个(int)参数和一个int返回类型,但是当我探索ParameterInfo[]时,我实际上看到了八个参数:
-
Int32, -
Boolean, -
Int32, -
Boolean, -
Int32, -
Boolean, -
Int32&, Boolean&
这些额外参数从何而来?
更新
更详细地说,生成的代理中的代码如下所示:
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/IInleerAppService/AddThreeNumbers", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void AddThreeNumbers(int one, [System.Xml.Serialization.XmlIgnoreAttribute()] bool oneSpecified, int two, [System.Xml.Serialization.XmlIgnoreAttribute()] bool twoSpecified, int three, [System.Xml.Serialization.XmlIgnoreAttribute()] bool threeSpecified, out int AddThreeNumbersResult, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool AddThreeNumbersResultSpecified) {
object[] results = this.Invoke("AddThreeNumbers", new object[] {
one,
oneSpecified,
two,
twoSpecified,
three,
threeSpecified});
AddThreeNumbersResult = ((int)(results[0]));
AddThreeNumbersResultSpecified = ((bool)(results[1]));
}
这是为什么?
更新
如果您像我一样对此感到困扰,您可以通过简单地应用以下 sn-p 代码来轻松避免显示这些额外参数:
if (!parameterInfo[i].Name.EndsWith("Specified") && !parameterInfo[i].IsRetval && !parameterInfo[i].Name.EndsWith("Result"))
{
// magic
}
【问题讨论】:
-
你是用什么来获取 MethodInfo 的?你确定这是同样的方法吗?例如,这里的方法名称是什么?基本上:请提供更多上下文
-
基本上我只是在代码中生成了一个代理程序集并通过反射读取它。 webservice也是我自己写的,确实是一样的方法。
标签: c# wcf reflection proxy