locked
The formatter threw an exception while trying to deserialize the message

    Question

  • Hi
    I got this error when programming in C# 2008

    The formatter threw an exception when trying to deserialize the message: Error while trying to deserialize parameter http://tempuri.org/:GetListSitesResponse. The InnerException message was' Error on line 1, position 314. The item 'http://tempuri.org/:anyType' contains data data contract 'http://tempuri.org/:Site'. The deserializer has no knowledge of any type that is assigned to this contract. Add the type corresponding to 'Site' to the list of known types (eg, using the attribute KnownTypeAttribute or adding it to the list of known types passed to DataContractSerializer). '. See InnerException for more information.

    This happen in my button_click event

    (this is a project on C# 2008 express windows form application)
    private void button1_Click(object sender, EventArgs e)
            {
                SiteDevelopmentReference.Service1SoapClient sd = new SiteDevelopmentReference.Service1SoapClient();
                listBox1.Items.AddRange(sd.GetListSites().ToArray());                   
            }

    I have a service reference from another project for the method GetListSite

    (this is a project from Visual development Studio 2008)
    public class Service1 : System.Web.Services.WebService
        {

            [WebMethod]
            [XmlInclude(typeof(SiteDevelopment.Site))]
            public ArrayList GetListSites()
            {
                return SiteDevelopmentManager.GetSiteList();              
            }
        }

    An this is referenced from another class on another project

    (this is a project on C# 2008 express )
    namespace SiteDevelopment
    {
        public class SiteDevelopmentManager
        {
            public static ArrayList GetSiteList()
            {
                SiteDal dal = new SiteDal();
                return dal.SelectSites();
            }

            public static Site GetSite(string id)
            {
                SiteDal dal = new SiteDal();
                return dal.SelectSite(id);
            }
        }
    }

    I test the method GetListSites

    [WebMethod]
            [XmlInclude(typeof(SiteDevelopment.Site))]
            public ArrayList GetListSites()
            {
                return SiteDevelopmentManager.GetSiteList();              
            }
    and is running fine displaying the xml that i neeed
    but when I use the button_click event the error appears

    Thanks in advance



    • Moved by Riquel_DongModerator Monday, February 15, 2010 3:21 AM this is not a WCF issue (From:Windows Communication Foundation)
    Wednesday, February 10, 2010 5:41 PM

All replies

  • I see you are using a Service Reference, which is a WCF client. Why not use a WCF service as well? WCF should be used for all new web service development.

    Also, I strongly suggest you not use the ArrayList class. ArrayList is a .NET 1.0 class that has been superseded by the generic list classes. For instance, List<object> is a nearly direct replacement for ArrayList.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Tuesday, February 16, 2010 2:51 AM
    Moderator
  • WCF is cool but non-MS older systems

    (like Avaya Dialog Designer)

    cannot process the crazy WSDL it makes.

    Thw WCFExtra project didn't seem to help much.

    It's just not backwards compatible enough.....

    Tuesday, April 19, 2011 8:58 PM
  • FYI, it's not a question of MS vs. non-MS systems. There are some systems that decided they didn't need to implement the entire WSDL standard. In particular, there are systems which don't process includes. The question should really be asked of the creators of those systems: why can't you support a standard that has been in place for a decade?
    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Tuesday, April 19, 2011 9:54 PM
    Moderator