My apologies if the same question has been posted some where, but after searching for almost 5 days, one can understand how desperate i am, since most of the answers seem not to give me a solution. Enough of rambling . So, i am trying to post json to a wcf restful web service, using volley. Below are my code snippets
// Android/Volley
public void setJsonDataToWebservices(String url){
JSONObject params = new JSONObject();
try {
params.put("FullName","nathalue Gustava");
params.put("Id","123");
params.put("Password","123456789");
} catch (JSONException e) {
e.printStackTrace();
}
// Create a future request object
// Create a json request object
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
Toast.makeText(getActivity(), "Success", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(getActivity(), "Failed", Toast.LENGTH_SHORT).show();
}
}){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
VolleySingleton.getIntance().addToRequestQueue(jsonObjectRequest);
}
Here is my interface for the service
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "simplePostExample")]
string simplePostExample(Stream jsonStream);
...... and here is a method to deserialize the stream and return it a string
public string simplePostExample(Stream jsonStream)
{
StreamReader reader = null;
string text = string.Empty;
try
{
reader = new StreamReader(jsonStream);
text = reader.ReadToEnd();
}
catch (Exception)
{
throw;
}
return text != null ? text : "String is empty";
}
and here are the error logs Handling an exception. Exception details: System.InvalidOperationException: Incoming message for operation 'simplePostExample' (contract 'IDigitizingDataRestfulWebService' with namespace 'http://tempuri.org/') contains an unrecognized http body format value 'Json'. The expected body format value is 'Raw'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details. at System.ServiceModel.Dispatcher.HttpStreamFormatter.GetStreamFromMessage(Message message, Boolean isRequest) at System.ServiceModel.Dispatcher.HttpStreamFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
Now, dear people of the earth, please tell me where i am going wrong.