asp.net - 如何将 minOccurs 设置为 1

标签 asp.net .net web-services wsdl asmx

我正在构建一个 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/

相关文章:

c# - 事件句柄和可见

c# - 从 uint32 获取特定位

c# - 修剪字符串末尾的字符串

java - Swagger UI 显示,但我得到一个 "ERROR"指示器

.net - 应用程序图标未显示在控制面板中 'Add/Remove Programs'

web-services - 从 Tomcat 上运行的 CXF 网络服务获取 WSDL

java - 使用 PHP 脚本在免费虚拟主机上创建 Web 服务

java - cxf-codegen-plugin 不符合 cxf ValidationFeature

javascript - 从后面的 ASP.NET C# 代码解析二维数组到 Javascript

c# - GAC 使用什么来记录 DLL