如何设置的minOccurs到1如何设置、minOccurs

2023-09-04 00:52:01 作者:人间仙子

我要建一个ASP.NET Web服务。

我有我的code定义如下,但我无法弄清楚如何在WSDL中指定名字和姓氏属性的minOccurs。我希望这些要求,并不能为空。这可能吗?

  [WebMethod的()
公共无效TestMethod的(TestClass的测试)
{
    ...
}

[可序列化]
公共类识别TestClass
{
    公共字符串名字{获得;组; }
    公共字符串名字{获得;组; }
}
 

解决方案

我已经发布了详细的解答上有同样问题的另一个线程:的如何使DOTNET Web服务设置的minOccurs =1的字符串值。

不过,对于字符串的答案是否。

只有这样做的的minOccurs = 1 的没有的可空=真的是用声明属性的没有默认值(字符串有一个默认值中的的String.Empty )和无属性检查是否是指定的值(使相同的属性名称指定字样追加到它的名称)。

而你仍然是有限的,如果约翰·桑德斯的回答是真实的。

  

事实证明,在WSDL不用于验证传入XML。它不会有问题是否可以指定的minOccurs - 它不会被用来验证输入

I'm building an ASP.NET web service.

怎么修改mindmaster这款思维导图的默认设置

I've got my code defined as below, but I can't figure out how to the the wsdl to specify the minOccurs of the FirstName and LastName properties. I want those as required, and can not be empty. Is it possible?

[WebMethod()]
public void TestMethod(TestClass Test)
{
    ...
}

[Serializable]
public class TestClass
{
    public string FirstName { get; set; }
    public string LastName { get; set; }    
}

解决方案

I have posted the detailed answer on another thread with the same problem: How to make a dotnet webservice set minOccurs="1" on a string value.

However the answer for strings is no.

The only way make minOccurs=1 without nullable=true is to declare a property with no default value (string has a default value of String.Empty) and without a property to check if the value was specified (making an identical property name with "Specified" word appended to it's name).

And you are still limited if John Saunders' answer is true.

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.

 
精彩推荐