Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid, HttpPost for WCF
    primarykey
    data
    text
    <p>I'm trying to use httpost to get data from our WCF webservice</p> <p>If the webservice function is without params , something like List getAllMessages()</p> <p>I'm getting the List in json, no problem here</p> <p>The tricky part is when the function needs to get argument let's say Message getMessage(string id) when trying to call this kind of functions I get error code 500</p> <p>The working code is:</p> <pre><code>public String GetAllTitles() { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://www.xxx.com/Service/VsService.svc/GetAllTitles"); httppost.setHeader("Content-Type", "application/json; charset=utf-8"); try { // Add your data List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); return readHttpResponse(response); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } </code></pre> <p>this code works great for functios without arguments.. I took this code and changed it to:</p> <pre><code> public String SearchTitle(final String id) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://www.xxx.com/Service/VsService.svc/SearchTitle"); httppost.setHeader("Content-Type", "application/json; charset=utf-8"); httppost.setHeader("Accept", "application/json; charset=utf-8"); NameValuePair data = new BasicNameValuePair("id",id); try { // Add your data List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs.add(data); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); return readHttpResponse(response); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } </code></pre> <p>The function header in thr webservice is:</p> <pre><code> [OperationContract] public TitleResult SearchTitle(string id) { Stopwatch sw = LogHelper.StopwatchInit(); try { TitleManager tm = new TitleManager(); Title title = tm.TitleById(id); sw.StopAndLog("SearchTitle", "id: " + id); return new TitleResult() { Title = title }; } catch (Exception ex) { sw.StopAndLogException("SearchTitle", ex, "id: " + id); return new TitleResult() { Message = ex.Message }; } } </code></pre> <p>Anyone can see what am I missing? </p> <p>Thanks, I'm breaking my head over this one.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload