I wrote some wcf interface ( REST ) that need to be called from android platform.
The first method is working good on any call from android – but the second method not working at all and i don’t see any reason to this to happaned.
The code in the client ( android ) is not make any exception – i just see in the HttpResponse the message ‘bad request’ and i dont see that the code is stop on the wcf code ( in the server ).
The WCF code:
[OperationContract, WebInvoke( Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare )]
Replay_1_DTO Method_01( Stream image );
[OperationContract, WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
Replay_2_DTO Method_02(int val1);
The android code for the second method:
Replay_2_DTO Call_Method_02(int val1)
{
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(WEB_SERVICE_URL);
Replay_2_DTO replay_2_DTO = null;
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("val1", val1));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse p = httpclient.execute(httppost);
String str = EntityUtils.toString(p.getEntity());
replay_2_DTO = parser( str );
}
catch (Exception e) { ... }
return replay_2_DTO;
}
The most likely cause of this behavior is that the WCF service can’t serialize replay_2_DTO or one of its children.
To figure this out, add the following to the section of your web.config. Once you have reproduced the error, double click on the file to use the log viewer tool, which should show you exactly what is happening.
Another good tool to use, even before the above suggestion, is fiddler. Sometimes you can see more detailed information in the response that will lead you in the right direction.