Complex data types in WCF?

后端 未结 14 1062
自闭症患者
自闭症患者 2020-12-12 19:48

I\'ve run into a problem trying to return an object that holds a collection of childobjects that again can hold a collection of grandchild objects. I get an error, \'connect

相关标签:
14条回答
  • 2020-12-12 20:27

    I've had this error when using 'yield return' to build up an enumeration of objects mapped to my DataContract type.

    Calling ToList / ToArray on the yield results fixed the issue and the service call worked correctly.

    0 讨论(0)
  • 2020-12-12 20:28

    Ok i finally found the real problem in my case. It seems exposing enums is not the greatest thing in the world. I either have to set a default value on them, or instead expose the property as an int or whatever integer-type my enum is based on.

    Thanks for helping, you had no way of knowing this - i found the enums on the 3rd level in my structure and systematicly removing datamembers one by one was the way i found out. It seems i'm not the only one who ran into this problem - this guy obviously had similar problems :)

    http://zianet.dk/blog/2007/11/24/serializing-enums-in-wcf/

    0 讨论(0)
  • 2020-12-12 20:29

    Don't return the literal IEnumerable in a contract, there is the famous WCF IEnumerable bug

    0 讨论(0)
  • 2020-12-12 20:30

    If you are working with WCF+(EF+POCO) then try setting,

    ObjectContext.ContextOptions.LazyLoadingEnabled = false;
    ObjectContext.ContextOptions.ProxyCreationEnabled = false;
    
    0 讨论(0)
  • 2020-12-12 20:32

    this is actually the same information as your first exception description. it would be interesing what the original cause for the socketexception was. it has to be some type of error in the service itself. can you locate where exactly whar exception happens?

    i had similar errors when trying to return normal IEnumerables that were overwritten (they were marked as virtual) by NHibernate, and substitued with GenericPersistentBag, which is not serializable. have you marked your IEnumerable datamembers as virtual due to nhibernate or something similar? this could explain your error.

    btw. wcf exceptions are often quite meaningless (which can be very frustrating when tracking down a bug ;)

    0 讨论(0)
  • 2020-12-12 20:33

    As a note, you need to learn how to use the WCF logging utilities:

    Logging info.

    Config Editor (makes it a snap to setup).

    Trace viewer. Totally awesome. Allows multiple services (client and server) to trace and can join them and help you analyse all the details. Lets you get to the root of issues really fast. (Cause when there's a server WCF error, the client is unlikely to get useful data out.)

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