2013-02-26 9 views
5

से डब्ल्यूसीएफ सेवा में JSONArray पोस्ट करना मुझे मेरी डब्ल्यूसीएफ सेवा में मूल्यों के JSONArray पोस्ट करने में समस्या हो रही है। जब मैं फिडलर या नेट टेस्ट क्लाइंट से डेटा पोस्ट करता हूं तो यह ठीक काम करता है। हर बार जब मैं अपने एंड्रॉइड एप्लिकेशन से पोस्ट करने का प्रयास करता हूं तो मुझे अनुरोध त्रुटिएंड्रॉइड

यह जेएसओएन डेटा है जिसे मैं एंड्रॉइड एप्लिकेशन से अपनी डब्ल्यूसीएफ सेवा में भेजता हूं। मैं फ़िडलर से इस सटीक डेटा की कोशिश की है और यह

[{"date":"2013-02-22 15:30:374:021","id":"1","description":"test","name":"test"}, 
"date":"2013-02-25 11:56:926:020","id":"2","description":"ghy","name":"fhh"}, 
"date":"2013-02-25 11:56:248:026","id":"3","description":"ghfm","name":"run"}] 

मेरे एंड्रॉयड कोड

public JSONObject makeHttpPost(String url, String method, JSONArray params) { 
    try { 

     if (method == "POST") { 

      DefaultHttpClient httpClient = new DefaultHttpClient(); 
      HttpPost httpPost = new HttpPost(url); 
      httpPost.setHeader("Accept", "application/json"); 
      httpPost.setHeader("Content-Type", 
      "application/json; charset=utf-8"); 
      StringEntity se = new StringEntity(params.toString(),"UTF-8"); 

      se.setContentType("application/json;charset=UTF-8"); 
      httpPost.setEntity(se); 

      Log.e("Gerhard", params.toString()); 
      HttpResponse httpResponse = httpClient.execute(httpPost); 
      HttpEntity httpEntity = httpResponse.getEntity(); 
      is = httpEntity.getContent(); 



     } 

    } catch (UnsupportedEncodingException e) { 
     e.printStackTrace(); 
    } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

मेरे WCF सेवा

[OperationContract] 
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "updateOrderAddress")] 
    String UpdateOrderAddress(Stream JSONdataStream); 

public String UpdateOrderAddress(Stream JSONdataStream) 
    { 
     try 
     { 
      // Read in our Stream into a string... 
      StreamReader reader = new StreamReader(JSONdataStream); 
      string JSONdata = reader.ReadToEnd(); 

      // ..then convert the string into a single "wsOrder" record. 

      if (JSONdata == null) 
      { 
       // Error: Couldn't deserialize our JSON string into a "wsOrder" object. 
       return "null"; 
      } 



      return JSONdata;  // Success ! 
     } 
     catch (Exception e) 
     { 
      return e.ToString(); 
     } 
    } 

त्रुटि मैं हो रही है

02-26 14:00:56.185: E/Gerhard(31064):  <p>The server encountered an error processing the request. The exception message is 'Incoming message for operation 'UpdateOrderAddress' (contract 'IService1' 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.'. See server logs for more details. The exception stack trace is: </p> 
काम करता है

मैंने कई जीईटी आवश्यकताएं बुलाई हैं एंड्रॉइड एप्लिकेशन से टीएस एक ही डब्ल्यूसीएफ सेवा के लिए और यह बहुत अच्छा काम करता है, लेकिन अब मुझे डब्ल्यूसीएफ सेवा में डेटा की एक सरणी भेजने की जरूरत है। कृपया कृपया अग्रिम

+0

आप किसी भी त्रुटि हो रही है से हटाने

httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-Type", "application/json; charset=utf-8"); 

? प्रतिक्रिया क्या है? – Rajesh

+0

क्षमा करें अभी पोस्ट – razeth01

+0

पर त्रुटि को जोड़ा गया है क्या आप 'se.setContentType ("application/json; charset = UTF-8") के बिना प्रयास कर सकते हैं; '? – Rajesh

उत्तर

6

में me.Thanks मदद उर कोड

+0

इसने एक समस्या हल की जिसे मैंने फिडलर से एक टेस्ट संदेश भेजने की कोशिश की थी। मुझे एक स्पष्टीकरण पसंद आएगा ... –

+0

यह बहुत मदद करता है !! thx – anevil