Don’t use UriTemplate = "/MethodName/Param1/{Param1}/Param2/{JsonObject} for Json input with WCF Service

When building Ajax-enabled WCF service that expect a Json object as input then the following would not work

[OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Methodname/jsonvariable/{jsonvariable}/param2/{param2}")]
public void MethodName(string jsonvariable, string param2)
{
 
}

Where jsonvariable is a json object passed through jQuery (or ASP.NET Ajax) to a WCF service that looks like this

[{"Name":"za","Email":zubairdotnet@hotmail.com}]

After spending a while I figured out that the following UriTemplate should be used instead

 

[OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Methodname/?jsonvariable={jsonvariable}&param2={param2}")]
public void MethodName(string jsonvariable, string param2)
{
 
}

1 Comment

Comments have been disabled for this content.