ASP.NET Web 服务中的可选参数 [英] Optional parameters in ASP.NET web service

查看:33
本文介绍了ASP.NET Web 服务中的可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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?

推荐答案

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

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.

您或许可以手动编辑生成的 WSDL 文件.但是,如果重新生成 wsdl,您将不得不重做这项工作.

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

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

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

使用 WCF,您可以简单地将数据协定中的参数标记为是否需要:

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

[DataMember(IsRequired="false")]

这篇关于ASP.NET Web 服务中的可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆