Question : Parameters and return type in a webservice

Hi!

What are limitation?

I've tried to use my own class that use a dictionary and I got an error that makes problem. How can I solve it?

Thank you!

here is the error message:
Server Error in '/' Application.
Impossible de sérialiser le membre TestWcf.MyMessageClass.Changes de type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], car il implémente IDictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Impossible de sérialiser le membre TestWcf.MyMessageClass.Changes de type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], car il implémente IDictionary.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace TestWcf
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://myFirstdummyanddirtynamespace.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public List<MyMessageClass> HelloWorld(int nb)
        {
            List<MyMessageClass> responses = new List<MyMessageClass>();
            for (int i = 0; i < nb; i++) {
                MyMessageClass currentResponse = new MyMessageClass() { DataType= "MyType1", Id= i};
                for (int j = 0; j < nb; j++)
                {
                    currentResponse.Changes.Add("MyField" + j, "myValue" + j);
                }
            }
            return responses;
        }
    }
    public class MyMessageClass
    {
        public MyMessageClass() {
            Changes = new Dictionary<string, string>();
        }

        public string DataType;
        public int Id { get; set; }
        public Dictionary<string, string> Changes { get; set; }
    }

}

Answer : Parameters and return type in a webservice

Hum, i changed it into a List of a custom object that contains two string and it works now god.  I think it's the Dictionnary type that isnn't allowed.
Random Solutions  
 
programming4us programming4us