android soap web service - not retrieving output - android

private final String zipCodenameSpace ="http://www.webserviceX.NET/";
private final String zipURL="http://www.webserviceX.net/uszip.asmx";
private final String zipSoapAction ="http://www.webserviceX.NET/GetInfoByCity";
private final String zipMethodName="GetInfoByCity";
SoapObject request = new SoapObject(zipCodenameSpace, zipMethodName);
PropertyInfo cityInfo = new PropertyInfo();
cityInfo.setName("USCity");
cityInfo.setValue(city);
// cityInfo.setType(String.class);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
request.addProperty(cityInfo);
TextView tv = (TextView) findViewById(R.id.tv1);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(zipURL);
try {
androidHttpTransport.call(zipSoapAction, envelope);
// Object response =(SoapObject) envelope.getResponse();
SoapObject response = (SoapObject) envelope.getResponse();
Log.d("This is an element", response.toString());
// tv.setText(response.toString());
// return response.toString();
} catch (Exception e) {
e.printStackTrace();
}
Showing null exception. Error is occurring at soapObject response.
I tried to use soap primitive but not working. Please help me where the problem is
Given Webservice returns xml.

cityInfo.setValue(city);
Where are you fetching this "city" value in your code? I think thats the problem. For testing you can set it as string directly here.like "NewYork".

Related

how to fix SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request

I sync data from webservice using SOAP(ksoap2) lib.Early days my application is everything ok. Today, when I run my program today, I get the following error at this line SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
private final static String NAMESPACE = "http://tempuri.org/";
private static String URL = "http://172.230.0.30/pos_cashsale/Service1.asmx";
private final static String SOAP_ACTION = "http://tempuri.org/";
public static String invokeJSONWS(String Name1, String Value1,
String Name2, String Value2, String methName) {
String responseJSON = "";
// Create request
try {
SoapObject request = new SoapObject(NAMESPACE, methName);
if (!Value1.equals("")) {
// Property which holds input parameters
PropertyInfo paramPI = new PropertyInfo();
// Set Name
paramPI.setName(Name1);
// Set Value
paramPI.setValue(Value1);
// Set dataType
paramPI.setType(String.class);
// Add the property to request object
request.addProperty(paramPI);
}
if (!Value2.equals("")) {
// Property which holds input parameters
PropertyInfo paramPI2 = new PropertyInfo();
// Set Name
paramPI2.setName(Name2);
// Set Value
paramPI2.setValue(Value2);
// Set dataType
paramPI2.setType(String.class);
// Add the property to request object
request.addProperty(paramPI2);
}
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER10);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION + methName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to static variable
responseJSON = response.toString();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return responseJSON;
}

android send data to a .net webservice

I am trying to create a android app to send text and photos to .net webservice. I have functions in my webservice. one of them gets a dummy name(I created this to check if I can make a connection) and the other one is to insert some data into DB. I want to post my work to get help.
private final String NAMESPACE = "http://methodoor.com/";
//webservice is working, you can check it online
private final String URL = "http://servicing2.rotanet.com.tr/service.asmx";
private final String SOAP_ACTION = "http://methodoor.com/checkupservice/SendData";
private final String METHOD_NAME = "SendData";
//Create request
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("containerId",1);
.........
.........
request.addProperty("sFileID","asd");
request.addProperty("userId",1);
//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(URL);
try {
//Invole web service
androidHttpTransport.call(SOAP_ACTION, envelope);
//Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
//Assign it to fahren static variable
fahren = response.toString();
} catch (Exception e) {
}
My problem is, I am not sure if this is the correct way to pass data to webservice. it doesnt crash or gives any error message. It just doesnt insert into the DB
here you go..make sure to check spelling of each tag in your service, method name and path of your service..
public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL,String IP,String SERVICEPATH) throws IOException, XmlPullParserException
{
abc.allowAllSSL();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
//request.addProperty("iTopN", "5"); //variable name, value. I got the variable name, from the wsdl file!
request.addProperty("UserId", login);
request.addProperty("Password", password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap
envelope.dotNet = true;
envelope.setOutputSoapObject(request); // prepare request
envelope.bodyOut = request;
Log.d("ENVELOPE",""+"Coming3");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//androidHttpTransport.
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.d("ENVELOPE",""+envelope.bodyIn);
SoapObject result = (SoapObject) envelope.bodyIn; // get response
Log.d("ENVELOPE",""+envelope.bodyIn);
SoapObject responseBodyRaw,responseBody,tableRow;
return result;
}
Here is parameter details
private String NAMESPACE = "http://tempuri.org/";
private String SOAP_ACTION = "http://tempuri.org/UserProfile";
private String METHOD_NAME = "UserProfile";
private String URL="https://172.17.60.15/HostingService/PhoneForService.asmx";
//private String URL="https://172.19.2.250/testService/phone.asmx";
private String SERVICEPATH="/HostingService/PhoneForService.asmx";
I hope would be helpful for you

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

how to parse through complex soap objects in Android

Hello Friends i am using soap web services very first time in my code.
but i am not getting how to handle nested soap objects.
this is my code
private final String URL = "http://192.168.0.20/BookingEngineService/HotelBookingService.asmx";
private final String SOAP_ACTION = "http://tempuri.org/AndroidTestRequest";
private final String METHOD_NAME = "AndroidTestRequest";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("User", "abcd#xyz.com");
request.addProperty("Password", "abcd#123");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.i("myAppEnvelope", envelope.toString());
SoapObject response = (SoapObject) envelope.getResponse();
// here i am trying to get values from response which is soap object
for (int i = 0; i < response.getPropertyCount(); i++) {
SoapObject con = (SoapObject) response.getProperty(i);
Log.e("Continent", con.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
i am getting soap object as a response and which is very complex so i am not getting how to parse it. this is my response this is very small part of my response.
I am not getting how to get values from SoapObject -> Properties -> elementData -> value-> property -> elementData and so on ... its too complex please help me.
You can convert soap object to a string. Check the example code bellow
Eg:
final SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
final String str = response.toString();
It's a simple XML parsing. Go through the link for more details.
You can get the response as input stream and convert that into string and using that string, you can create an XML object. Please refer the link for more information.

Android: soap primitive error

I am having some issues with accessing a web service. Getting ClassCastException Error. Consider a scenario that I am trying to access a method of a web-service and the webservice is supposed to return two strings (Lets say String1 and String2). Moreover, I have to provide or pass two parameters (lets say Parameter 1 and Parameter 2 where Parameter 1 should be integer and Parameter 2 should be String) Here is my code
public class MyWebService extends Activity {
private static final String SOAP_ACTION ="http://www.mywebsite.com/myMethod";
private static final String METHOD_NAME = "MyMethod";
private static final String NAMESPACE = "http://www.myNamespace/";
private static final String URL = "http://mysession.com/myservice.asmx?WSDL";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("Parameter 1");
pi.setValue(1);
pi.setType(pi.INTEGER_CLASS);
request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("Parameter 2");
pi2.setValue("Any string");
pi2.setType(pi2.STRING_CLASS);
request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result=(SoapObject)envelope.getResponse();
String string1=result.getProperty(0).toString();
String string2=result.getProperty(1).toString();
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is the exception I am getting
java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive
Can anyone tell me if I am doing something wrong here..
Thanks
Try this,
SoapPrimitive result= (SoapPrimitive)envelope.getResponse();
OR
Object result= (Object)envelope.getResponse();
instead of
SoapObject result=(SoapObject)envelope.getResponse();
Try this:
SoapObject request = new SoapObject(SOAP_NAMESPACE,SOAP_METHOD);
request.addProperty("name", abcd);
request.addProperty("age", 30);

Categories

Resources