4

My Scenario: I am using Monotouch for iOS to create an iPhone app. I am calling ASP.NEt MVC 4 Web API based http services to login/log off. For Login, i use the POST webmethod and all's well. For Logoff, i am calling the Delete web method. I want to pass JSON data (serialized complex data) to the Delete call. If i pass simple data like a single string parameter as part of the URL itself, then all's well i.e. Delete does work! In order to pass the complex Json Data, here's my call (i have adjusted code to make it simple by showing just one parameter - UserName being sent via JSON):

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost/module/api/session/");
        req.ContentType = "application/json";
        req.CookieContainer = jar;
        req.Method = "Delete";
        using (var streamWrite = new StreamWriter(req.GetRequestStream()))
        {
            string jSON = "{\"UserName\":\"" + "someone" + "\"}";
            streamWrite.Write(jSON);
            streamWrite.Close();
        }
        HttpWebResponse res = (HttpWebResponse)req.GetResponse();

on the server, the Delete method looks has this definition:

public void Delete(Credentials user)

where Credentials is a complex type.

Now, here's the issue!

The above code, gets into the Delete method on the server as soon as it hits:

req.GetRequestStream()

And hence the parameter sent to the Delete method ends up being null

And here's the weird part: If i use the exact same code using a test VS 2010 windows application, even the above code works...i.e it does not call Delete until req.GetResponse() is called! And in this scenario, the parameter to the Delete method is a valid object!

QUESTION

Any ideas or Is this a bug with Monotouch, if so, any workaround?

NOTE:

if i change the Delete definition to public void Delete(string userName) and instead of json, if i pass the parameter as part of the url itself, all's well. But like i said this is just a simplified example to illustrate my issue. Any help is appreciated!!!

AMSI Dev
  • 61
  • 5

1 Answers1

2

This seems to be ill-defined. See this question for more details: Is an entity body allowed for an HTTP DELETE request?

In general MonoTouch (based on Mono) will try to be feature/bug compatible with the Microsoft .NET framework to ease code portability between platforms.

IOW if MS.NET ignores the body of a DELETE method then so will MonoTouch. If the behaviour differs then a bug report should be filled at http://bugzilla.xamarin.com

Community
  • 1
  • 1
poupou
  • 43,413
  • 6
  • 77
  • 174
  • Hi poupou,Thanks for your reply. I did review the link - while early comments suggest that body is ignored, there's a newer comment that says it's allowed. Anyways, like i mentioned in my original message, the same code does work in a Visual Studio 2010 windows forms application - i.e. it does not ignore the additional json data sent. So sounds like i should file a report on bugzilla. Let me know if you think otherwise else i'll do so. – AMSI Dev Aug 07 '12 at 12:35
  • @AMSIDev Could you please post the URL of the bugzilla report? Thanks a lot! – Nicolas Raoul Jul 24 '13 at 08:38