0

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);
4

1 回答 1

1

这篇文章:

对于 REST 服务,它提供了一种不依赖 SOAP 的 WCF 服务消费的通用方式。这就是我们不再需要“添加 ServiceReference...”来使用它的原因。REST 服务操作可以通过标准的 HTTP GET/POST 请求访问,因此任何启用 webrequest 的客户端都可以使用它。例如,您可以使用 HttpWebRequest 调用 REST 操作并使用 LINQ to XML 从响应 XML 数据中加载和提取值。它非常灵活。

DTO,通常用于数据传输对象 - 只不过是您想要作为参数传递/作为结果接收的实体。

在您的示例中, ApplicationDTO- 可能是一些实体来保存有关应用程序功能对象(名称,类型,...)的数据

于 2013-04-25T13:48:22.623 回答