Calling an XFire webservice

Put your problem here if it does not fit any of the other categories.

Calling an XFire webservice

Postby Jesmiatka » Mon Feb 04, 2008 3:39 pm

<This post is also posted on the google discussion forum>

Hi,

I've been playing around with Android for about a week now and now I
have come to a point where I want to go and use some webservices. I've
been looking around for some options and I saw some solutions, now is
my question: Which one will work for webservices made by XFire which I
can access by it's WSDL.

I've tried to use the KSOAP example, but for some reason it always
stated that my connection was refused. I'm also not sure
if this is the correct and best/fastest way to handle the call of a
webservice in Android.

Anyone with some good information or suggestions what to use?

Yours sincerly,
Mike Jesmiatka

[edit]
I've made 3 functions with 3 different returns which I want to try out:
1) Returning a String
2) Returning an array
3) Returning an object
[/edit]

[edit2]
After trying a while I can't seem to get the KSOAP solution working.
It keeps on refusing my connection while I try to call a method.
I think it's because I'm not using a valid SOAP action or something.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     private static final String SOAP_ACTION = "echoMethod";
  2.  
  3.     private static final String METHOD_NAME = "echoMethod";
  4.  
  5.     private static final String NAMESPACE = "http://localhost:8080/";
  6.  
  7.     private static final String URL = "http://@localhost:8080/androidService-1.0/services/SimpleServiceImpl";
  8.  
  9.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


Is this valid?
[/edit2]
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Top

HI study this Microsoft MapPoint web service application

Postby gvkreddyvamsi » Tue Feb 05, 2008 5:39 am

Hi,

you can know well abt SOAP and parsing.

by
vamsi
Attachments
ReverseGeoCode.zip
(59.11 KiB) Downloaded 474 times
gvkreddyvamsi
Developer
Developer
 
Posts: 43
Joined: Mon Jan 21, 2008 5:10 am
Location: INDIA

Postby Jesmiatka » Tue Feb 05, 2008 10:39 am

Hi,

I have rewrote your code to fit with my webservice and return type of it.
But now it seems to be the problem of my server ;) still get a connection refused with this method aswell..

I'll guess I have to work that out, though it's weird because I can access all the links trough my browser.

Thanks for your response!

Yours sincerely,
Mike Jesmiatka

[edit]
This was indeed the problem, you should use an IP adress in stead of LOCALHOST
[/edit]
Last edited by Jesmiatka on Tue Feb 05, 2008 1:59 pm, edited 1 time in total.
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby Jesmiatka » Tue Feb 05, 2008 1:21 pm

Hi again!

I worked it out, thanks to the example.
Although keep in mind that LOCALHOST means the emulator phone and not the system you are behind. This is why I got the connection refused, I was trying to connect to a webservice on the phone instead of my system.

I also made a small adjustment in the Handler since some of my SOAP response elements had <ns1: xxx> or <ns2: xxx> as a name. I filtered the ns#: out of it. Code following here:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public void startElement(String namespaceURI,
  3.  
  4.                              String localName,
  5.  
  6.                              String qName,
  7.  
  8.                              Attributes atts) throws SAXException {
  9.  
  10.         String elementName;
  11.  
  12.        
  13.  
  14.         if(qName.contains(":")){
  15.  
  16.                 elementName = qName.split(":")[1];
  17.  
  18.         } else {
  19.  
  20.                 elementName = qName;
  21.  
  22.         }
  23.  
  24.                
  25.  
  26.         if (elementName.equals("Data")) {
  27.  
  28.             current = new MyData();
  29.  
  30.         } else if (elementName.equals("var1")) {
  31.  
  32.             isVar1 = true;
  33.  
  34.         } else if (elementName.equals("var2")) {
  35.  
  36.                 isVar2 = true;
  37.  
  38.         }
  39.  
  40.     }
  41.  
  42.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


Hope this will help other people out aswell ;)

Yours sincerely,
Mike Jesmiatka
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Here is the simple and best way call web service

Postby gvkreddyvamsi » Thu Feb 21, 2008 8:36 am

Hi,

I have done simple example to call a web service from android.

I have attached that for your review.


by
vamsi
Attachments
CallingWebServices.zip
(33.66 KiB) Downloaded 553 times
gvkreddyvamsi
Developer
Developer
 
Posts: 43
Joined: Mon Jan 21, 2008 5:10 am
Location: INDIA

Postby chitgoks » Wed Mar 12, 2008 5:49 am

@gvkreddyvamsi: your code uses apache axis right?
but your sample source rar doesnt include the libs. does android already have webservice libs to access webservices?
Website/Java Games: http://www.chitgoks.com
Blogs:
http://tech.chitgoks.com
http://wuhtevah.chitgoks.com
http://disneyusa.blogspot.com
chitgoks
Developer
Developer
 
Posts: 36
Joined: Tue Mar 11, 2008 3:06 am

Top

Postby wazabe » Thu Mar 20, 2008 11:42 pm

Jesmiatka wrote:I worked it out, thanks to the example.
Although keep in mind that LOCALHOST means the emulator phone and not the system you are behind. This is why I got the connection refused, I was trying to connect to a webservice on the phone instead of my system.


Thanks you so much.
User avatar
wazabe
Freshman
Freshman
 
Posts: 8
Joined: Fri Jan 18, 2008 10:49 pm

Re: Here is the simple and best way call web servic

Postby desuvinodkumar » Wed Jun 17, 2009 7:02 am

gvkreddyvamsi wrote:Hi,

I have done simple example to call a web service from android.

I have attached that for your review.


by
vamsi



I'M NOT GEETING ANY OUPTPUT JUST SIMPLY I'M GETTING HELLOWORLD CALLING WEBSERVICES
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Sample way connection

Postby kamal89 » Tue Mar 22, 2011 1:48 pm

HAI i am kamal and i am new for android i just do a program and access it with url but that program did not give any response so i am confused past 7 day please help me
whenever i try it on ksoap2 i got this type of error XMLPULLPARSER Exception :Expected Start Tag:"www.w3.com/"""/........
my program is

package com.temp;


//import java.io.IOException;
//import java.io.StringReader;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
//import org.xmlpull.v1.XmlPullParser;
//import org.xmlpull.v1.XmlPullParserException;
//import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.os.Bundle;
import android.provider.ContactsContract.RawContacts.Entity;
import android.util.Log;
import android.widget.TextView;


public class post extends Activity {
private static final String NAMESPACE = "http://tempuri.org/";

private static final String URL ="http://sample req.asmx";

private static final String SOAP_ACTION = "http://tempuri.org/LoginRequest";

private static final String METHOD_NAME = "LoginRequest";

TextView tv;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// END_TAG, or ENTITY_REF, null
String string = "some json format";

StringBuilder soap = new StringBuilder(URL);
String req= soap.toString();
DefaultHttpClient httpclient = new DefaultHttpClient();

// HttpProtocolParams.setUseExpectContinue(httpclient.getParams(), false);


//setUseExpectContinue(httpclient.getParams(), false); // Comment: 1
try {

HttpPost httpget = new HttpPost(soap.toString()); // Comment: 3


//httppost.setHeader("POST","makenewbuddies/mobileapp/APImobilelogin.asmx ");
httpget.setHeader("Host","184.168.113.188");
httpget.setHeader("SOAPAction", SOAP_ACTION);

httpget.setHeader("Content-Type", "application/soap+xml; charset=utf-8");
httpget.setHeader("Content-Type",""+soap.length());

// UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(soap.toString(),)
// urlEncodedFormEntity.setContentEncoding(HTTP.UTF_8);
//httppost.setEntity(urlEncodedFormEntity);

// Comment: 4
soap.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

soap.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">") ;

soap.append("<soap:Body>");

soap.append("<LoginRequest xmlns=\"http://tempuri.org/\">");

soap.append("<JSONRequestString>"+string+"</JSONRequestString>");

soap.append("</LoginRequest>");

soap.append("</soap:Body>");

soap.append("</soap:Envelope>");

Log.d("soap value1 is",soap.toString());
// Log.d("soap value is ",soap.toString());


//StringEntity strent= new StringEntity(req,HTTP.UTF_8);
//strent.setContentType("ctString");

//strent.setContentType("application/soap+xml");
//strent.getContentLength();

//((HttpResponse) httpget).setEntity(strent);
//httppost.setEntity(strent);

//ResponseHandler<String> response =new BasicResponseHandler();
//BasicResponseHandler response = new BasicResponseHandler();


HttpResponse responseBody= httpclient.execute(httpget);
Log.i("response status code",responseBody.getStatusLine().toString());
// Log.i("oneout",responseBody.getLastHeader(req));
HttpEntity responseentity = responseBody.getEntity();
String out = EntityUtils.toString(responseentity);
Log.i("Response",out);





}catch(Exception e) {

e.printStackTrace();

System.out.println("Exception Thanks God : " + e.toString());

}



}
}
kamal89
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Mar 22, 2011 1:37 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 9 guests