Web Service return null in Android - android

I have a web service that I use in my android project. One method in my web service return null in android with ksoap2. When I debug the project, envelope is returning like this:
GPSYerBilgisiGetirResponse{GPSYerBilgisiGetirResult=anyType{}; }
Out of android, I run the web service and give parameter to method, returning data like this:
<ArrayOfFirma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Firma>
<gpsilce>BEYOĞLU</gpsilce>
<gpssemt>KASIMPAŞA</gpssemt>
</Firma>
</ArrayOfFirma>
This is my function for using connect to web service
private String[] konumGetir(String ParamPK){
PropertyInfo pk = new PropertyInfo();
pk.name= "pk";
pk.setValue(ParamPK);
pk.type = PropertyInfo.STRING_CLASS;
SoapObject request = new SoapObject(NAMESPACE, "GPSYerBilgisiGetir");
request.addProperty(pk);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut=request;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call("http://tempuri.org/GPSYerBilgisiGetir", envelope);
SoapObject response = (SoapObject) envelope.getResponse();
konumList=new String[1];
for(int i=0;i<response.getPropertyCount();i++){
Object property = response.getProperty(i);
if(property instanceof SoapObject){
SoapObject firmalar = (SoapObject) property;
konumList[0]=firmalar.getProperty("gpssemt") + "-" + firmalar.getProperty("gpsilce");
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return konumList;
}
This is my web service method:
<WebMethod()> _
Public Function GPSYerBilgisiGetir(ByVal pk As String) As List(Of Firma)
Dim konumlist As New List(Of Firma)
Dim dg As New dgetir("SELECT DISTINCT ILCE,SEMT FROM GPSYERBILGISI WHERE PK='" + pk + "'")
While dg.dtr.Read
Dim gpskonum As New Firma
gpskonum.gpsilce = dg.dtr.Item("ILCE")
gpskonum.gpssemt = dg.dtr.Item("SEMT")
konumlist.Add(gpskonum)
End While
dg.close()
Return konumlist
End Function

Try this code.
private String[] konumGetir(String ParamPK){
SoapObject request = new SoapObject(NAMESPACE, "GPSYerBilgisiGetir");
request.addProperty("pk", ParamPK);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION_NAME, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
int childCount = result.getPropertyCount();
konumList = new String[childCount];
SoapObject tempArray[] = new SoapObject[childCount];
int i;
for (i = 0; i < childCount; i++) {
tempArray[i] = (SoapObject) result.getProperty(i);
konumList[i] = tempArray.getProperty(0).toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return konumList;
}
Hope it helps.

Related

Android Webservice do not return expected data in listview

I want to fetch a listview from webservice in Android app. I managed to get the data when i tried to break my code. But this is what I get when i break the code in the array list:
[com.xxx.example.Hotels#41319dc0, com.xxx.example.Hotels#4131a518, com.xxx.example.Hotels#4132fec8, com.xxx.example.Hotels#413323a0]
Below is my code that called the list.
mainListView = (ListView) findViewById(R.id.lview);
WebService2 cs = new WebService2();
listHt = cs.selectAllHotels();
listAdapter = new HotelArrayAdapter(this, listHt);
mainListView.setAdapter(listAdapter);
Below is the code called the webservice.
public ArrayList<Hotels> selectAllHotels() {
ArrayList<Hotels> lst = new ArrayList<Hotels>();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapObject table = null;
SoapObject responseBody = null;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
responseBody = (SoapObject) envelope.getResponse();
responseBody = (SoapObject) responseBody.getProperty(1);
table = (SoapObject) responseBody.getProperty(0);
for (int i = 0; i < table.getPropertyCount(); i++) {
Hotels dto = new Hotels();
SoapObject row = (SoapObject) table.getProperty(i);
dto.setName(row.getProperty("HOTELNAME").toString());
lst.add(dto);
}
} catch (Exception e) {
e.printStackTrace();
}
return lst;
}

how to parse data from Soap envelope object in android

SoapObject result = (SoapObject) envelope.getResponse();
SoapObject root = (SoapObject) result.getProperty(0);
SoapObject s_deals = (SoapObject) root.getProperty("InfraWiseDetails");
SoapObject s_deals_1 = (SoapObject) s_deals.getProperty("VisitInfraDetails");
for (int i = 0; i < s_deals_1.getPropertyCount(); i++) {
Object property = s_deals_1.getProperty(i);
if (property instanceof SoapObject) {
SoapObject category_list = (SoapObject) property;
String x = category_list.getProperty("Feedback").toString();
String y = category_list.getProperty("InfraName").toString();
String z = category_list.getProperty("Problem").toString();
}
}
this is my Code
in SoapObject SoapObject result = (SoapObject) envelope.getResponse(); i am getting response --->
anyType{InfraWiseDetails=anyType{VisitInfraDetails=anyType{Feedback=Status OK; InfraName=Tables and Chairs; Problem=null; ResolutionStatus=false; Status=true; };
VisitInfraDetails=anyType{Feedback=Water Quality very poor; InfraName=Water; Problem=Rust in Water; ResolutionStatus=false; Status=false; }; }; VisitMasterId=1; }
I want to Parse data from given SoapObject and get all value of FeedBack, Infraname, Problem... please tell me where am doing wrong i am unable to get value
After long time i am looking on ksoap2 code. Try this :
SoapObject result = (SoapObject) envelope.getResponse();
SoapObject root = (SoapObject) result.getProperty(0);
SoapObject s_deals = (SoapObject) root.getProperty("InfraWiseDetails");
for (int i = 0; i < s_deals.getPropertyCount(); i++) {
SoapObject s_deals_1 = (SoapObject) s_deals.getProperty(i);
String x = s_deals_1.getProperty("Feedback").toString();
String y = s_deals_1.getProperty("InfraName").toString();
String z = s_deals_1.getProperty("Problem").toString();
}
Try like this in your Code , You can parse the data from KSoap
getdata(String SearchValue)- Call this method inside your do inBackground
public void getdata(String SearchValue)
{
// Create request
SoapObject request = new SoapObject(NAMESPACE2, METHOD_NAME2);
PropertyInfo pi4 = new PropertyInfo();
pi4.setName("City");
pi4.setValue(SearchValue);// get the string that is to be sent to the webservice
pi4.setType(String.class);
request.addProperty(pi4);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL2);
try {
// Invole web service
androidHttpTransport.call(SOAP_ACTION2, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
//Converting string to Array list
ArrayList<String> Servciecityname_arr= new ArrayList<String>();
if ((response.toString()).contains("{"))
{
SoapObject rep = (SoapObject) envelope.bodyIn;
JSONArray jr = new JSONArray(rep.getPropertyAsString(0));
for (int i = 0; i < jr.length(); i++) {
JSONObject jb = (JSONObject) jr.get(i);
Cityname = jb.getString("CityName123");
Servciecityname_arr.add(Cityname);
}
CITYNAME = new String[Servciecityname_arr.size()];
CITYNAME = Servciecityname_arr.toArray(CITYNAME);
}
else
{
Status_Response = response.toString();
}
} catch (Exception e) {
Log.i(TAG2, "Error in catch");
e.printStackTrace();
}
}

Magento: transfer product to customer's cart android

I am making shopping cart using android ksoap2 and magento soap api V2. I am unable to move the cart products to customer's cart using the api shoppingCartProductMoveToCustomerQuote. I am getting error as 'Customer’s quote is not existed'.I used the link
I have use the code below:
private String response,id;
String[][] Products = new String[][] {{"20","20","1"}};
protected String doInBackground(String... params)
{
try
{
//SoapEnvelop.VER11 is SOAP Version 1.1 constant
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.xsd = SoapSerializationEnvelope.XSD;
envelope.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE,"login");
request.addProperty("username", "***");
request.addProperty("apiKey", "*********");
//envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(URL);
try
{
transport.debug=true;
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + "shoppingCartProductAdd", envelope);
// transport.call(NAMESPACE + SOAP_ACTION_PREFIX + "catalogProductList", envelope);
response=(String) envelope.getResponse();
String sessionId = response.toString();
Log.d("The session Id is:",sessionId);
SoapObject SingleProduct = new SoapObject(NAMESPACE, "shoppingCartProductEntity");
PropertyInfo pi = new PropertyInfo();
pi.setName("product_id");
pi.setValue(Integer.parseInt(Products[0][0]));
pi.setType(Integer.class);
SingleProduct.addProperty(pi);
pi = new PropertyInfo();
pi.setName("sku");
pi.setValue(Products[0][1]);
pi.setType(String.class);
SingleProduct.addProperty(pi);
pi = new PropertyInfo();
pi.setName("qty");
pi.setValue(Products[0][2]);
pi.setType(Double.class);
SingleProduct.addProperty(pi);
SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
EntityArray.addProperty("products",SingleProduct);
request = new SoapObject(NAMESPACE,METHOD_NAME);
//adding the propery such as sessionId and Customerdata for request
request.addProperty("sessionId",sessionId );
request.addProperty("quoteId",100);
request.addProperty("products",EntityArray);
request.addProperty("options",null);
request.addProperty("bundle_option",null);
request.addProperty("bundle_option_qty",null);
request.addProperty("links",null);
//request.addProperty("store_id", 1);
envelope.setOutputSoapObject(request);
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD_NAME, envelope);
//getting the response which is the customerId
Log.d("Test", "request: " + transport.requestDump);
Log.d("Test", "response: " + transport.responseDump);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (XmlPullParserException e)
{
e.printStackTrace();
}
shoppingCartProductAdd method having only 4 parameters
sessionId,
quoteId,
products\productsData ,
storeId (optional)
, but your sending more then that, so remove
request.addProperty("options",null);
request.addProperty("bundle_option",null);
request.addProperty("bundle_option_qty",null);
request.addProperty("links",null);
from your code and try.
You can add these properties to the shoppingCartProductEntity methods if you want.
http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html for more details

error that occurs while the data from the webservice Ksoap

error occurs when requesting data from the internet in ksoap object
public String[] getProfile(String email) {
String[] profileArray = new String[3];
METHOD_NAME = "getProfile";
SoapObject getprofileSoapObject = new SoapObject(NAMESPACE,METHOD_NAME);
//To avoid code duplication getproperty. Set info
getprofileSoapObject.addProperty(setProperty("email", email));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getprofileSoapObject);
HttpTransportSE http = new HttpTransportSE(URL);
try { //call httptransport
http.call(SOAP_ACTION, envelope);
SoapObject SoapObject2 = (SoapObject) envelope.bodyIn;
//Set profile detail
profileArray[0] = SoapObject2.getProperty(0).toString();
profileArray[1] = SoapObject2.getProperty(1).toString();
profileArray[2] = SoapObject2.getProperty(2).toString();
return profileArray;
} catch (Exception e) {
//System.out.println(e.getMessage());
}
return profileArray;
}
NullPointerException error occurs after http.call

Android : how to pass a integer value to service using KSOAP in android

Not able to pass an integer value to the service request.The value that reaches service request becomes null
Here is my code
private static final String METHOD_NAME ="GetPrivileges";
private static final String NAMESPACE = "http://AuthorizationManagement.ServiceContracts/2007/01/";
private static final String URL ="http://192.168.5.219/NTLS_Authorization
/AuthorisationManager.asmx";
final String SOAP_ACTION ="http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges";
public void call() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi=new PropertyInfo();
pi.type=PropertyInfo.INTEGER_CLASS;
pi.setName("RoleID");
pi.setValue(3);
pi.setNamespace(NAMESPACE);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
String resultData = result.toString();
public void call(int number)
{
try
{
String METHOD_NAME ="GetPrivileges";
String NAMESPACE = "http://AuthorizationManagement.ServiceContracts/2007/01/";
String URL ="http://192.168.5.219/NTLS_Authorization/AuthorisationManager.asmx";
final String SOAP_ACTION ="http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("RoleID",number);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
String resultData = result.toString();
Log.v("Result==>",resultData);
}
catch(Exception e)
{
e.printStackTrace();
}
}
simply you can add this
requestObject.addProperty("RoleID",3);
May be try this code //note don't put directly number(3 in ur case) instead pass it as parameter ...
final SoapObject requestObject = new SoapObject(Constants.NAMESPACE,METHOD_NAME );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
requestObject.addProperty("RoleID",number);
envelope.setOutputSoapObject(requestObject);
AndroidHttpTransport androidHttpTransport =new AndroidHttpTransport(Constants.URL);
try
{
androidHttpTransport.call(Constants.SOAP_ACTION+METHOD_NAME, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
Log.v("result",response.toString());
}
catch(Exception e)
{
e.printStackTrace();
}

Categories

Resources