KSOAP2 webservice (I know it's been addressed before)

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

KSOAP2 webservice (I know it's been addressed before)

Postby cchang » Fri Feb 27, 2009 6:43 pm

Hi,

I'm having a tough time trying to find a solution to access a webservice with ksoap2. I've downloaded the lib ksoap2-j2se-full-2.1.2.jar and added it to my project. I saw other posts here and other forums about this but still can't find a solution to create the soap request and keep having this error:

02-27 17:24:38.429: WARN/System.err(2654): SoapFault - faultcode: 'soap:Client' faultstring: 'Invalid request or credentials' faultactor: 'http://services.sapo.pt' detail: org.kxml2.kdom.Node@4340be80
02-27 17:24:38.449: WARN/System.err(2654): at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(Unknown Source)
02-27 17:24:38.458: WARN/System.err(2654): at org.ksoap2.SoapEnvelope.parse(Unknown Source)
02-27 17:24:38.458: WARN/System.err(2654): at org.ksoap2.transport.Transport.parseResponse(Unknown Source)
02-27 17:24:38.458: WARN/System.err(2654): at org.ksoap2.transport.HttpTransportSE.call(Unknown Source)
02-27 17:24:38.458: WARN/System.err(2654): at com.criticalsoftware.meo.Main.callWebService(Main.java:54)
02-27 17:24:38.468: WARN/System.err(2654): at com.criticalsoftware.meo.Main$1.onClick(Main.java:37)
02-27 17:24:38.468: WARN/System.err(2654): at android.view.View.performClick(View.java:2109)
02-27 17:24:38.468: WARN/System.err(2654): at android.view.View.onTouchEvent(View.java:3523)
02-27 17:24:38.468: WARN/System.err(2654): at android.widget.TextView.onTouchEvent(TextView.java:4410)
02-27 17:24:38.649: WARN/System.err(2654): at android.view.View.dispatchTouchEvent(View.java:3178)
02-27 17:24:38.649: WARN/System.err(2654): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
02-27 17:24:38.649: WARN/System.err(2654): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
02-27 17:24:38.649: WARN/System.err(2654): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
02-27 17:24:38.649: WARN/System.err(2654): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
02-27 17:24:38.649: WARN/System.err(2654): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1561)
02-27 17:24:38.649: WARN/System.err(2654): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1085)
02-27 17:24:38.670: WARN/System.err(2654): at android.app.Activity.dispatchTouchEvent(Activity.java:1873)
02-27 17:24:38.679: WARN/System.err(2654): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1545)
02-27 17:24:38.679: WARN/System.err(2654): at android.view.ViewRoot.handleMessage(ViewRoot.java:1140)
02-27 17:24:38.679: WARN/System.err(2654): at android.os.Handler.dispatchMessage(Handler.java:88)
02-27 17:24:38.679: WARN/System.err(2654): at android.os.Looper.loop(Looper.java:123)
02-27 17:24:38.679: WARN/System.err(2654): at android.app.ActivityThread.main(ActivityThread.java:3742)
02-27 17:24:38.679: WARN/System.err(2654): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 17:24:38.679: WARN/System.err(2654): at java.lang.reflect.Method.invoke(Method.java:515)
02-27 17:24:38.679: WARN/System.err(2654): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
02-27 17:24:38.690: WARN/System.err(2654): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
02-27 17:24:38.690: WARN/System.err(2654): at dalvik.system.NativeStart.main(Native Method)

The error occurs on the line:
androidHttpTransport.call(SOAP_ACTION, envelope);

I guess it is related to one of this variables:
private static final String SOAP_ACTION = "http://services.sapo.pt/Metadata/EPG/GetChannelList";
private static final String METHOD_NAME = "GetChannelList";
private static final String NAMESPACE = "http://services.sapo.pt/Metadata/EPG";
private static final String URL = "http://services.sapo.pt/Metadata/Contract/EPG?culture=PT";

The webservice I'm trying to access is:
WSDL: http://services.sapo.pt/Metadata/Contra ... culture=PT
Available methods: http://services.sapo.pt/Metadata/Service/EPG?culture=PT

I'm trying to call the very simple method: "GetChannelList", but I can't get it to work. I'm able to call the webservice with no problems using soapUI. Thanks for everything.

Here is my activity code:

package com.criticalsoftware.meo;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Main extends Activity {
private Button okButton;
private TextView result;
private Object resultRequestSoap = null;
private static final String SOAP_ACTION = "http://services.sapo.pt/Metadata/EPG/GetChannelList";
private static final String METHOD_NAME = "GetChannelList";
private static final String NAMESPACE = "http://services.sapo.pt/Metadata/EPG";
private static final String URL = "http://services.sapo.pt/Metadata/Contract/EPG?culture=PT";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

result = (TextView) findViewById(R.id.result);
okButton = (Button) findViewById(R.id.invio);

okButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
callWebService();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
});
}

public void callWebService() throws IOException, XmlPullParserException{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {
androidHttpTransport.call(SOAP_ACTION, envelope);
resultRequestSoap = envelope.getResponse();
//Parse Response
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
//Return a String for view
result.setText(resultsRequestSOAP.getProperty(0).toString());
} catch (Exception e) {
e.printStackTrace();
}

}
}
cchang
Freshman
Freshman
 
Posts: 8
Joined: Mon Feb 23, 2009 4:40 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests