在方法/数据成员中向 WCF 添加限制 [英] Add restrictions to WCF in method/data member

查看:19
本文介绍了在方法/数据成员中向 WCF 添加限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WCF 的新手,我尝试向数据成员添加限制.

I'm new to WCF and I try to add restriction to data member.

以这种方法为例:

[DataMember]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }

我想设置最大和最小长度.我知道如何在 XML 代码中添加限制

I want to set max and min length. I know how to add the restriction to the XML code

 <xs:restriction base="xs:string">
  <xs:minLength value="2"/>
  <xs:maxLength value="10"/>
</xs:restriction>

但是有没有办法直接从代码中添加限制?

but is there a way to add a restriction straight from the code?

推荐答案

根据 MSDN、maxLength、minLength 和length 等将被忽略.没有任何声明方式可以强制执行您所要求的内容,就像我希望的那样.这是 .NET 和 XML 世界之间出现裂痕的地方之一.我发现的唯一强制执行方法是构建一个 消息检查器并在那里应用变换.

According to MSDN, maxLength, minLength and length etc are ignored. There is no declarative way to enforce what you're asking for, as much as I wish there was. This is one of those places where the cracks between the .NET and XML worlds show. The only method I've found for enforcement is to build a message inspector and apply the transform in there.

这篇关于在方法/数据成员中向 WCF 添加限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆