Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top