我正在构建一个 ASP.NET Web 服务。
我的代码定义如下,但我不知道如何通过 wsdl 指定 FirstName 和 LastName 属性的 minOccurs。我要那些按要求,不能为空。是否可以?
[WebMethod()]
public void TestMethod(TestClass Test)
{
...
}
[Serializable]
public class TestClass
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
最佳答案
我在另一个有同样问题的帖子上发布了详细的答案:How to make a dotnet webservice set minOccurs=“1” on a string value .
然而,字符串的答案是 否 .
在没有 nullable=true 的情况下使 minOccurs=1 的唯一方法是使用 声明一个属性。无默认值 (字符串的默认值为 String.Empty) 和 没有属性来检查是否指定了值(创建一个相同的属性名称,并在其名称后附加“指定”字样)。
如果约翰桑德斯的回答是真的,你仍然受到限制。
It turns out that the WSDL is not used to validate incoming XML. It wouldn't matter whether or not you could specify minOccurs - it would not be used to validate the input.
关于asp.net - 如何将 minOccurs 设置为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1156498/