是否仍无法通知消费客户数据限制?
这个问题绝对是其他从未回答或至少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
Run Code Online (Sandbox Code Playgroud)
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; }
}
}
Run Code Online (Sandbox Code Playgroud)
...生成的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>
Run Code Online (Sandbox Code Playgroud)
这是我期待的(或类似的):
<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>
Run Code Online (Sandbox Code Playgroud)
小智 -1
对我来说,我通过创建一个必须 var 的附加类来做到这一点
status as short
const SUCCESS as short= 1
const FAILED as short= 0
msg as string
Run Code Online (Sandbox Code Playgroud)
和一个返回此类对象的函数名调用,我所有的服务调用都被重定向到这个函数,这是一个常量,供资源检查是否已应用所需的函数,如果没有,我将根据消息采取行动
dim Result=//wcf call
if Result.status=SUCCSES then
//do something
else
msgbox(Result.msg)
end if
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
237 次 |
| 最近记录: |