0

I have created a WCF Data Service and it works fine. My Custom methods that are GET type methods work ok as well. The problem is in POST custom method.

The method looks like that:

    [WebInvoke(Method = "POST")]
    public string CustomMethod(string myParameter)
    {
        return "yes" + myParameter;
    }

I also invoke:

    config.SetServiceOperationAccessRule("CustomMethod", ServiceOperationRights.All);

Then in fiddler my request looks like that:

    Method: POST
    URL: http://localhost:1219/DataService.svc/CustomMethod
    Reguest Headers:
    User-Agent: Fiddler
    Host: localhost:1219
    Content-Length: 27
    Content-Type: application/x-www-form-urlencoded
    Request Body:
    myParameter=parameter1value

The method gets called but the "myParameter" parameter is always null. What am I missing?

Thanks for your time.

PK.
  • 588
  • 1
  • 4
  • 12
  • What is "parameter1value"? Try replacing it with some hard coded strings for testing purposes. I haven't used fiddler but where you are passing values to "myParameter" in your request "config.SetServiceOperationAccessRule("CustomMethod", ServiceOperationRights.All)"?? – Faizan Mubasher Jan 16 '14 at 05:39
  • parameter1value is actually a string value. Thanks but "tne" got the answer right. The content must be json. – PK. Jan 20 '14 at 22:25

2 Answers2

0

I believe the way you are passing parameter 'myParameter' may be wrong.

you can try to consume your service using visual studio and then try to pass it.

one more question.. when you call the service as get service, is Content-Type is

Content-Type:application/x-www-form-urlencoded

user2463514
  • 273
  • 1
  • 4
  • 19
0

Please refer to Section 10.4.1.3. Invoking an Action for OData 3.

Short story: The content type must be JSON.

If the invoke request contains any non-binding parameter values, the Content-Type of the request MUST be 'application/json', and the parameter values MUST be encoded in a single JSON object in the request body.

Aaroninus
  • 1,062
  • 2
  • 17
  • 35
tne
  • 7,071
  • 2
  • 45
  • 68