Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Android Volley库将JSON发布到WCF Restful服务_C#_Android_Json_Wcf_Android Volley - Fatal编程技术网

C# 使用Android Volley库将JSON发布到WCF Restful服务

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

如果同样的问题被贴到了某个地方,我深表歉意,但在搜索了近5天之后,人们可以理解我是多么绝望,因为大多数答案似乎都没有给我答案。别胡扯了。因此,我尝试使用截取将json发布到wcf restful web服务。下面是我的代码片段

//安卓/截击

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";
        }