ASP.NET Web 服务中的可选参数

发布于 2024-07-24 06:54:37 字数 283 浏览 7 评论 0原文

我有一个 ASP.NET Web 服务。 该网络服务运行良好。 但是,WSDL 将某些参数列为可选(minoccurrs = 0),将其他参数列为非可选。 一些可选参数实际上不是可选的,其他标记为非可选的参数实际上是可选的。 我想解决这个问题,但我找不到此信息的来源位置。

在我看来,所有原始类型(int、boolean 等)都是非可选的,所有其他参数都标记为可选。 但是,我找不到可以更改此设置的位置。 如果请求中缺少原始值,我想指定它们的默认值,并指定哪个非原始参数实际上是可选的。 我在哪里做这个?

I have a ASP.NET web service. This web service works fine. However, the WSDL lists some parameters as optional (minoccurs = 0) and others as non-optional. Some of the optional parameters are actually not optional, others which are marked as non-optional are actually optional. I would like to fix this, but I can't find the location where this information is coming from.

It seems to me that all primitive types (int, boolean etc.) are non-optional and all other parameters are marked as optional. However, I can't find a location where I can change this. I would like to specify default values for the primitive values if they are missing in the request and specify which non-primitive parameter is actually optional. Where do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑脸一如从前 2024-07-31 06:54:37

我假设当您说 ASP.net Web 服务时,您正在创建具有 ASMX 扩展的 Web 服务。 我认为在这种情况下发生的情况是所有可为空的类型都变为可选,不可为空的类型变为非可选。

您也许可以手动编辑生成的 WSDL 文件。 但是如果重新生成了 wsdl,您就必须重做这项工作。

我建议您使用 basicHttpBinding 切换到 WCF(除了您的服务名称之外,您的客户不应注意到差异)。

使用 WCF,您可以简单地根据需要或不需要标记数据协定中的参数:

[DataMember(IsRequired="false")]

I am assuming that when you say ASP.net web services, you are creating web services with ASMX extension. I think that what happens in this case is that all nullable types become optional and non-nullable become non-optional.

You could perhaps manually edit the generated WSDL file. But then you would have to redo that work if the wsdl was regenerated.

I would suggest that you switch to WCF with basisHttpBinding (except for the name of you service your clients should not notice the difference).

Using WCF you can simply mark the parameter in the data contract as required or not:

[DataMember(IsRequired="false")]
滴情不沾 2024-07-31 06:54:37

原语不是引用类型,而是类型。 您可以通过几种方式将类型设置为“可空”。

这里是短手

int? i;

还是长手

Nullable<int> i;

The primitives are not reference types, but rather they are value types. You can make a value type "nullable" a couple ways.

The short-hand is

int? i;

or long-hand here

Nullable<int> i;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文