Take the 2-minute tour ×

I'm trying to understand WCF, so my questions may be dumb. I believe I have a firm understanding of "GET" operations. I'm now working on some "POST" operations. My question is, can I write a WCF Service operation, with WebInvoke, that accepts multiple parameters? Or, when I POST data, will it only accept a single serialized parameter?

Thank you!

share|improve this question
this smells like a second version of your previous question :) –  Taylor Bird Feb 6 '11 at 14:50
add comment

2 Answers

up vote 6 down vote accepted

Yes, but your POST will have to be passed in using a common understanding of the data, aka a "data contract".

In WCF, the typical approach here is that you'd create a contract class (just an off-my-head example, not 100% working))

public class MyContract
   public string MyData1 { get(); set{};}

   public string MyData2 { get(); set{};}


Then you'd specify your WCF operation to accept that contract type as its parameter

public string DoSomethingFromPost(MyContract postedData)

On your client, you'd serialize the data to an xml/json that matches your contract. Again, loose example:

<MyContract xmlns="http://yournamespace.com">

When the contract matches, WCF will deserialze your POST into your contract object, at which point you can use it like any other class.

share|improve this answer
A closing square bracket is missing from the first piece of sample code –  Carlos P May 22 '12 at 12:45
Thx Carlos, fixed it –  Taylor Bird May 29 '12 at 15:39
add comment

It seems like there is a bit of confusion between wcf (which is the name given to microsofts overall abstraction for network programming) and a specific protocol HTTP, that defines verbs like "POST" and "GET", that wcf will be using to communicate.

When you define a wcf service operation and attribute it with [WebInvoke] you are going to access to the service using REST over HTTP. See webinvoke for more detail, however the remarks sum it up well

The WebInvokeAttribute attribute is applied to a service operation in addition to the OperationContractAttribute and associates the operation with a UriTemplate as well as an underlying transport verb that represents an invocation (for example, HTTP POST, PUT, or DELETE). The WebInvokeAttribute attribute is a passive operation behavior (the IOperationBehavior methods do nothing) that adds metadata to the operation description. Applying the WebInvokeAttribute attribute to a service operation has no effect unless a behavior that looks for this metadata in the operation description (such as WebHttpBehavior) is added to the service's behavior collection. The WebInvokeAttribute determines what HTTP method that a service operation responds to. By default, all methods that have the WebInvokeAttribute applied respond to POST requests.

Also further down the article defines how to map values to your service contract. Something like..

[WebInvoke(Method = "POST", UriTemplate = "Mod?x={x}&y={y}")]
long Mod(long x, long y);

EDIT: To make this a bit more informative for people new to the field.

share|improve this answer
since Taylor covered the POST body, heres access via the Uri –  almog.ori Feb 6 '11 at 15:09
+1, Good addition, forgot this. I typically avoid POSTing via query string for no good reason, but in many situations this is equally appropriate –  Taylor Bird Feb 6 '11 at 16:48
Can you combine the two methods? e.g. a method with the URI of Mod?x={x}&y={y} which has post data in the form of SomeObject? So the signature would look something like: long Mod(long x, long y, SomeObject data) –  Josh M. May 3 '11 at 17:14
add comment

Your Answer


