Search code examples
c#wcfsoap.net-corexmlserializer

Restrict framework from adding optional tags in SOAP xml message in c# NetCore


I am working on a REST webapi that consumes a SOAP WS to query for invoices information. I am using SoapUI for testing and I get the correct information. But from my webapi when calling the autogenerated method the request includes all the optional attributes with a default value.

I tried many things and the only thing that worked was to delete all the optional attributes from the autogenerated method which proved the default values are the problem but I might need them if I want to add them as filters to get a specific invoice from another call. I also tryed adding a boolean property for each optional with "propertyNameSpecified" as mentioned here: https://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlserializer?view=netframework-4.8 but the information is there even though this properties are all false.

here is the WSDL for the WS: https://fwshomo.afip.gov.ar/wsfecred/FECredService?wsdl and the method is consultarComprobantes that gets an object of type: consultarComprobantesRequest. I can provide code but all this is autogenerated with visual studio's added service, please let me know if you need it anyway.

Result is an empty array when I know there is an invoice (i generated it) and can see it with SoapUI with the request without optional parameters (or correct ones to get to this specific invoice)


Solution

  • I fixed this modifying the proxy class by eliminating all optional members. Its not ideal for if I re-generate the proxy class the solution will no longer work but as long as I don't do that it will be ok. Whenever I need to send an optional member in the message I simply generate a new class that inherits from the one with only the optional parameters and define whichever optional member I need in the new class. The proxy method works with the instance of the new class with no problem because of it's inheritance, so no convertion is needed.