You must Sign In to post a response.
  • Category: WCF

    How to pass a class as a parameter in wcf

    Hi every one,
    i trie'd to pass class as a parameter in wcf for mobile application.and how i can retrive that class data with loop in wcf.i hope u are all understand.
    thank u.
  • #770391
    you need to create a model for your requirement and then pass that parameter like wanted to pass location class as parameter to wcf end point then

    creation of model for location

    class location{
    private int loc_id;
    private string loc_name;
    }

    creation of wcf method

    public IActionResult SaveLocation(Location location)
    {
    // action
    }

    Thanks!
    B.Ramana Reddy

  • #770401
    I will be able to use this function in my client software. I must send a class while eating, am I right? In that case, how can I send a class?
    class Program
    {
    static void Main(string[] args)
    {
    CarDetailsserviceClient client = new CarDetailsserviceClient();
    string abc = client.updateCarDetails(); // This shows error
    }
    }

    public class carclient
    {
    public string carno = "6789";
    }

  • #770415
    1) Create class
    public class SampleClass
    {
    public string SampleVarA { get; set; }
    public string SampleVarB { get; set; }
    public string SampleVarC { get; set; }
    }

    2) Define contract as below
    [OperationContract]
    [WebInvoke(Method = "POST",
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/MyWcfMethod")]
    string MyWcfMethod(List<SampleClass> myInput);
    3) Implement the method as below
    public string MyWcfMethod(List<SampleClass> myInput)
    {
    var result = string.Empty;
    foreach (var item in myInput)
    {
    result += item.SampleVarA;
    result += "--";
    }
    return result;
    }

    4) U can send the object as json collection from UI


  • Sign In to post your comments