How to remove an item from cart using magento api in android? - android

I am using "shoppingCartProductRemove" api to remove an item from cart in magento. For that i am using the following code:
SoapObject item = new SoapObject(NAMESPACE,"shoppingCartProductEntity");
PropertyInfo pinfo = new PropertyInfo();
String productid = productId.get(deleteProductPosition);
pinfo.setName("product_id");
pinfo.setValue(productid);
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
String productsku = productSku.get(deleteProductPosition);
pinfo.setName("sku");
pinfo.setValue(productsku);
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
int productQty = Qty.get(deleteProductPosition);
pinfo.setName("qty");
pinfo.setValue(productQty);
pinfo.setType(Double.class);
item.addProperty(pinfo);
SoapObject EntityArray = new SoapObject(NAMESPACE,"shoppingCartProductEntity");
EntityArray.addProperty("productsData", item);
SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductRemove");
request.addProperty("sessionId", sessionId);
request.addProperty("quoteId", 118);
request.addProperty("productsData", item);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
Object catrInfoObjs = env.getResponse();
but i am getting the xml pullparser exception. Is there any reference to remove an item from cart. Need help here!!

I got it using the following code:
SoapObject item = new SoapObject(NAMESPACE, "shoppingCartProductEntity");
PropertyInfo pinfo = new PropertyInfo();
pinfo.setName("product_id");
pinfo.setValue(productId.get(deleteProductPosition));
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
pinfo.setName("sku");
pinfo.setValue(productSku.get(deleteProductPosition));
pinfo.setType(String.class);
item.addProperty(pinfo);
int productQty = Qty.get(deleteProductPosition);
pinfo = new PropertyInfo();
pinfo.setName("qty");
pinfo.setValue(productQty);
pinfo.setType(Double.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
pinfo.setName("options");
pinfo.setValue(" ");
pinfo.setType(String[].class);
item.addProperty(pinfo);
SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
EntityArray.addProperty("products",item);
SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductRemove");
request.addProperty("sessionId", sessionId);
request.addProperty("quoteId", 74);
request.addProperty("products",EntityArray);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
Object result = (Boolean) env.getResponse();

Related

Parse Ksoap response array in android

I want to parse my Ksoap response array but not getting it
Response when debug app:
events_data {
events = [events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
},
events {
groom = sanskaar;
bride = saumya;
event_name = hzbrgbj;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
},
events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
}
];
}
Code using to parse response:
SoapObject response = (SoapObject) envelope.getResponse();
//SoapObject response = (SoapObject) envelope.bodyIn;
System.out.print(response);
int count = response.getPropertyCount();
System.out.print(count);
for(int i=0;i<response.getPropertyCount();i++){
Object property = response.getProperty(i);
if(property instanceof SoapObject){
SoapObject final_object = (SoapObject) property;
//Parsing response data
Event_data.put("groom", final_object.getProperty("groom").toString());
System.out.print(Event_data);//testing of response data
}
}
(property instanceof SoapObject) Giving false. Code does not parse response.
While i am parsing this following response with same activity code its working good:
data {
user = user {
id = 39;
user_name = ;
email = ;
phone = 7827701616;
address = ;
url = ;
user_role = 1;
plan = 1;
verification_pin = 18053;
status = 1;
android_id = 38d23c7201b21f93;
};
}
Help me with this.
Try this code buddy:
SoapObject response = (SoapObject) envelope.getResponse();
//SoapObject response = (SoapObject) envelope.bodyIn;
System.out.print(response);
int count = response.getPropertyCount();
System.out.print(count);
for(int i=0;i<response.getPropertyCount();i++){
Object property = response.getProperty(i);
if(property instanceof SoapObject){
SoapObject final_object = (SoapObject) property;
for(int j=0; j<final_object.getPropertyCount();j++){
Object final_property = final_object.getProperty(j);
if(final_property instanceof SoapObject){
SoapObject array_object = (SoapObject) final_property;
//Parsing response data
Event_data.put("groom",array_object.getProperty("groom").toString());
}
}
System.out.print(Event_data);//testing of response data
}
}
Read this:
How to parse this type soap array response in android
According to the other posts the response should be as given below, Kindly check it,
events_data {
events = events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
};
events {
groom = sanskaar;
bride = saumya;
event_name = hzbrgbj;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
};
events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
};
}
I solve my problem by using VECTOR
Code:
ht.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
for(int i=0;i<response.getPropertyCount();i++){
Vector resV = (Vector)response.getProperty(i);
int resVlenght = resV.size();
for(int count = 0;count<resVlenght;count++)
{
HashMap<String,String> value = new HashMap<String,String>();
String n = resV.elementAt(count).toString();
SoapObject p = (SoapObject)resV.elementAt(count);
System.out.print(n);
String groom= p.getProperty("groom").toString();
}
}

I need to arrange the barcharts properly in android

Right now i am creating a barchart in android using AChartEngine.After getting run of my application,at-first the emulator is showing like the first below image. But i need to show like the second below image how to do this?
And also i need to change the color for the background and also i wanna change the bar-charts colors,
How to do these things?
I have tried these codes, but not working
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.GRAY);
Please find my sources for reference.
Chart.java
public class Chart extends Activity {
EditText edt1, edt2;
TextView txtv1;
Button btn;
Bundle data;
String[] orderNo = new String[10];
int[] freightRate = new int[10];
int[] marginPercent = new int[10];
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getTMSChart(edt1.getText().toString(), edt2.getText().toString());
Intent intnt = new Intent(v.getContext(), BarGraphActivity.class);
intnt.putExtras(data);
startActivity(intnt);
}
});
}
public void getTMSChart(String FromDate, String ToDate)
{
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String METHOD = "GetTMSChart";
String NAMESPACE = "http://tempuri.org/";
String SOAP_ACTION = "http://tempuri.org/GetTMSChart";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate.trim());
request.addProperty("ToDate", ToDate.trim());
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
data = new Bundle();
for (int i = 0; i < tablesCount; i++) {
SoapObject table = (SoapObject) root.getProperty(i);
orderNo[i] = table.getPropertyAsString("Order_No");
freightRate[i] = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
marginPercent[i] = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
/*Toast.makeText(getApplicationContext(), "Order No:" + orderNo[i] + "\nFreigtRate:" + freightRate[i] + "\nMarginPc:" + marginPercent[i], Toast.LENGTH_SHORT).show();*/
}
data.putStringArray("orderno", orderNo);
data.putIntArray("freightrate", freightRate);
data.putIntArray("marginpercent", marginPercent);
data.putInt("count",tablesCount);
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} }}
BarGraphActivity.java
public class BarGraphActivity extends Activity{
String[] orderNo = new String[10];
int[] freightRate = new int[10];
int[] marginPercent = new int[10];
int count;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Bundle idata = getIntent().getExtras();
if (idata !=null)
{
orderNo = idata.getStringArray("orderno");
freightRate = idata.getIntArray("freightrate");
marginPercent = idata.getIntArray("marginpercent");
count = idata.getInt("count");
CategorySeries series = new CategorySeries("Order-FreightRate Graph");
for ( int i = 0; i < count; i++){
series.add(orderNo[i], freightRate[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series.toXYSeries());
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setDisplayChartValues(true);
//renderer.setChartValuesSpacing(1);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
for ( int i = 0; i < count; i++){
mRenderer.addXTextLabel(i+1, orderNo[i]);
}
mRenderer.setZoomButtonsVisible(true);
mRenderer.setBarSpacing(0.5);
Intent intent = ChartFactory.getBarChartIntent(getApplicationContext(), dataset, mRenderer, Type.DEFAULT);
startActivity(intent);
} } }
Thanks for your precious time!..
Hi if you want to change background color for your chart just use these methods
mrenderer.setApplyBackgroundColor(true);
mrenderer.setBackgroundColor(Color.parseColor("#898989")); // here you have to give hexa decimal code
mrenderer.setMarginsColor(Color.parseColor("#898989")); // here you have to give hexa decimal code
If you want to change your bar color means just do like this
int[] colors = new int[] { Color.parseColor("#DAE1EB"), Color.parseColor("#406193")};
int color_length = colors.length;
for (int i = 0; i < color_length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
r.setChartValuesSpacing(5);
mrenderer.addSeriesRenderer(r);
}
If you are creating multiple renderer means use different color for the dual bar. If you are creating single bar means give only one color. It will works.

Unable to show values in separate text views in android

I am consuming a web service by soap method from Android. And I am showing the values from that web service in to two separate text views on the next screen.
Here that web service is returning two values. But I'm only able to show one value from that web service in text view on the next screen.
But I need to show both values in two separate textview boxes on the next screen....
How can I do this?
Suggestions please..
NOTE :- The input value for that web service is for FromDate : 01/01/2012 and
for ToDate : 07/07/2012
Please find my sources for reference
Main_WB.java
public class Main_WB extends Activity
{
EditText edt1,edt2;
//TextView txt_1;
Button btn;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText)findViewById(R.id.editText1);
edt2 = (EditText)findViewById(R.id.editText2);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
getTMSChart(edt1.getText().toString(),edt2.getText().toString());
Intent myint = new Intent(Main_WB.this,ResultActivity.class);
startActivity(myint);
}
});
}
private void getTMSChart(String FromDate,String ToDate)
{
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject)(result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
// String[] ord = new String[propertyCount];
// String[] fre = new String[propertyCount];
// int[] fre = new int[propertyCount];
// int[] margin = new int[propertyCount];
for (int j = 0; j < propertyCount; j++)
{
String x,y;
// int orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
// int freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
// int marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
String orderNo = table.getPropertyAsString("Order_No");
String freight = table.getAttributeAsString("Freight_Rate");
x = orderNo.toString();
y = freight.toString();
Intent in = new Intent(getApplicationContext(),ResultActivity.class);
in.putExtra("gotonextpageX",x);
in.putExtra("gotonextpageY", y);
startActivity(in);
//ord[j] = orderNo;
// fre[j] = freightRate;
// margin[j]= marginPercent;
// x = orderNo.toString();
// y = fre.toString();
// Intent myIntent = new Intent(Main_WB.this, ResultActivity.class);
// myIntent.putExtra("gotonextpage", x);
// startActivity(myIntent);
// whatever you do with these values
}
}
}
catch (Exception e)
{
}
} }
ResultActivity.java
public class ResultActivity extends Activity
{
String x,y;
TextView txt1,txt2;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
x = extras.getString("gotonextpageX");
y = extras.getString("gotonextpageY");
}
else
{
}
txt1 = (TextView)findViewById(R.id.txtVw);
txt2 = (TextView)findViewById(R.id.txtVw2);
txt1.setText(x);
txt2.setText(y);
}}
Thanks for your precious time!..
Here check it out ...
public class Main_WB extends Activity {
EditText edt1, edt2;
// TextView txt_1;
Button btn;
ArrayList<String> result;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
result = new ArrayList<String>();
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
result.addAll(getTMSChart(edt1.getText().toString(), edt2.getText().toString()));
Intent in = new Intent(getApplicationContext(), ResultActivity.class);
in.putExtra("gotonextpageX", result.get(0));
in.putExtra("gotonextpageY", result.get(1));
startActivity(in);
}
});
}
private ArrayList<String> getTMSChart(String FromDate, String ToDate) {
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
String x = "", y = "";
ArrayList<String> stringResult = new ArrayList<String>();
try {
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++) {
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
for (int j = 0; j < propertyCount; j++) {
stringResult.add(table.getPropertyAsString("Order_No").toString());
stringResult.add(table.getPropertyAsString("Freight_Rate").toString());
}
}
} catch (Exception e) {
}
return stringResult;
}
}
And dont change your second class, this must work.

Calling a web method from eclipse using KSOAP2

I created a web service using visual studio and tested it, it works fine. I am trying to call a web method from eclipse. I don't get any errors but the problem is nothing happens. It is supposed to insert values taken from the user into the database. I have given the java class and web method below. What am I doing wrong? Please help
////Java Class to call web method passing in values/////
public class Registration extends Activity{
private static final String SOAP_ACTION = "http://tempuri.org/register";
private static final String OPERATION_NAME = "register";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:54714/WebSite1/Service.asmx";
Button sqlRegister;
EditText sqlFirstName,sqlLastName,sqlEmail,sqlMobileNumber,sqlCurrentLocation,sqlUsername,sqlPassword;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
sqlFirstName = (EditText) findViewById(R.id.etFname);
sqlLastName = (EditText) findViewById(R.id.etLname);
sqlEmail = (EditText) findViewById(R.id.etEmail);
sqlMobileNumber = (EditText) findViewById(R.id.etPhone);
sqlCurrentLocation = (EditText) findViewById(R.id.etCurrentLoc);
sqlUsername = (EditText) findViewById(R.id.etUsername);
sqlPassword = (EditText) findViewById(R.id.etPwd);
sqlRegister = (Button) findViewById(R.id.bRegister);
sqlRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
switch (v.getId()){
case R.id.bRegister:
try{
String firstname = sqlFirstName.getText().toString();
String lastname = sqlLastName.getText().toString();
String emailadd = sqlEmail.getText().toString();
String number = sqlMobileNumber.getText().toString();
String loc = sqlCurrentLocation.getText().toString();
String uname = sqlUsername.getText().toString();
String pwd = sqlPassword.getText().toString();
SoapObject Request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("fname");
pi.setValue(firstname);
pi.setType(int.class);
Request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("lname");
pi2.setValue(lastname);
pi2.setType(int.class);
Request.addProperty(pi2);
PropertyInfo pi3 = new PropertyInfo();
pi2.setName("email");
pi2.setValue(emailadd);
pi2.setType(int.class);
Request.addProperty(pi3);
PropertyInfo pi4 = new PropertyInfo();
pi2.setName("num");
pi2.setValue(number);
pi2.setType(int.class);
Request.addProperty(pi4);
PropertyInfo pi5 = new PropertyInfo();
pi2.setName("locID");
pi2.setValue(loc);
pi2.setType(int.class);
Request.addProperty(pi5);
PropertyInfo pi6 = new PropertyInfo();
pi2.setName("username");
pi2.setValue(uname);
pi2.setType(int.class);
Request.addProperty(pi6);
PropertyInfo pi7 = new PropertyInfo();
pi2.setName("password");
pi2.setValue(pwd);
pi2.setType(int.class);
Request.addProperty(pi7);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(SOAP_ADDRESS);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
int result = Integer.parseInt(response.getProperty(0).toString());
if(result ==1){
Toast.makeText(Registration.this, "You have been registered Successfully", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(Registration.this, "Try Again", Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
e.printStackTrace();
}
break;
}
}
});
}
}
///Web Method in visual Studio////
[WebMethod]
public int register(string fname, string lname, string email, string num, int locID,string username,string password)
{
SqlConnection conn;
conn = ConnectionManager.GetConnection();
conn.Open();
string cmdregister = "INSERT into [User] values(#fname,#lname,#email,#num,#locID)";
SqlCommand sqlCommand = new SqlCommand(cmdregister, conn);
sqlCommand.CommandType = CommandType.Text;
sqlCommand.Parameters.Add("#fname", SqlDbType.Text).Value = fname;
sqlCommand.Parameters.Add("#lname", SqlDbType.Text).Value = lname;
sqlCommand.Parameters.Add("#email", SqlDbType.Text).Value = email;
sqlCommand.Parameters.Add("#num", SqlDbType.Text).Value = num;
sqlCommand.Parameters.Add("#locID", SqlDbType.Int).Value = locID;
sqlCommand.ExecuteNonQuery();
string cmdlogin = "INSERT into [Login] values(#username,#id,#password)";
SqlCommand sqllogin = new SqlCommand(cmdlogin, conn);
sqllogin.CommandType = CommandType.Text;
sqllogin.Parameters.Add("#username", SqlDbType.Text).Value = username;
sqllogin.Parameters.Add("#password", SqlDbType.Text).Value = password;
sqllogin.ExecuteNonQuery();
conn.Close();
return 1;
}
I found what was wrong, thanks to someone.
1) I have used:
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(SOAP_ADDRESS);
Instead it should be:
HttpTransportSE httptransport = new HttpTransportSE(SOAP_ADDRESS);
2) I have used:
PropertyInfo pi = new PropertyInfo();
pi.setName("fname");
pi.setValue(firstname);
pi.setType(int.class);
Request.addProperty(pi);
Instead it should be:
request.addProperty("fname", String.valueOf(firstname));
For the other text fields as well

Android call WCF Service , that return DataTable

How to process Data table in android>My service return dataTable.How to handle it?
public static final String APPURL = "http://192.168.1.213:6969/MySalesServices";
private static final String METHOD_NAME = "SalesList";
private static final String NAMESPACE = "http://tempuri.org/";
private static String SOAP_ACTION = "http://tempuri.org/IMySalesServices/SalesList";
SoapPrimitive responsePrimitive = null;
ArrayList<String> tablesName = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState) {
..................
}
public SoapPrimitive soapPrimitive(String METHOD_NAME, String SOAP_ACTION,String NAMESPACE, String URL) throws IOException, XmlPullParserException {
SoapPrimitive responses = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
request.addProperty("strExec", strExecutive);
request.addProperty("strBusinessUnit", strBusinessUnit);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
responses = (SoapPrimitive) envelope.getResponse();
}catch(SocketException ex){
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return responses;
}
I got following error :
AnyType{element=anyType{complexType=anyType{choice=anyType{element=anyType{complexType=anyType{sequence=anyType{element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; }; }
please help me
You return the Method type as String & concert it Datatable to Json as String that is good way to do & easy
//Converting table to json
public String ConverTableToJson(DataTable dtDownloadJson)
{
string[] StrDc = new string[dtDownloadJson.Columns.Count];
string HeadStr = string.Empty;
if (dtDownloadJson.Rows.Count > 0)
{
for (int i = 0; i < dtDownloadJson.Columns.Count; i++)
{
StrDc[i] = dtDownloadJson.Columns[i].Caption;
HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
}
if (HeadStr.Length > 0)
{
HeadStr = HeadStr.Substring(0, HeadStr.Length - 1);
StringBuilder Sb = new StringBuilder();
Sb.Append("{\"" + dtDownloadJson.TableName + "\" : [");
for (int i = 0; i < dtDownloadJson.Rows.Count; i++)
{
string TempStr = HeadStr;
Sb.Append("{");
for (int j = 0; j < dtDownloadJson.Columns.Count; j++)
{
TempStr = TempStr.Replace(dtDownloadJson.Columns[j] + j.ToString() + "¾", dtDownloadJson.Rows[i][j].ToString());
}
Sb.Append(TempStr + "},");
}
Sb = new StringBuilder(Sb.ToString().Substring(0, Sb.ToString().Length - 1));
Sb.Append("]}");
return Sb.ToString();
}else
{
return "0";
}
}
else
{
return "0";
}
}
The error you are getting aint an error at all. At least, thats the behavious I saw at my own application using a setup that was quite like the one you have there. Have you tried casting the response to a SoapObject? You can then call the .getPropertyCount() method on that SoapObject to start looping trough the content of the response. Quick example:
//Create a Transport object makes the webservice call
HttpTransportSE httpTrans = new HttpTransportSE(URL);
httpTrans.call(SOAP_ACTION, env);
//Cast the object to SoapObject
SoapObject storages = (SoapObject)env.getResponse();
//Loop trough the result
for(int i = 0; i < storages.getPropertyCount(); i++) {
//Get a SoapObject for each storage
SoapObject storage = (SoapObject)storages.getProperty(i);
}
Seeing the response you got, you might have to dig a few levels deep to get the data you need tho. Either 6 or 7 levels deep. If it is an option, I would change the response you get from the webservice so that it is easier to parse.

Categories

Resources