1

I was having problems sending an object that has 3 properties, the problem is with the array of customers while sending I have the following error object:

You can not serialize member. Because it is an interface.

if the property off customers ws works very well. I have tried in various ways to eliminate the error but none seems to work left a fragment of code so that they can give me their point of view. thank you very much

public class CustomersResponse
{
    public bool Success { get; set; }
    public string Error { get; set; }
    public customer[] ListCustomers { get; set; }
}

and the code of ws is

/// <summary>
/// 
/// </summary>
[WebService(Namespace = "http://tempuri.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 wsCustomers : System.Web.Services.WebService
{
    [WebMethod]
    public CustomersResponse CustomersResult()
    {
        CustomersResponse customers = new CustomersResponse ();
        try
        {
            using (var context = new DataContext())
            {
                customers.Success = true;
                customers .Error = string.Empty;
            }
        }
        catch (Exception ex)
        {
            customers .Success = false;
            customers .Error = ex.Message.ToString();
        }

        return customers ;
    }
}

if I delete the property ListCustomers the ws works well, if I put marks the mistake :(

Vesper
  • 375
  • 1
  • 8
  • 14
  • What is the definition for `customer`? Is it an interface or a class? – Tim Jul 14 '16 at 07:27
  • Possible duplicate of [Cannot serialize member.... because it is an interface](http://stackoverflow.com/questions/3632769/cannot-serialize-member-because-it-is-an-interface) – Tim Jul 14 '16 at 07:28
  • Can you post the code for you the `customer` class? Is there something in that class that may be returning an interface? – Tim Jul 14 '16 at 16:51

2 Answers2

0

you need to put [Serializable] metatag before your customer class.

[Serializable]
public class customer
{

//....

}

Nikhil
  • 46
  • 5
0

I could already solve the problema.cual was the solution I have a model called customers EntityFramework used. another class was created with the same attributes customers and already works ws think when compiling the application does something that affects customers and so brand that exception.

Vesper
  • 375
  • 1
  • 8
  • 14