I am consuming a 3rd party SOAP service into my C# .NET Core console application.
To do so, I added in the service reference, by importing the WSDL (Add --> Connected Service --> WCF Web Service).
The service exposes a method called "Order", which takes in an OrderRequest
parameter
OrderResponse Order(OrderRequest request);
And the OrderRequest
is defined like this:
public partial class OrderRequest
{
private string fMethod;
private KVPfield[] searchFields;
}
Nothing too exciting about the KVPfield
object, it just looks like this:
public partial class KVPfield
{
private string fKey;
private string fValue;
}
So in my mind, EASY, just define an array of KVPfield
's and assign that to the OrderRequest
:
var orderReq = new OrderRequest();
orderReq.fMethod = "save";
orderReq.searchFields= new KVPfield[] {
new KVPfield() { fKey = "EPID", fValue = "XY111359" },
new KVPfield() { fKey = "VSN", fValue = "HTP000157A" }
};
But now when I execute the method
var resp = svc.Order(orderReq);
But then it throws the following error:
System.ServiceModel.CommunicationException: 'There was an error in serializing body of message OrderRequest: 'CodeGenError(IsNotAssignableFrom): Cannot convert source type [svc.KVPfield[]] to target type [svc.KVPfield].'.
Why if my WSDL's is asking for an ARRAY of KVPfield
, is it expecting a single KVPfield
?
Is it something to do with how I am defining my KVPfield[]
, or something in the internals of the wsdl?
Found the issue.
The generated C# code, was riddled with
KVPfield[][]
I just changed those to
KVPfield[]
and all works fine now.