Pass object to Webservice

Asked

Viewed 303 times

5

I’m starting the development using Webservice + Windows Form and I did some silly methods passing parameters, however, I came up with the idea of passing an object as parameter where the Web Service would return me a string any concatenating each data, so far so good. The problem is, how can I pass an Object that is in the Windows Form Solution to Webservice?

Both would have to have the same basic class?

I did more or less like this in Windows Form:

 private void button1_Click(object sender, EventArgs e)
    {
        Funcionario.FuncionarioSoapClient func = new Funcionario.FuncionarioSoapClient();
        Cliente c = new Cliente();
        c.Nome = "JR";
        c.Idade = 20;
        func.Concatena(c);

    }

But I get the error: cannot Convert from 'Webservice...' to 'Webserivce...'

Overall, how do I do this? pass a windows form object to the webservice?

  • It depends. What kind of web service do you have? WCF, ASMX or ASP.NET Webapi?

1 answer

1

Unable to pass an object to the webservice.

You have to convert the object to string and send the string to the webservice and in the webservice convert the string to an object again.

Normally I use Json to turn the object into a string.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.