Service Reference is using Arrays instead of List, even when settings say to use List

后端 未结 2 556
难免孤独
难免孤独 2021-02-14 16:13

I\'m using Visual Studio 2010, and I\'ve got a service reference to a web service we created. Our methods return objects that contain generic List properties:

p         


        
2条回答
  •  抹茶落季
    2021-02-14 16:37

    Did you add a "Service Reference" or a "Web Reference"? It appears that the proxy was generated with the XmlSerializer instead of the DataContractSerializer. If the DataContractSerializer was used, you would have System.Runtime.Serialization... Attributes instead of the Xml.Serialization... attributes. How exactly did you generate this web reference? The updated XmlSerializer will convert all collections to Arrays, where as, the Datacontract serializer knows how to generate .Net DataTypes. Add Web Reference uses the XmlSerializer BTW.

    Also, I'm curious about your use of MessageBodyMember. Why are you trying to generate your own MessageContracts. Messing with MessageContracts can be very dangerous, especially if you don't know exactly what you are doing.

    Instead, try the following:

    [DataContract]
    public class ExampleResponse
    {
        private System.Collections.Generic.List intValues;
    
        [DataMember]
        public System.Collections.Generic.List IntValues
        {
            get { return intValues; }
            set { intValues = value; }
        }
    }
    

    See how that works for you and let us know.

提交回复
热议问题