Optional parameters in ASP.NET web service

前端 未结 2 1538
旧时难觅i
旧时难觅i 2020-12-11 16:09

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 option

相关标签:
2条回答
  • 2020-12-11 16:44

    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")]
    
    0 讨论(0)
  • 2020-12-11 16:46

    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;
    
    0 讨论(0)
提交回复
热议问题