如何使 dotnet webservice 设置 minOccurs=“1";在字

How to make a dotnet webservice set minOccurs=quot;1quot; on a string value(如何使 dotnet webservice 设置 minOccurs=“1;在字符串值上)

本文介绍了如何使 dotnet webservice 设置 minOccurs=“1";在字符串值上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns="http://a.com/a.xsd"
     targetNamespace="http://a.com/a.xsd"
     elementFormDefault="qualified"
     attributeFormDefault="unqualified">
    <xs:element name="A">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Item"  minOccurs="1" maxOccurs="1">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:minLength value="1"/>                                       
                            <xs:whiteSpace value="collapse"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

我使用 XSD.exe v2.0.50727.3615 将其转换为 C# 类,生成代码如下

Which I have converted into a C# class using XSD.exe v2.0.50727.3615 which generates code as follows

namespace A {
    using System.Xml.Serialization;
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://a.com/a.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://a.com/a.xsd", IsNullable=false)]
    public partial class A {
        private string itemField;
        /// <remarks/>
        public string Item {
            get {
                return this.itemField;
            }
            set {
                this.itemField = value;
            }
        }
    }
}

我在我的网络服务中返回了一个 A.A 对象,它在服务描述中生成了这个片段

I am returning an A.A object in my webservice, which produces this snippet in the service description

<s:schema elementFormDefault="qualified" targetNamespace="http://a.com/a.xsd"> 
  <s:element name="Test2Result"> 
    <s:complexType> 
      <s:sequence> 
        <s:element minOccurs="0" maxOccurs="1" name="Item" type="s:string" /> 
      </s:sequence> 
    </s:complexType> 
  </s:element> 
</s:schema> 

从 XSD 中的 minOccrus="1" 到自动生成的 WSDL 中的 minOccurs="0" 的变化正在给系统另一端的机器带来麻烦.

The change from minOccrus="1" in the XSD to minOccurs="0" on the auto-generated WSDL is causing grief to the machine on the other end of the system.

我当然可以提供手动编辑的 WSDL 供他们使用,但我希望自动生成的 WSDL 能够满足他们的需求.

I could of course provide a hand edited WSDL for them to use, but I would like the auto-generated one to suit their needs.

关于如何说服 dotnet 在其自动生成的 WSDL 中为字符串类型输出 minOccurs="1" 而不添加 nillable="true" 的任何建议?

Any suggestions on how to convince dotnet to output minOccurs="1" for a string type in its autogenerated WSDLs without also adding nillable="true"?

推荐答案

我注意到下面一行:

对于将 XML Schema 复杂类型与非 XML 特定的类绑定,.NET Framework 不提供等效于 minOccurs 或 maxOccurs 属性的直接编程语言.

For binding XML Schema complex types with non-XML-specific classes, the .NET Framework does not provide a direct programming language equivalent to the minOccurs or maxOccurs attribute.

从这里:http://msdn.microsoft.com/en-us/library/zds0b35c(v=vs.85).aspx

这篇关于如何使 dotnet webservice 设置 minOccurs=“1";在字符串值上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使 dotnet webservice 设置 minOccurs=“1";在字

基础教程推荐