0

I have a WCF service that accepts a POST request from jqGrid in the form of HTML form and returns JSON.

While things were on .NET 4.0, all worked fine. I could access form fields inside the service via request["fieldName"]. Once I upgraded to .NET 4.5, all my request["fieldName"] are now blank. Is there some kind of known issue with .NET 4.5, WCF and HttpContext.Current.Request?

Here is an example:

 POST http://{REMOVED}/Grid.svc/Execute HTTP/1.1
 Accept: application/json, text/javascript, */*; q=0.01
 X-Requested-With: XMLHttpRequest
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
 Accept-Encoding: gzip, deflate

 _search=false&nd=1355782305975&rows=15&page=1&sidx=modified&sord=desc&search=&category=all

and, here is the service:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class GridAccess
{
    [OperationContract]
    [WebInvoke(Method = "POST",
           BodyStyle = WebMessageBodyStyle.Bare,
           ResponseFormat = WebMessageFormat.Json,
           RequestFormat = WebMessageFormat.Json
    )]
    public GridResponse Execute()
    {
        var request = System.Web.HttpContext.Current.Request;

All references to request["fieldName"] worked before under .NET 4.0 and now, after upgrade to .NET 4.5, they return NULLs.

John Saunders
  • 157,405
  • 24
  • 229
  • 388
user1044169
  • 2,293
  • 5
  • 30
  • 56

2 Answers2

2

The issue's root cause looks to be the same as the issue described in post : Visual Studio 2012 install broke my 2010 WCF project. I can see your code starts working again if I follow the work around suggested in this post. You can refer to this blog post for more information.

Community
  • 1
  • 1
Praburaj
  • 10,857
  • 1
  • 20
  • 20
  • Thanks. Please keep us posted on any other bugs with the same root cause, and let us know when you have fixed them. – John Saunders Dec 18 '12 at 22:50
  • I already rolled back to VS 2010 and uninstalled .NET 4.5. Things are back to working with .NET 4.0. At this time, I am abandoning the idea of upgrading to .NET 4.5 – user1044169 Dec 19 '12 at 00:11
0

To resolve these kind of issues. Just add the System.Web DLL to the Assembly. Then reference it like this for example:

System.Web.HttpRequest request = System.Web.HttpContext.Current.Request; 
Tunaki
  • 116,530
  • 39
  • 281
  • 370