添加到 webmethods 的额外参数
我正在从 wsdl 生成的代理中读取一些 MethodInfo
。
其中一种方法具有三个 (int
) 参数和一个 int
返回类型,但当我探索 ParameterInfo[]
时,我实际上看到了八个参数:
Int32
、布尔值
、Int32
、布尔值
、Int32
、布尔值,
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]));
}
这是为什么?
更新
如果您像我一样被这个问题困扰,您可以通过简单地应用以下代码片段来轻松避免显示这些额外的参数:
if (!parameterInfo[i].Name.EndsWith("Specified") && !parameterInfo[i].IsRetval && !parameterInfo[i].Name.EndsWith("Result"))
{
// magic
}
I'm reading some MethodInfo
from a proxy generated from a wsdl.
One of the methods has three (int
) parameters and a int
return type, but when I explore the ParameterInfo[]
I actually see eight parameters:
Int32
,Boolean
,Int32
,Boolean
,Int32
,Boolean
,Int32&
,Boolean&
Where do these extra parameters originate?
UPDATE
To elaborate a bit more, the code in the generated proxy looks as following:
/// <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]));
}
Why is this?
UPDATE
If you're bugged by this, as I am, you cane easily avoid displaying those extra parameters by simply applying the following snippet of code:
if (!parameterInfo[i].Name.EndsWith("Specified") && !parameterInfo[i].IsRetval && !parameterInfo[i].Name.EndsWith("Result"))
{
// magic
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近自己发现了这一点。在某些情况下,它与 XSD 中的
minoccurrs=0
有关。 WCF 代理类不使用可为 null 的类型,因此 XmlSerializer 无法确定您是否想要发送特定字段。您可以设置
one
,但不会发送。您还必须将oneSpecified
设置为true
以使序列化程序序列化one
的值并将其发送。更多信息 此处。
I recently found this out for myself. In some cases it has todo with
minoccurs=0
in the XSD. The WCF proxy class doesn't use nullable types, so it's not possible for the XmlSerializer to determine whether you want or don't want to send a certain field.You can set
one
, but it won't be sent. You also have to setoneSpecified
totrue
to make the serializer serialize the value ofone
and send it.Some more info here.