Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to connect an Android application with IIS server on laptop
    primarykey
    data
    text
    <p>I have developed an android application which use a C# web service. I have published the web service using IIS server. Now I want to install my application to an Android device and connect it to the WCF rest service running on an IIS server. </p> <p>What steps should I take to accomplish this? </p> <p>So far i have used the methods mentioned below. But there are some errors :( Help me fix them!</p> <pre><code> public String ServiceCallMethod() { //int x1 = 262, x2 = 525, y1 = 100, y2 = 390; String url = "http://192.168.43.73:85/PathService/PathService.svc/FindPath/"+x1+","+y1+"/"+x2+","+y2+""; HttpClient httpclient = new DefaultHttpClient(); // Prepare a request object HttpGet httpget = new HttpGet(url); // Execute the request HttpResponse response; try { response = httpclient.execute(httpget); // Examine the response status Log.i("Praeda",response.getStatusLine().toString()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { // A Simple JSON Response Read InputStream instream = entity.getContent(); String result= convertStreamToString(instream); // returns error when i debug :(its supposed to return an point array list like this.. //Response - {"FindPathResult":[{"x":262,"y":165},{"x":346,"y":165},{"x":420,"y":165},{"x":473,"y":165},{"x":473,"y":240},{"x":473,"y":277},{"x":473,"y":320},{"x":473,"y":390},{"x":525,"y":390}]} //Instead it returns this //&lt;?xml version="1.0" encoding="utf-8"?&gt; // &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 //Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; // &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; // &lt;head&gt; // &lt;title&gt;Request Error&lt;/title&gt; // &lt;style&gt;BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}&lt;/style&gt; //&lt;/head&gt; //&lt;body&gt; //&lt;div id="content"&gt; //&lt;p class="heading1"&gt;Request Error&lt;/p&gt; //&lt;p&gt;The server encountered an error processing the request. See server logs for more details.&lt;/p&gt; //&lt;/div&gt; //&lt;/body&gt; //&lt;/html&gt; // ---------------------------------------------------------------------------- Log.i("Praeda",result); // A Simple JSONObject Creation JSONObject json=new JSONObject(result); Log.i("Praeda","&lt;jsonobject&gt;\n"+json.toString()+"\n&lt;/jsonobject&gt;"); // A Simple JSONObject Parsing JSONArray nameArray=json.names(); JSONArray valArray=json.toJSONArray(nameArray); for(int i=0;i&lt;valArray.length();i++) { Log.i("Praeda","&lt;jsonname"+i+"&gt;\n"+nameArray.getString(i)+"\n&lt;/jsonname"+i+"&gt;\n" +"&lt;jsonvalue"+i+"&gt;\n"+valArray.getString(i)+"\n&lt;/jsonvalue"+i+"&gt;"); Log.i("TEST","JSONArray Recieved"); } // A Simple JSONObject Value Pushing json.put("sample key", "sample value"); Log.i("Praeda","&lt;jsonobject&gt;\n"+json.toString()+"\n&lt;/jsonobject&gt;"); // Closing the input stream will trigger connection release instream.close(); //I want to assign the result to one of my String arrays(this_results) ------------- this_result = result; //----------------------------------------------------- System.out.println(" End of ServiceCallMethod() "); return result; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } private static String convertStreamToString(InputStream is) { /* * To convert the InputStream to String we use the BufferedReader.readLine() * method. We iterate until the BufferedReader return null which means * there's no more data to read. Each line will appended to a StringBuilder * and returned as String. */ BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } </code></pre> <p>And this is my WCF Rest Get method</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using testServer; namespace IGTSMPathService { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "PathService" in code, svc and config file together. public class PathService : IPathService { //GET Method //http://localhost:50837/PathService.svc/FindPath/262,100/525,390 //Response - {"FindPathResult":[{"x":262,"y":165},{"x":346,"y":165},{"x":420,"y":165}, {"x":473,"y":165},{"x":473,"y":240},{"x":473,"y":277},{"x":473,"y":320},{"x":473,"y":390},{"x":525,"y":390}]} public System.Drawing.Point[] FindPath(string cLocation, string destination) { System.Drawing.Point[] list; Location loc = new Location(cLocation); System.Drawing.Point cur, des; cur = new System.Drawing.Point(Int32.Parse(cLocation.Split(',')[0].Trim()), Int32.Parse(cLocation.Split(',')[1].Trim())); des = new System.Drawing.Point(Int32.Parse(destination.Split(',')[0].Trim()), Int32.Parse(destination.Split(',')[1].Trim())); list = loc.findPoint(cur, des); return list; } } </code></pre> <p>}</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