Mam problem z opublikowaniem wartości JSONArray wartości w mojej usłudze WCF. Kiedy wysyłam dane z Fiddlera lub klienta testowego .Net, wszystko działa dobrze. Za każdym razem, gdy próbuję wysyłać posty z mojej aplikacji Android, otrzymuję żądanie ErrorPublikowanie usługi JSONArray na usługi WCF z systemu Android
To jest dane JSON, które wysyłam do mojej usługi WCF z aplikacji Android. Próbowałem dokładnie ten danych z Skrzypek i działa
[{"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"}]
Mój android kod
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();
}
My WCF usługi
[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();
}
}
Błąd Dostaję
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>
Nazwałam wiele żądań GET ts z aplikacji Android do tej samej usługi WCF i działa świetnie, ale teraz muszę wysłać tablicę danych do usługi wcf. Proszę pomóż me.thanks z góry
Czy otrzymujesz jakieś błędy? Jaka jest odpowiedź? – Rajesh
Niestety właśnie dodano błąd do wpisu – razeth01
Czy możesz spróbować bez 'se.setContentType (" application/json; charset = UTF-8 ");'? – Rajesh