Pass class as a function parameter in client program WCF C# -


i have written wcf program have class library declared function contains class parameter.

i accessed function in client program don't know how pass class function. write code below.

  1. i have interface contains basic function declaration
  2. in class library there class implementing interface. interface contains method takes class parameter.

that class parameter contains properties.

[servicecontract] public interface icardetails {     [operationcontract]     string updatecardetails(car c); }  public class cardetails : icardetails {     public string updatecardetails(car c)     {         //some operations , initilizations         string example = car.carno = "1234";         return "success";     } }  public class car {     private string carno;     private string carmodel;      public string carno     {         get{ return carno; }         set{ carno = value; }      }      public string carmodel     {         get{ return carmodel; }         set{ carmodel = value; }     } } 

3) access function in myclient program consume. while consuming need send class right? if how can send class.

class program {     static void main(string[] args)     {         cardetailsserviceclient client = new cardetailsserviceclient();         string abc = client.updatecardetails(); // shows error     } }  public class carclient {     public string carno = "6789"; } 

i want send client class carclient wcf service function updatecardetails.

you can't pass class, must pass object of class. create new object :

car carclient = new car() { carno = "6789" }; 

then, pass in argument :

string abc = client.updatecardetails(carclient); 

car must include in datacontract :

[datacontract] public class car {     private string carno;     private string carmodel;      [datamember]     public string carno     {         { return this.carno; }         set { this.carno = value; }     }      [datamember]     public string carmodel     {         { return this.carmodel; }         set { this.carmodel = value; }     } } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -