Hi Community,
I have been trying to get a WCF RESTful service working with the microsoft wcf rest starters kit, and ive successfully been able to get it up and running with GET, POST and PUT methods. However once ive done this ive tried to make the uri resource more "hackable" by removing the reference of "Service.svc" by using a HTTPModule. So before the change i called the uri :-
/service.svc/accounts
to :-
/rest/accounts
this all worked great. For GET methods only it seems!! I tried to test my POST and PUT methods to no avail. Can somebody point me in the right direction here, i find it very frustrating that something as simple as making a uri hackable is still a chore to do with MS technologies. Im using IIS6.
Here is some sample code. A service command :-
[OperationContract(Name = "CreateAccount")]
[WebInvoke(UriTemplate = "rest/accounts", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
public bool CreateAccount(NameValueCollection pairs)
{
}
And the HTTPModule to rewrite the reference to Service.svc :-
void application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
if (context.Request.RawUrl.Contains("/rest/"))
{
Uri uri = context.Request.Url;
string queryString = uri.Query;
if(queryString.Length > 1)
queryString = queryString.Substring(1);// to remove the ?
string pathInfo = uri.AbsolutePath.Substring(uri.AbsolutePath.LastIndexOf("/rest/"));
context.RewritePath("~/Service.svc", pathInfo, queryString, true);
}
}
Really looking forward to your suggestions guys