Get the return value from a WCF Restful service which is POST method
<p>I want to know how to get the return value from a WCF Restful service which is POST method. I am able to get the return value if it is a GET method. In GET method, webClient.DownloadString(url); is returning the result. But in case of POST method, webClient.UploadString(url, "POST", data); is not returning the result, it is just invoking the web service.</p>

<p>I have seen many samples, people are just calling the WCF service post method with UploadString() method and assuming that it returns success. But I want to check the return value and based on that show appropriate message.</p>

<pre><code>//----------------------------------- WCF RESTful service -----------------------------------
[ServiceContract]
public interface IAppService
{       
    [OperationContract]
    [WebInvoke(UriTemplate = "ValidateVisitPIN", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    bool ValidateVisitPIN(VisitPinRequest visitPinRequest);
}

public class AppService : IAppService
{
    public bool ValidateVisitPIN(VisitPinRequest visitPinRequest)
    {
        //......
        if(visitPinRequest.visitPin == 100)
            return true;
        else
            return false;
    }
}
//----------------------------------- WCF client application -----------------------------------
//POST method
using (WebClient webClient = new WebClient())
{
    VisitPinRequest visitPinRequest = new VisitPinRequest();
    visitPinRequest.VisitPin = txtVisitPIN.Text;

    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(VisitPinRequest));
    MemoryStream mem = new MemoryStream();
    ser.WriteObject(mem, visitPinRequest);
    string url = webServiceURL + "ValidateVisitPIN";

    string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
    webClient.Headers["Content-type"] = "application/json";
    webClient.Encoding = Encoding.UTF8;
    var returnString = webClient.UploadString(url, "POST", data);
}

//Get method
using (WebClient webClient = new WebClient())
{
    string url = webServiceURL + "ValidateVisitPIN/" + txtVisitPIN.Text;
    string outputString = webClient.DownloadString(url);
    MessageBox.Show(outputString);
}
</code></pre>