添加到 webmethods 的额外参数

发布于 2024-12-15 18:28:30 字数 1876 浏览 1 评论 0原文

我正在从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

机场等船 2024-12-22 18:28:30

我最近自己发现了这一点。在某些情况下,它与 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 set oneSpecified to true to make the serializer serialize the value of one and send it.

Some more info here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文