WCF REST Web Service and HTTP Headers



I've created a REST web service that returns a simply id passed in xml format.


However, as part of the xml returned, I want to include custom headers. I want to be able to read the data in the request headers and return some of them back in the response.


For example, if the request includes Header1 and Header2, I want to return Header1 and Header2 as part of the response, along with a new header, Header3.


I'm struggling to work out where and how to do this so any help would be appreciated.


My code:


RestServiceImpl.svc.cs:



namespace RestService
{

public class RestServiceImpl : IRestServiceImpl
{
#region iRestService Members

public string XMLData(string id)
{
return "You requested product " + id;
}

#endregion
}
}


IRestServiceImpl.cs:



namespace RestService
{
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "xml/{id}")]
string XMLData(string id);

}
}

No comments:

Post a Comment