【发布时间】:2015-08-21 15:51:27
【问题描述】:
我的 WFC 项目 WSDL 缺少基于零的索引的 EnumerationValue 注释。如果说 JSON 为付款方式传入 0 或 1,则会在转换期间对其他系统造成问题。
我已经像这样定义了我的 .net 类的枚举:
[DataContract(Name = "PaymentMethod")]
public enum PaymentMethod
{
[EnumMember]
Mastercard = 0,
[EnumMember]
Visa = 1
}
[DataContract(Name = "RequestType")]
public enum RequestType
{
[EnumMember]
New = 1,
[EnumMember]
Reload = 2
}
但是生成的 WSDL 看起来像这样:
<xs:simpleType name="PaymentMethod">
<xs:restriction base="xs:string">
<xs:enumeration value="Mastercard"/>
<xs:enumeration value="Visa"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="PaymentMethod" nillable="true" type="tns:PaymentMethod"/>
<xs:simpleType name="RequestType">
<xs:restriction base="xs:string">
<xs:enumeration value="New">
<xs:annotation>
<xs:appinfo>
<EnumerationValue>1</EnumerationValue>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="Reload">
<xs:annotation>
<xs:appinfo>
<EnumerationValue>2</EnumerationValue>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:element name="RequestType" nillable="true" type="tns:RequestType"/>
【问题讨论】:
-
如果从枚举中去掉 DataContact 属性会发生什么?我通常会这样做以获得更好的 WSDL。
-
感谢您的评论。它根本不影响 WSDL。
标签: .net web-services wcf wsdl