How to send an object to an Asp.NET C # webservice?

1

I need to send an object of a class that I created to a webservice, but when I call the method it passes the object it types are incompatible. I tried to receive the object as Object, but an error generating XML document. How can I send this object?

Example: User:

[Serializable]
public class Usuario 
{ 
   String _Nome; 

   public String Nome { 
      get { return _Nome;} 
      set { _Nome = value; } 
   } 
} 

A method that passes an object to my webservice as follows:

{
... 
WS.InformarNome(usuario); 
}

And the webservice receives the user:

public void InformarNome(Usuario u) { ... }
    
asked by anonymous 26.12.2014 / 12:38

1 answer

1

Use Json, leave the method receiving a string that in this case will be the object and then upon receiving this serialized object, just use the proper .net api to convert to the object.

public string Cadastro(string json)
        {
            Aluno aluno= JsonConvert.DeserializeObject<Aluno>(aluno);
        }
    
26.12.2014 / 14:15