locked
How to Pass dynamic parameters to a WCF Service ? RRS feed

  • Question

  • User-1634172812 posted

    Hi,

    I am writing a WCF Service (REST) and about to Pass the Parameters to the service dynamically.

    example: Here, The Passanges details will save in Database based on the input selection.

    If the Adult Count is 2, the Value of two Adults should store in Database by the Service.

    Value of Adult should pass like this,(Example)

    Adult1: Title:Mr Firstname: Thiri Lastname:Sangu, Adult2:Title:Mr Firstname:Sontu LastnameLSandeep

    The Same Parameter will apply for Child and Infant too.

    Please, Help me to Proceed further.

    1.  What method should i use to call the service ?(POST or GET)

    2.  How to pass of group of values(Adult count is 2) to a Service ?

    Thanks




    Friday, March 29, 2013 2:35 AM

Answers

  • User-1658256289 posted

    Hi,  if you want to post data to rest service dynamically, you can consider creating Dynamic Data Entry User Interfaces for the client. I do not come out a better way until now. Creating Dynamic Data Entry User Interfaces:

    http://msdn.microsoft.com/en-us/library/aa479330.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 2, 2013 5:46 AM

All replies

  • User220959680 posted

    Adult1: Title:Mr Firstname: Thiri Lastname:Sangu

    Passenger class with properties as below.

    public class Passenger
    {
       public string firstName{get;set;}
       public string lastName{get;set;}
       //To store Adult/Infant etc. 
       public string pType{get;set;}
    
    }

    Service method accepts an instance of (object) Passenger from client.

    What method should i use to call the service ?(POST or GET)

    POST. (Http POST)

    service consumer POSTs data to the service, where service reads the data and inserts into database.

    How to pass of group of values(Adult count is 2) to a Service

    Create list of passenger class and add each passenger to the list and POST to the service.

    List<Passenger> passengers = new List<Passenger>();
    
    //passenger 1
    Passenger p1 = new Passenger();
    
    //Below comes from the UI 
    p1.FirstName = "David";
    p2.LastName = "Harper";
    p2.Type = "Adult";
    
    //Add passenger 1 to the list
    passengers.Add(p1);
    
    //same for rest of passengers
    

    Service url (example); http://localhost:<serviceName>/Passenger/<object passed from the client>

    http://www.codeproject.com/Articles/201901/CREATE-RESTful-WCF-Service-API-Using-POST-Step-By

    http://forums.asp.net/t/1830710.aspx/1

    Let me google that for you

    Friday, March 29, 2013 10:08 AM
  • User-1634172812 posted

    Thanks for your repy. The Passanger details is assigned by the User dynamically.

    How do i do that ? And How to Construct the URL of the Service or How the URL will look like ?

    Thanks again.

    Saturday, March 30, 2013 12:28 AM
  • User-1658256289 posted

    Hi,  if you want to post data to rest service dynamically, you can consider creating Dynamic Data Entry User Interfaces for the client. I do not come out a better way until now. Creating Dynamic Data Entry User Interfaces:

    http://msdn.microsoft.com/en-us/library/aa479330.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 2, 2013 5:46 AM