有效的 ASP.NET Webmethod 返回类型有哪些?
我的 webmethod 只能返回像我在所有 asp.net 站点示例中看到的字符串吗?
Can my webmethod only return strings like I see in all the asp.net site examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
asp.net Webmethods 可以返回任何可序列化的数据类型。
asp.net Webmethods can return any serializable data type.
假设此问题与旧版 ASMX Web 服务技术有关,请参阅 使用 ASP.NET 创建的 XML Web 服务支持的数据类型。
一定要注意它说的地方:
Assuming that this question is about the legacy ASMX web service technology, see Data Types Supported by XML Web Services Created Using ASP.NET.
Be sure to take note of where it says:
据我所知,您几乎可以返回任何 .NET 类,包括匿名类型。 我已返回代表我的业务实体的自定义对象,包括子实体的通用集合。 Guid、整数、字符串等。基本上任何可以序列化为字符串的东西。
As far as I know, you can pretty much return any .NET class, including anonymous types. I've returned custom objects representing my business entities, including generic collections of children entities. Guids, ints, strings, etc. Anything that can be serialized into a string basically.