Web Service problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Web Service problem

Postby quauhtlimtz » Thu Dec 13, 2007 6:10 pm

Hello, everybody:

After calling a Web Service I get a response with the ascii extended characters codified as you can see on this picture (e.g. "&lt;" instead of "<"):

Image



If I call the Web Service with the same Get line ( http://www.webservicex.net/hcpcs.asmx/GetHCPCSbyHCPCSCode?HCPC=12345 ) from a browser it displays the characters correctly:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <string><NewDataSet /></string>
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Does anybody knows if I am missing something? I think this is a codification issue.

Here is the source code:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.quauhtli.webservices;
  2.  
  3. import org.apache.commons.httpclient.HttpClient;
  4. import org.apache.commons.httpclient.HttpStatus;
  5. import org.apache.commons.httpclient.methods.GetMethod;
  6.  
  7. import android.app.Activity;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.widget.TextView;
  11.  
  12. public class CallingWebServices extends Activity {
  13.         /** Called when the activity is first created. */
  14.        
  15.         @Override
  16.         public void onCreate(Bundle icicle) {
  17.                 super.onCreate(icicle);
  18.                 setContentView(R.layout.main);
  19.                 HttpClient client = new HttpClient();
  20.  
  21.                 GetMethod get = new GetMethod(
  22.                                 "http://www.webservicex.net/hcpcs.asmx/GetHCPCSbyHCPCSCode?HCPC=12345");
  23.                 try {
  24.                         int status = client.executeMethod(get);
  25.                         TextView resultado = (TextView) findViewById(R.id.ws_response);
  26.                         String res = "";
  27.  
  28.                         if (status == HttpStatus.SC_OK)
  29.                                 res = get.getResponseBodyAsString();
  30.                         else
  31.                                 res = getString(R.string.ws_not_found);
  32.                        
  33.                         resultado.setText(res);
  34.                 } catch (Exception e) {
  35.                         Log.e("Error:", e.getMessage());
  36.                 } finally {
  37.                         get.releaseConnection();
  38.                         get = null;
  39.                 }
  40.  
  41.         }
  42. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Attachments
CallingWebServices.zip
Eclipse Project
(32.65 KiB) Downloaded 118 times
quauhtlimtz
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Nov 26, 2007 5:56 pm
Location: Mexico

Top

Postby plusminus » Thu Dec 13, 2007 6:23 pm

Hello

It is displaying 'right' or better, it is displaying raw, look at the Source-Code your browser returns.
It returns exactly the same, as your TextView shows.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <string xmlns="http://www.webserviceX.NET">&lt;NewDataSet /&gt;</string>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby quauhtlimtz » Thu Dec 13, 2007 6:26 pm

Yeah, you right, plusminus :(

So now, the problem is how to convert this string to a human-readeable form. I don't know if I am using the GetMethod correctly.
quauhtlimtz
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Nov 26, 2007 5:56 pm
Location: Mexico

Postby plusminus » Thu Dec 13, 2007 6:46 pm

Hello quauhtlimtz,

I think you are using it right, as it returns everything correct.
Do you need it just readable for human :?:

Commonly such things are converted ( the php-function htmlspecialchars(..) does replace them ):
  • '&' --> '&amp;'
  • '"' --> '&quot;'
  • '<' --> '&lt;'
  • '>' --> '&gt;'
This could become a nice tutorial :!:
I'll transform it into one :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby quauhtlimtz » Fri Dec 14, 2007 7:34 pm

Thanks, +-

So you mean to substitute manually those chars? What I need is to use the returning string to do something else, however, if I use the string as is returned, my program will not recognize it.

I will wait for your tutorial! :D
quauhtlimtz
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Nov 26, 2007 5:56 pm
Location: Mexico

Problem with "CallingWebServices" sample code

Postby jrr » Sat Feb 02, 2008 6:09 pm

Hi all,

I tried the sample code but got the following error messages:

JDI thread evaluations (Timeof error .......)

Exception processing async thread queue.
Timeout ocurred while waiting for packet 5205.

I'm not behind a firewall, using Eclipse Vers. 3.3.1.1 Build id: M20071023-1652
and Android Development Tools 0.33 plugin Build android_sdk_windows_m3-rc37a.

Any suggestion ?

Best regards
jrr
Freshman
Freshman
 
Posts: 8
Joined: Sat Feb 02, 2008 5:43 pm

Top

Postby plusminus » Sat Feb 02, 2008 8:03 pm

Hello jrr,

never seen such an error. No clue what to do :(

Perhaps you have more luck with my :src: Getting Data From the Web (URLConnection via http)-Tutorial.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby jrr » Sun Feb 03, 2008 3:13 pm

Hi plusminus,

Thanks for your suggestion.

I tried your tutorial sample code but got the following error: "Host is unresolved: http://www.anddev.org:80".

It sounds like a network problem but I can read the file with my browser (same as with
CallingWebService" sample code).

Any suggestion ?

Thanks in advance.

jrr
jrr
Freshman
Freshman
 
Posts: 8
Joined: Sat Feb 02, 2008 5:43 pm

Postby plusminus » Sun Feb 03, 2008 7:38 pm

Hello jrr,

it works also from within the Android-Browser or only your desktop browser :?:
Can you do normal websurfing in the emulator :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby jrr » Tue Feb 05, 2008 4:05 pm

Hi plusminus,

I can reach the site only from my desktop browser.

I can not do normal websurfing in the emulator.

I am not behind a firewall, not using DNS, using Windows Vista, have Wifi and Ethernet adapters
but only Ethernet one enabled.

Seems to be a networking problem.

I checked the forum for this kind of problem but seems to be not an easy problem to solve.

Any advice ?

Best regards.
jrr
Freshman
Freshman
 
Posts: 8
Joined: Sat Feb 02, 2008 5:43 pm

Postby Jodol » Tue Feb 05, 2008 7:50 pm

jrr,

just to check, you do have the network (GPRS or better) enabled in the emulator?

Jodol
Member of a Dutch company developing applications for Android.
ColdTrick Solutions
User avatar
Jodol
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Dec 19, 2007 6:29 pm
Location: Netherlands

Postby jrr » Tue Feb 05, 2008 8:11 pm

Hi Jodol,

Sorry, I only tried the browser with a standard connection to Internet, no clue about GPRS enabled nor how to check it out.

Thanks for your help.

Best regards.

jrr
jrr
Freshman
Freshman
 
Posts: 8
Joined: Sat Feb 02, 2008 5:43 pm

Re: Web Service problem

Postby Jodol » Tue Feb 05, 2008 8:36 pm

jrr,

the 'G' in the top bar of the emulator indicates if you have a data connection active in the emulator.

quauhtlimtz wrote:
Image



If there is no 'G' then no dataconnection is enabled.

If it is not enabled let me know, then i will post directions on how to enable them.

Greetz,

Jodol
Member of a Dutch company developing applications for Android.
ColdTrick Solutions
User avatar
Jodol
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Dec 19, 2007 6:29 pm
Location: Netherlands

Postby jrr » Tue Feb 05, 2008 8:36 pm

Hi Jodol,

I checked the emulator "run" configuration, the network options are:

Network Speed: Full

Network Latency: None

Best regards.

jrr
jrr
Freshman
Freshman
 
Posts: 8
Joined: Sat Feb 02, 2008 5:43 pm

Postby jrr » Tue Feb 05, 2008 8:48 pm

Hi Jodol,

The 'G' is displayed on the emulator's top bar.

Best regards.

jrr
jrr
Freshman
Freshman
 
Posts: 8
Joined: Sat Feb 02, 2008 5:43 pm

Top
Next

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests