Pass the array list to the WCF application

后端 未结 2 1978
孤城傲影
孤城傲影 2021-01-24 07:37

I am new to WCF. I have a scenario where i have \"Error.

When i am trying to pass the arr

相关标签:
2条回答
  • 2021-01-24 07:44

    This line is the problem, from the service:

    object[] GetCommisionResponse(object[] loc_);
    

    What you've told WCF here is that you're going to be returning an array of Object. Because of that, the client expects to get back an array of Object. That of course is not what you're actually giving it.

    Subclasses don't work the same way in WCF that they work elsewhere. You have to explicitly define in the service what you're returning, because the client has to know what to expect and create classes for.

    So if you're actually returning an array of Flight, change it to this:

    Flight[] GetCommisionResponse(object[] loc_);
    

    But if you're returning something and some subclasses of itself, you'll have to use the KnownType attribute.

    [KnownType(typeof(FlightSubClass))]
    Flight[] GetCommisionResponse(object[] loc_);
    

    You can do the same thing on the Interface using ServiceKnownType, and only have to do it once.

    0 讨论(0)
  • 2021-01-24 08:06

    When you generate the Service reference, you should set the CollectionType to System.Collections.Arraylist - if you use the UI it's in the Advanced section, if you use svcutil.exe it's the /ct switch

    There's a lot more information in Collections in Data Contracts on MSDN

    0 讨论(0)
提交回复
热议问题