Problem passing array of objects in Dictionary class from WebService to ASP consumer.

Last post 05-16-2008 9:03 AM by zombieboy. 2 replies.

Sort Posts:

  • Problem passing array of objects in Dictionary class from WebService to ASP consumer.

    05-04-2008, 11:20 AM
    • Loading...
    • zombieboy
    • Joined on 04-16-2008, 5:04 PM
    • Posts 8

    I try passing an array of objects from my webservice in 2008 VS c# to an ASP c# client. What construction is easiest? I'm happy with anything that manage to pass an array objects containing one integer and a few strings.

     I would like to use foreach constructs or similar at client (to keep it simple for clients). 

    I tried to use Dictionary class I quickly found out that Dictionary<key,object> doesn't serialize ( why not is beyond my imagination - it's a bit like designing a car but forget to include a steeringwheel )

     So I tried to use XML Serializable Generic Dictionary from http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx

    However the client doesn't get back data even if I see when debugging that inside the webservice,  blogs variable is successfully populated. Not sure if I need to call WriteXML /ReadXML myself?

     

     ------------------   Server Code 

    [WebMethod]public SerializableDictionary<int, BlogItem> SearchFreeTextBlog(string SearchText)

    {

    SerializableDictionary<int, BlogItem> blogs = new SerializableDictionary<int, BlogItem>();

    blogs = DBSearchBlogs(SearchText);

    return blogs;

    }

     ------    client code

    WebServiceBlog2.Service serviceBlog = new WebServiceBlog2.Service();

    // commented out: SerializableDictionary<int, BlogItem> blogs = new SerializableDictionary<int, BlogItem>();

    DataSet blogs = serviceBlog.SearchFreeTextBlog("asp.net");

    // Web service returns a SerializableDictionary<int, BlogItem> , but client code compile only if using a DataSet , why?

    System.Console.Write( blogs.ToString() ); // blog is empty at client

    GridViewBlogs.DataSource = blogs; // exception "The IListSource does not contain any data sources."

    Thanks a million!

    QA4Ever

  • Re: Problem passing array of objects in Dictionary class from WebService to ASP consumer.

    05-09-2008, 4:57 AM
    Answer

    Hi QA4Ever,

    I don't try the code from the blog, so I can't tell you why you are getting the problem. Since it is a common issue, you can search lots of sample on the web with code, like:

    http://www.codeproject.com/KB/XML/deepserializer.aspx

    http://search.microsoft.com/results.aspx?q=serialize+dictionary+sample&qsc0=0&FORM=QBME1&l=1&mkt=en-US&PageType=99

    Best regards,
    Guang-Ming Bian - MSFT

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Problem passing array of objects in Dictionary class from WebService to ASP consumer.

    05-16-2008, 9:03 AM
    • Loading...
    • zombieboy
    • Joined on 04-16-2008, 5:04 PM
    • Posts 8

    In the end I returned a DataTable since it did all the serializing itself.

    Saved me labour time at least.

    QA4Ever.

Page 1 of 1 (3 items)