加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 在int类型的Web服务参数上设置minOccurs =“0”(不是

发布时间:2020-12-16 07:21:54 所属栏目:asp.Net 来源:网络整理
导读:我有一个带有以下签名的ASP.NET 2.0 Web方法: [WebMethod]public QueryResult[] GetListData( string url,string list,string query,int noOfItems,string titleField) 我正在运行disco.exe工具从此Web服务生成.wsdl和.disco文件,以便在SharePoint中使用.正
我有一个带有以下签名的ASP.NET 2.0 Web方法:

[WebMethod]
public QueryResult[] GetListData(
    string url,string list,string query,int noOfItems,string titleField)

我正在运行disco.exe工具从此Web服务生成.wsdl和.disco文件,以便在SharePoint中使用.正在生成以下用于参数的WSDL:

<s:element minOccurs="0" maxOccurs="1" name="url" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="list" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="query" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="noOfItems" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="titleField" type="s:string" />

为什么int参数将minOccurs设置为1而不是0,我该如何更改?

我试过以下但没有成功:

参数声明中的[XmlElementAttribute(IsNullable = false)]:没有区别(正如您想到的那样)
参数声明中的[XmlElementAttribute(IsNullable = true)]:给出值类型System.Int32的错误“IsNullable可能不是’true’.请考虑使用Nullable.”
>将参数类型更改为int? :保持minOccurs =“1”并添加nillable =“true”
参数声明中的[XmlIgnore]:参数永远不会输出到WSDL

解决方法

您可以使用以下方式使WSDL看起来如您所愿:

[WebMethod]
public QueryResult[] GetListData(
    string url,[XmlElement(DataType = "integer")] string noOfItems,string titleField)

这个想法是你可以告诉对方它必须是一个整数,但你的内部类型可以是字符串,因此不需要该字段.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读