【问题标题】:XSD minOccurs="1" for stringXSD minOccurs="1" 用于字符串
【发布时间】:2013-06-07 05:07:40
【问题描述】:

我有一个名为“accountNumber”的字符串字段作为 Web 服务中使用的对象的一部分。我需要这个字段有minOccurs="1" 但没有 nillable="true"。 如果我将该字段定义为<XmlElement(IsNullable:=True)>,那么我会得到minOccurs="1" 和nillable="true"。如果我定义<XmlElement(IsNullable:=False)>,那么我不会得到nillable="true",而是会得到minOccurs="0"。

那么,我如何定义我的对象以在我的 XSD 中获取它:

<s:element minOccurs="1" maxOccurs="1" name="accountNumber" type="s:string" />

我的类定义很简单:

<Serializable()> _
<XmlType(Namespace:="http://mysite.org")> _
Public Class MyServiceWS
    'some other definitions
    <XmlElement(IsNullable:=True)> <VBFixedString(64)> Public accountNumber As String
End Class

感谢您的帮助。


2012 年 10 月 16 日编辑:逆向工程 XSD


我使用以下字段对 XSD 进行了逆向工程:

<xs:element name="TEST1" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="TEST2" minOccurs="0" maxOccurs="1" type="xs:string"/>
<xs:element name="TEST3" minOccurs="1" maxOccurs="1" nillable="true" type="xs:string"/>
<xs:element name="TEST4" minOccurs="0" maxOccurs="1" nillable="false" type="xs:string"/>

我使用了以下命令:xsd.exe MyClass.xsd /classes /language:vb /f

产生了以下结果:

'''<remarks/>
Public TEST1 As String

'''<remarks/>
Public TEST2 As String

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
Public TEST3 As String

'''<remarks/>
Public TEST4 As String

从这个结果来看,我想做的事情似乎无法完成。


编辑 2012 年 10 月 17 日:发现有类似问题的帖子


对于所有对此问题感兴趣的人,我发现了一个类似问题的帖子。没有提供解决方案。

How to make a dotnet webservice set minOccurs=“1” on a string value

【问题讨论】:

  • 我建议做相反的事情:创建一个虚拟 XML Schema,其中包含您想要的 XSD 内容,然后使用 vb 语言设置运行 xsd.exe 以生成代码,然后采取查看生成的其他提示。
  • 已经试过了——它们似乎是一样的。
  • 那么您是说为此,您得到了不同的 minOccurs 吗?即往返工程是否也行不通,即从 XSD 反向到 VB.NET 和从 VB 代码到 XSD 的正向工程会给您不同的结果?
  • 我以另一种方式做到了...请查看我的编辑。

标签: vb.net xsd


【解决方案1】:

据我所知,我所要求的无法通过 .NET 实现自动化。我必须手动更改 WSDL。

【讨论】:

    【解决方案2】:

    我已经在另一个有同样问题的帖子上发布了详细答案:How to make a dotnet webservice set minOccurs=“1” on a string value。

    但简短的回答是否。字符串类型是不可能的。

    String 类型有一个默认值 String.Empty,除非没有默认值(只有使用 IsNullable = true 表示字符串)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 2011-11-04
      相关资源
      最近更新 更多