【发布时间】:2017-06-16 07:01:04
【问题描述】:
是否仍然无法通知消费客户端数据限制?
这个问题绝对是其他从未回答过或至少 5 年没有可行解决方案的问题的重复。链接已过期或无用或参考 .Net 3.x,那时我们无能为力。
需要明确的是,这与服务验证无关......请不要去那里。这只是关于通过自动生成的 WSDL / XSD 让客户端了解这些限制。
给定以下 WCF 服务,指定了 StringLength、Range 和 DefaultValue....
VB版:
<ServiceContract([Namespace]:="example.com")>
Public Interface IWCF_Service
<OperationContract()>
Function Test1(Value As Something) As String
Class Something
<StringLength(50), DefaultValue("Whatever")>
Public Property Thing1 As String = "Whatever"
<Range(5, 50), DefaultValue(10), Required>
Public Property Thing2 As Int32 = 10
End Class
End Interface
C#版本:
[ServiceContract(Namespace = "example.com")]
public interface IWCF_Service
{
[OperationContract()]
string Test1(Something Value);
public class Something
{
[StringLength(50), DefaultValue("Whatever")]
public string Thing1 { get; set; }
[Range(5, 50), DefaultValue(10), Required()]
public Int32 Thing2 { get; set; }
}
}
...生成的 XSD 缺少默认值和限制,Thing2 应该是 minOccurs="1",因为它是必需的:
<xs:complexType name="IWCF_Service.Something">
<xs:sequence>
<xs:element minOccurs="0" name="Thing1" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Thing2" type="xs:int" />
</xs:sequence>
</xs:complexType>
这是我所期待的(或类似的):
<xs:complexType name="IWCF_Service.Something">
<xs:sequence>
<xs:element minOccurs="0" name="Thing1" nillable="true" default="Whatever">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Thing2" default="10">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="5" />
<xs:maxInclusive value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
【问题讨论】:
-
为什么说“这是我所期待的(或类似的):”VB 输出和 C# 输出哪一个?
-
@Chillzy C#/VB 代码是输入。自动生成的 WSDL / XSD 是我们没有得到的输出。
-
我明白了。第一个输出是VB代码输出,第二个是C#输出?
-
@Chillzy VB 和 C# 都生成了上面非常短的 XSD。我希望他们生产的 XSD 越长。