Thursday, October 26, 2023

Inbound SOAP web service in Dynamics 365 Finance needs enum as non extensible

This was a weird one for me, If an inbound SOAP service in X++ expects an enum, such that the contract class defines in the following way


[DataContractAttribute]
public final class myContract 
{
    myEnum myEnum ;
    [DataMemberAttribute('myEnum')]
    public myEnum parmMyEnum (myEnum _myEnum = myEnum )
    {
        myEnum = _myEnum ;
        return myEnum ;
    }
}

Then you need to make sure that the extensible property on mEnum is set to false.

 

Otherwise you get the error in the following format
         <faultstring xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org:myContract . The InnerException message was 'Invalid enum value 'None' cannot be deserialized into type 'Dynamics.AX.Application.myEnum '. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'.  Please see InnerException for more details.</faultstring>


In essence, the inbound services do not seem to allow extensible enums

In addition, to create a list type of contract classes, I have found this to be the cleanest way

[Newtonsoft.Json.JsonObjectAttribute(IsReference = false)]//Remove $id from Custom Web Service JSON
public class LOKInventoryServiceOutputContractList  
{
    protected List                    inventoryOutputContract;

    [DataMemberAttribute("InventoryList"),
    DataCollectionAttribute(Types::Class, classStr(LOKInventoryServiceOutputContract))]//the name of the class that will be in the list
    public List parmInventoryOutputContract(List _inventoryOutputContract = inventoryOutputContract)
    {
        inventoryOutputContract = _inventoryOutputContract;
        return inventoryOutputContract;
    }

}

No comments:

Post a Comment