on 05-25-2012 8:02 AM
Hi,
I want consume the SAP SOAP web-services from Android .For that i was written the Following Code .
package com.venkattt.pack;
import java.net.SocketException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
public class SoapWebservicesExampleActivity extends Activity {
/** Called when the activity is first created. */
final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
final String URL = "http://*************:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_p...";
final String METHOD_NAME = "Z_GET_CUST_GEN";
final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
// request.addProperty("Input", "1460");
request.addProperty("Langu", "d");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); // put all required data into a soap
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
Object result = (Object) envelope.getResponse();
System.out.println("The Result is "+result);
}
catch(SocketException ex){
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
But when i Ruining the Application in Android I Got The Following Exception in My Android Log cat in Eclipse:
05-25 12:29:51.445: WARN/System.err(1008): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions targetNamespace='urn:sap-com:document:sap:soap:functions:mc-style'>@1:686 in java.io.InputStreamReader@405450f0)
05-25 12:29:51.455: WARN/System.err(1008): | at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273) |
05-25 12:29:51.455: WARN/System.err(1008): | at org.kxml2.io.KXmlParser.require(KXmlParser.java:1424) |
Please see once and let me know where i am doing the wrong in My Code.
Thanks in Advance......
Venkat.A
Hi Venkat, Ca you make sure you are using the BINDING URL for calling the Service (not the WSDL URL).
You can get your Binding URL of your service from the WSDL file.
The XML Tag name would be, <soap: address_location>.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Venkat and Kaushal,
Please refer the below code for accessing SAP web service from Android.
final static String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style"; // Name space from WSDL
final static String METHOD_NAME = "GetUser"; //Operation Name form WSDL
final static String SOAP_ACTION = "NAMESPACE + METHOD_NAME";
final static String URL ="http://server:port/sap/bc/srt/rfc/sap/zget_user_dets/100/zsn_getuserdets/zbn_getuserdets"; // address location
private static final String USERNAME = ""; //Login user id of SAP server
private static final String PASSWORD = ""; //Login Password of Sap Server
public void onCreate(Bundle savedInstanceState) {
/*** Application logic here *********/
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AuthTransportSE androidHttpTransport=null;
try{
androidHttpTransport = new AuthTransportSE(URL,USERNAME, PASSWORD);
androidHttpTransport.debug = true;
}
catch(Exception ex)
{
System.out.println("eror: "+ex);
}
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.bodyIn;
String uname = response.getPropertyAsString("Return1"); // Export var from SAP Function module
String pass = response.getPropertyAsString("Return2");
String lang = response.getPropertyAsString("Return3");
/********* Process output here *************/
}
catch (Exception e)
{
e.printStackTrace();
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Venkat and Kaushal,
To access SAP web service from Android using ksoap2, use the class HttpTransportBasicAuth.
Pass your parameters as below.
Also make sure you pass the binding URL of the SAP web service( which you can get from the WSDL file).
For eg.
HttpTransportBasicAuth auht= new HttpTransportBasicAuth(url,username,password);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Facing the same problem. Trying to find a solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm assuming you haven't linked ksoap2 library appropriately to the android project. Even though the ksoap2 jar file appears under project properties, I would still recommend you to drag and drop the jar into lib folder in the project directory structure. See if that helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.