C# 使用Android Volley库将JSON发布到WCF Restful服务
如果同样的问题被贴到了某个地方,我深表歉意,但在搜索了近5天之后,人们可以理解我是多么绝望,因为大多数答案似乎都没有给我答案。别胡扯了。因此,我尝试使用截取将json发布到wcf restful web服务。下面是我的代码片段 //安卓/截击C# 使用Android Volley库将JSON发布到WCF Restful服务,c#,android,json,wcf,android-volley,C#,Android,Json,Wcf,Android Volley,如果同样的问题被贴到了某个地方,我深表歉意,但在搜索了近5天之后,人们可以理解我是多么绝望,因为大多数答案似乎都没有给我答案。别胡扯了。因此,我尝试使用截取将json发布到wcf restful web服务。下面是我的代码片段 //安卓/截击 public void setJsonDataToWebservices(String url){ JSONObject params = new JSONObject(); try { params
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);
}
。。。。。。下面是一个反序列化流并返回字符串的方法
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";
}
下面是错误日志
处理异常。异常详细信息:System.InvalidOperationException:操作“simplePostExample”(命名空间为“”的协定“IDigitzingDataRestfulWebService”)的传入消息包含无法识别的http正文格式值“Json”。预期的正文格式值为“原始”。这可能是因为尚未在绑定上配置WebContentTypeMapper。有关更多详细信息,请参阅WebContentTypeMapper的文档。
位于System.ServiceModel.Dispatcher.HttpStreamFormatter.GetStreamFromMessage(消息消息消息,布尔isRequest)
位于System.ServiceModel.Dispatcher.HttpStreamFormatter.DeserializeRequest(消息消息,对象[]参数)
位于System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(消息消息,对象[]参数)
位于System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(消息消息,对象[]参数)
位于System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatcheRuntime.ProcessMessage5(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatcheRuntime.ProcessMessage41(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&rpc)
位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&rpc)
现在,地球上亲爱的人们,请告诉我哪里出了问题。您是否在此处检查了解决方案:Hello@toshkini,我在该链接上尝试了该解决方案,但仍然出现相同的错误。您是否在此处检查了该解决方案:具体地说,我指的是覆盖getBodyContentType
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";
}