wcf数据服务将响应格式化为xml

时间:2014-02-05 08:37:03

标签: c# xml wcf

我已经创建了像这样的wcf数据服务

public class Northwind : DataService< SelfServiceEntities >
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("SMS", EntitySetRights.AllRead
                | EntitySetRights.WriteMerge
                | EntitySetRights.WriteReplace);
        }
    }

当我请求此网址时

http://localhost:2242/Northwind.svc/SMS

我得到了这个回复

<?xml version="1.0" encoding="utf-8"?><feed xml:base="http://localhost:2242/Northwind.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><id>http://localhost:2242/Northwind.svc/SMS</id><title type="text">SMS</title><updated>2014-02-05T08:33:49Z</updated><link rel="self" title="SMS" href="SMS" /><entry><id>http://localhost:2242/Northwind.svc/SMS(1)</id><category term="SelfServiceModel.SM" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" title="SM" href="SMS(1)" /><title /><updated>2014-02-05T08:33:49Z</updated><author><name /></author><content type="application/xml"><m:properties><d:ID m:type="Edm.Int32">1</d:ID><d:number>1</d:number><d:body_ar>1</d:body_ar><d:body_en>1</d:body_en></m:properties></content></entry><entry><id>http://localhost:2242/Northwind.svc/SMS(2)</id><category term="SelfServiceModel.SM" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" title="SM" href="SMS(2)" /><title /><updated>2014-02-05T08:33:49Z</updated><author><name /></author><content type="application/xml"><m:properties><d:ID m:type="Edm.Int32">2</d:ID><d:number>55</d:number><d:body_ar>55</d:body_ar><d:body_en>55</d:body_en></m:properties></content></entry></feed>

我的问题

如何将响应格式化为xml?

我做了一个研究,我找到了这个链接 http://msdn.microsoft.com/en-us/library/cc668794%28v=vs.110%29.aspx 说明

OData builds on standard Internet protocols to make data services interoperable with applications that do not use the .NET Framework. Because you can use standard URIs to address data, your application can access and change data by using the semantics of representational state transfer (REST), specifically the standard HTTP verbs of GET, PUT, POST, and DELETE. This enables you to access these services from any client that can parse and access data that is transmitted over standard HTTP protocols. 
  

OData定义了Atom发布协议(AtomPub)的一组扩展。它支持多种数据格式的HTTP请求和响应,以适应各种客户端应用程序和平台。 OData提要可以表示Atom,JavaScript Object Notation(JSON)和纯XML中的数据。 虽然Atom是默认格式,但Feed的格式在HTTP请求的标头中指定。有关更多信息,请参阅OData:Atom格式和OData:JSON格式。

0 个答案:

没有答案