I can't pass over parameters to wcf web service. My web method:
[OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "playersJson2")] List<Person> GetPlayers(string name1, string name2);
When I make http post request, I got 200 OK response with correct json form but web service seems to fail to get paramters (name1, name2). Wireshark shows following:
Do you see anything wrong?
Update: Not sure it matters but my service is using "webHttpBinding" and post request is coming from Android.
It looks like you need to parse your post data manual...
You can look here for example
You need to set the correctContent-Type
which isapplication/json
in this case.Sorry for misreading your question. Update your UriTemplate as follows:
WCF doesn't support forms/encoded data out-of-the box. The other answers mentioned some alternatives (receive the input as a Stream, change the request to JSON). Another alternative, which doesn't force you to change the request or the operation is to use a custom formatter which understands form-urlencoded requests. The code below shows one which does that.
The only thing that looks out of place is the
playerJson2
but that is just because I have never used the UriTemplate before. Can you get it to work without the UriTemplate and just post to/WcfService1/Service1.svc/GetPlayers
? Are there any other WCF services that you have working in the project?