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

时间:2012-11-10 13:42:41

标签: c# xml wsdl wsdl2code

我使用.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具有命名空间参数

需要什么更改添加到.WSDL导致.cs文件的文件如上所述。

1 个答案:

答案 0 :(得分:0)

我认为你的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>