且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-15 19:43:52

我假设当您说 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")]