【问题标题】:how to remove <optional> from Soap request如何从 Soap 请求中删除 <optional>
【发布时间】:2014-01-15 13:47:43
【问题描述】:

我正在使用 SoapUI Pro 4.6.1 来测试我的 WCF 服务。 我的请求看起来像这样

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
       <soapenv:Header/>
    <soapenv:Body>
  <tem:doPaymentRequest>
     <!--Optional:-->
     <tem:credentials>
        <!--Optional:-->
        <tem:accountId>?</tem:accountId>
        <!--Optional:-->
        <tem:userName>?</tem:userName>
        <!--Optional:-->
        <tem:password>?</tem:password>
     </tem:credentials>
     </tem:doPaymentRequest>

如何从 SOAP 中删除 --Optional:--> 我正在使用消息格式来包装我的数据合同,并且我正在为 DataContract 使用 isRequired 属性。

【问题讨论】:

    标签: wcf soapui datacontract messagecontract


    【解决方案1】:

    您要删除任何可选元素吗?然后 File -> Preferences -> WSDL Settings -> Include Optional (这是一个复选框)。当您向测试用例添加请求时,它还建议选择“创建可选元素”选项。

    【讨论】:

      【解决方案2】:

      您需要在数据协定类中的所有属性上指定[DataMember(IsRequired = true)],那么它们将不是可选的。

      【讨论】:

      • 是的,如果我们只使用 DataContract 和 DataMember,它是正确的。但是当我们使用 MessageContract 包装 DataContract 时,这不起作用。
      【解决方案3】:
      [DataContract]
      public class GetColorsRS
      {
          DataMember(Name = "Errors", Order = 1, IsRequired=false)]
          public List<Error> Errors { get; set; }
      }
      

      【讨论】:

      • 是的,如果我们只使用 DataContract 和 DataMember,它是正确的。但是当我们使用 MessageContract 包装 DataContract 时,这不起作用。
      猜你喜欢
      • 1970-01-01
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多