Search code examples
wcfdtorestsharp

WCF and Data Transfer Object


I am stuck on this simple question. In my console application, I want to consume a wcf service. So I add the web reference to the project and call it. That is it.

But why I saw some examples especially using RESTSHARP, they never add web reference. They just use so called "DTO" to return object by the service and consume it.

I hope somebody can clarify the concepts for me. Is DTO used inside WCF?

sample:

private static List<ApplicationDTO> features;
RestClient client = new RestClient("http://" + baseUrl + "/FacilityData.svc");
var request = new RestRequest(Method.GET);
request.Resource = "/GetFeatures";
request.Parameters.Clear();
request.AddParameter("Id", 888);
var response = client.Execute(request);
features = JsonConvert.DeserializeObject<List<ApplicationDTO>>(response.Content);

Solution

  • from this post:

    For REST service, it provides a generic way for WCF service consuming which doesn't rely on the SOAP. That's why we no longer need "Add ServiceReference..." for consuming it. REST service operations can be accessed through standard HTTP GET/POST request, so any webrequest enabled client can consume it. For example, you can use HttpWebRequest to invoke a REST operation and use LINQ to XML to load and extract values from the response XML data. It's very flexible.

    DTO, usually used for Data Transfer Object - is nothing more then entity you want to pass as parameter / receive as a result.

    In your example, ApplicationDTO - is probably some entity to hold Data about Application Feature object (Name, Type, ...)