0

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?

1 Answer 1

3

Found the issue.

The generated C# code, was riddled with

KVPfield[][]

I just changed those to

KVPfield[]

and all works fine now.

Sign up to request clarification or add additional context in comments.

1 Comment

i was converting legacy code from .NET48 to .NET80 and using dotnet-svcutil to do the codegen against a local .wsdl. It was seemingly getting confused with the structure of the .wsdl at the point of trying to generate and send the request i was getting CodeGenError(IsNotAssignableFrom): Cannot convert source type [System.String[]] to target type [System.String]. If only i'd found this earlier, would have saved me hours of wasted time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.