在ASP.NET Web服务的可选参数可选、参数、ASP、NET

2023-09-02 21:46:35 作者:国际女疯纸

我有一个ASP.NET Web服务。此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.

在我看来,所有的原始类型(整型,布尔型等)是不可选的,所有其他参数都被标记为可选。但是,我找不到在哪里我可以改变这个位置。我想指定默认值,如果缺少在请求中的原始值,并指定非基本参数实际上是可选的。我在哪里做?

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.

我会建议您切换到WCF与basisHttpBinding(除了你服务你的客户应该不会注意到差别的名称)。

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")]