Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Service Passing parameter Class

Hello I have a web service that has a parameter class

    [WebMethod]
    public int Customers(Customer _customers)
    {

        Customer getCustomer = new Customer();
        getCustomer.ID = _customers.ID;
        getCustomer.FirstName = _customers.FirstName;
        getCustomer.LastName = _customers.LastName;

        return 0;
    }

now I have a C# console application calling the webservice

        ServiceReference1.WebService1SoapClient _client = new WebService1SoapClient();

        Customer _customers = new Customer();
        _customers.ID = 1;
        _customers.FirstName = "FirstName";
        _customers.LastName = "LAstName";

        _client.Customers(_customers);

one the _client.Customers(_customers); I have an error

"cannot convert from 'Customer' to 'WRTC_BACKUPDB.ServiceReference1.Customer'"

like image 236
user2530833 Avatar asked Jun 09 '26 06:06

user2530833


1 Answers

It seems that you have 2 Customer classes on the client side

Changing

Customer _customers = new Customer();

to

var _customers = new WRTC_BACKUPDB.ServiceReference1.Customer();

Should solve this, although you should also determine where the other Customer class came from.

It may be that the console client has both a proxied Customer class created by the wizard when adding the Service Reference, and it also directly references the original Customer class used on the server assembly. If you wish to share the same class between client and server, there is an option to reuse type in the Service Reference wizard.

(also from a naming convention viewpoint, I would also change the variable name to _customer)

like image 175
StuartLC Avatar answered Jun 11 '26 22:06

StuartLC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!