Project Description
This extension library provides access to the message body request stream of a WCF Data Service (formerly ADO.NET Data Service), which is not possible with the WCF Data Services class. You are enabled passing data (e.g. Json data, form data, files) via HTTP POST to the message request body. Just add a reference to the extension and then call the GetMessageBodyAsStream() method to receive the request stream.
The library extends the original WCF Data Services class (System.Data.Services) by using extension methods. It integrates seamlessly into the WCF Data Services infrastrukture, without need to take care about derived types or inheritance. Internally it uses the operation context (DbContext) provided by the DataService<T> class to get access to the resquest stream.
How to use:
1 Add a reference to the library.
2 Add a using statement to System.Data.Services.Extensions:
using System.Data.Services.Extensions;
3 (Optional) Register library for the incoming request event or call the processing method directly in OnStartProcessingRequest(ProcessRequestArgs args):
public class PersonDataService : DataService<PersonEntities>
{...
// REGISTER HANDLER TO BE CALLED ON INCOMING REQUESTS
public PersonDataService()
{...
this.ProcessMessageBodyAttachEvent();
...}
// OR CALL THE PROCESSING METHOD DIRECTLY ON INCOMING REQUESTS:
protected override void OnStartProcessingRequest(ProcessRequestArgs args)
{...
this.ProcessRequest(args);
...}
...}
4 Get request stream or content:
public class PersonDataService : DataService<PersonEntities>
{...
// GET RESPONSE STREAM OR STRING
[WebInvoke(Method="POST")]
public SomeMethod()
{...
Stream stream = this.GetMessageAsStream();
String str = this.GetMessageAsString();
...}
// GET OBJECT FROM JSON DATA STREAM
[WebInvoke(Method="POST")]
public OtherMethod()
{...
Person person = this.GetMessageObjectFromJson<Person, PersonEntities>();
...}
...}
Copyright (c) 2011 Steffen Habermehl