Receiving a csv text file in XData

C.Request.Headers.Get

Keep it.

C.Response.StatusCode

No need, it's set automatically by XData. But in any case, for different status codes, you can use

TXDataOperationContext.Current.Handler.SetStatusCode(200);

C.Response.ContentType

Keep it.

C.Response.Close

No need. You don't need to answer anything, actually, so all vres code can be removed. It's up to you what to return in your XData method.

or should the code be integrated directly into the XData service function?

Directly.