更改WSDL文件以在生成的C#类中添加名称空间



我使用.wsdl文件和svcutil.exe生成相关.cs文件,生成的.cs文件如下:

 public partial class mytargettype {
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "", Order = 0)]
    [System.Xml.Serialization.XmlArrayAttribute()]
    [System.Xml.Serialization.XmlArrayItemAttribute("item", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string[] prop1;
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "", Order = 1)]
    [System.Xml.Serialization.XmlArrayAttribute()]
    [System.Xml.Serialization.XmlArrayItemAttribute("item", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string[] prop1;
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "", Order = 2)]
    [System.Xml.Serialization.XmlArrayAttribute()]
    [System.Xml.Serialization.XmlArrayItemAttribute("item", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string[] prop3;
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "", Order = 3)]
    [System.Xml.Serialization.XmlArrayAttribute()]
    [System.Xml.Serialization.XmlArrayItemAttribute("item", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public System.Nullable<int>[] prop4;
}

.wsdl文件的相关部分是:

 <wsdl:message name="mytargettype">
    <wsdl:part name="prop1" type="ns1:stringArray" />
    <wsdl:part name="prop2" type="ns1:stringArray" />
    <wsdl:part name="prop3" type="ns1:stringArray" />
    <wsdl:part name="prop4" type="ns1:intArray" />
  </wsdl:message>

所以,我需要生成的.cs文件,就像:

 [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "", Order = 2)]
 [System.Xml.Serialization.XmlArrayAttribute(Namespace = "http://jaxb.dev.java.net/array")]
 [System.Xml.Serialization.XmlArrayItemAttribute("item", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
 public string[] prop3;

如您所见,我需要XmlArrayAttribute具有名称空间参数,

哪些更改需要添加到导致.cs文件的.wsdl文件中。

我认为您的wsdl某个地方有这样的部分:

<xs:complexType name="stringArray" final="#all">
    <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="item" nillable="true" type="xs:string" />
    </xs:sequence>
</xs:complexType>

将其更改为以下可能会解决您的问题:

<xs:complexType name="stringArray" wsdl:arrayType="xs:string" mixed="true">
    <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="item" nillable="true" type="xs:string" />
    </xs:sequence>
</xs:complexType>

相关内容

  • 没有找到相关文章