WCF Data Service Customize XML -


created wcf data service , got working, xml not formatted quite way need , can't seem figure out how rid of stuff. have is:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <entry xml:base="http://172.1.2.2/database/databasetables.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/atom"> <id>http://172.1.2.2/database/databasetables.svc/device('999')</id> <title type="text"></title> <updated>2013-05-14t18:17:10z</updated> <author>   <name /> </author> <link rel="edit" title="device" href="device('999')" /> <category term="model.device" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml">   <m:properties>     <d:device_code>999</d:device_code>     <d:short_name>tc2</d:short_name>   </m:properties>  </content> </entry> 

what want is:

<device>   <device_code>999</device_code>   <short_name>tc2</short_name> </device> 

i have added name attribute data contract did not change anything.

wcf data services produces odata, uniform protocol built on common traits of restful services. using odata means people consuming service don't need learn server-specific details of custom api in order understand payload format, uri conventions, , http method semantics. if understand odata, , service produces odata, don't need learn new or write lots of custom code.

the xml want send not formatted in 1 of odata payload formats. that's not problem per-se, should aware won't able use wcf data services client (aka "add service reference" in visual studio), powerpivot, or of other tools , client libraries understand odata. in addition, odata xml format built on top of atompub, means browsers (and other atom-readers) can display data in intelligent way.

if you're looking create custom rest api using own format, there might other libraries , frameworks out there better suited. asp.net web api might choice here. i'm not sure this, think web api might make possible use standard odata uri conventions ($filter, $select, etc.) while producing custom format.

to summarize: odata great if want stick common standard , want able rely on existing, well-tested libraries consume service. wcf data services solid , stable implementation of odata. if you're not using odata (or if you're using parts of it), wcf data services not going you're looking for.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -