Search code examples
c#.netweb-serviceswcfcorewcf

Serialization issue in the passing an array in the CoreWCF service


I am working on migrating an old WebService from .NET (.asmx) to a CoreWCF SOAP service. The intention is to move from .NET Framework 4.0 to .NET 6/8 without affecting any upstream dependencies.

Mostly, the migration has been successful, but there is one use case that is failing. The old WebService has an API that accepts a string array as input. However, when I implemented the same parameters in CoreWCF, the incoming array is always received as empty.

The key difference I noticed is in the exported WSDL. The CoreWCF service specifies a namespace for the array element as “http://schemas.microsoft.com/2003/10/Serialization/Arrays,” whereas the older WebService did not have any specific namespace for that array element.

My primary suspicion is that CoreWCF is unable to deserialize the array due to the message inspectors I added I see these inspectors retrieve the values before they are passed to the operation. I also attempted to modify the request before sending it to the operation, but this approach is neither elegant nor effective.

I would greatly appreciate any guidance on resolving this issue.


Solution

  • You can create custom class like below (change the Namespace as per your need)

    [CollectionDataContract(Name = "ArrayOfString", Namespace = "http://example.com/Report", ItemName = "string")]
       [Serializable]
       public class ArrayOfString : List<string>
       {
       }