WCF架构问题

发布于 2025-01-07 03:03:05 字数 3685 浏览 2 评论 0原文

以下是该服务的架构。

<xs:element name="StartDate" type="tns:DateType">
  <xs:annotation>
    <xs:documentation>The start date of the planning item in question</xs:documentation>
  </xs:annotation>
</xs:element>
<xs:complexType name="DateType">
  <xs:annotation>
    <xs:documentation>
      0 - Hard Date (Use the date defined by the year, month and day attributes
      2 - Retirement
      3 - Death
      4 - Disability
      5 - Long Term Care
    </xs:documentation>
  </xs:annotation>
  <xs:sequence>
    <xs:element name="Date">
      <xs:complexType>
        <xs:attribute name="date_type" use="optional" default="0">
          <xs:simpleType>
            <xs:restriction base="xs:int">
              <xs:enumeration value="0">
                <xs:annotation>
                  <xs:documentation>Hard Date (Use the date defined by the year, month and day attributes</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="2">
                <xs:annotation>
                  <xs:documentation>Retirement</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="3">
                <xs:annotation>
                  <xs:documentation>Death</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="4">
                <xs:annotation>
                  <xs:documentation>Disability</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="5">
                <xs:annotation>
                  <xs:documentation>Long Term Care</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

这是代理类

公共分部类DateTypeDate {

    private int date_typeField;


    public DateTypeDate()
    {
        this.date_typeField = 0;
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    [System.ComponentModel.DefaultValueAttribute(0)]
    public int date_type
    {
        get
        {
            return this.date_typeField;
        }
        set
        {
            this.date_typeField = value;
        }
    }


}

我有一个要求,我们需要在 date_type 中发送 0 值。

1-我尝试了以下方法,假设默认情况下它应该分配“0”值。

   StartDate = new DateType();
   DateTypeDate date = new DateTypeDate();

2-然后我明确地将“date_type”值分配为0

StartDate = new DateType();
   DateTypeDate date = new DateTypeDate();
   date.date_type = 0;
   StartDate.Date = date;

在这两种情况下,“date_type”节点都不会出现在发送到服务的实际请求xml中。这是生成的请求 xml。

    <StartDate>
    <Date></Date>
    </StartDate>

But if i assign a different value than 0 then i can see the date_type node. for example 

    <StartDate>
     <Date date_type="2"></Date>
     </StartDate>


Would you able to help what could be the reason that node doesn't appear in request xml id i assign it to "0" also is there any way the node can appear without making chnages in schema. Thanks in advance

The below is schema of the service.

<xs:element name="StartDate" type="tns:DateType">
  <xs:annotation>
    <xs:documentation>The start date of the planning item in question</xs:documentation>
  </xs:annotation>
</xs:element>
<xs:complexType name="DateType">
  <xs:annotation>
    <xs:documentation>
      0 - Hard Date (Use the date defined by the year, month and day attributes
      2 - Retirement
      3 - Death
      4 - Disability
      5 - Long Term Care
    </xs:documentation>
  </xs:annotation>
  <xs:sequence>
    <xs:element name="Date">
      <xs:complexType>
        <xs:attribute name="date_type" use="optional" default="0">
          <xs:simpleType>
            <xs:restriction base="xs:int">
              <xs:enumeration value="0">
                <xs:annotation>
                  <xs:documentation>Hard Date (Use the date defined by the year, month and day attributes</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="2">
                <xs:annotation>
                  <xs:documentation>Retirement</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="3">
                <xs:annotation>
                  <xs:documentation>Death</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="4">
                <xs:annotation>
                  <xs:documentation>Disability</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
              <xs:enumeration value="5">
                <xs:annotation>
                  <xs:documentation>Long Term Care</xs:documentation>
                </xs:annotation>
              </xs:enumeration>
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

This is the proxy class

public partial class DateTypeDate
{

    private int date_typeField;


    public DateTypeDate()
    {
        this.date_typeField = 0;
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    [System.ComponentModel.DefaultValueAttribute(0)]
    public int date_type
    {
        get
        {
            return this.date_typeField;
        }
        set
        {
            this.date_typeField = value;
        }
    }


}

I have a requirement where we need to send 0 value in date_type.

1- I tried the below by assuming that by default it should assign "0" value.

   StartDate = new DateType();
   DateTypeDate date = new DateTypeDate();

2- Then i explicitly assign "date_type" value to 0

StartDate = new DateType();
   DateTypeDate date = new DateTypeDate();
   date.date_type = 0;
   StartDate.Date = date;

In both cases "date_type" node doesn't get appear in actual request xml being sent over to service. This is request xml which gets generated.

    <StartDate>
    <Date></Date>
    </StartDate>

But if i assign a different value than 0 then i can see the date_type node. for example 

    <StartDate>
     <Date date_type="2"></Date>
     </StartDate>


Would you able to help what could be the reason that node doesn't appear in request xml id i assign it to "0" also is there any way the node can appear without making chnages in schema. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

你与清晨阳光 2025-01-14 03:03:05

我不是 XML 模式专家,但在我看来,问题几乎肯定是由于模式中的以下行造成的:

<xs:attribute name="date_type" use="optional" default="0">

如果该属性是可选的,则意味着客户端不必发送它。尝试将其设置为必需。

I'm not an XML Schema expert, but it seems to me the problem is almost certainly because of the following line in the schema:

<xs:attribute name="date_type" use="optional" default="0">

If the attribute is optional that means the client doesn't have to send it. Try making it required instead.

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