Good evening,
I need your help.
Until now, using my webservice to withdraw data, there was no problem.
Even to receive the data, I have to send some. Example: Login.
However, now I want to send data to the webservice, and it will only return "true or false".
I know I have the necessary data, but does not do what is supposed to do.
That is, the method I am invoking, it needs to receive data, and with these data it does the update in the database.
I know which works manually, directly on webservice.
what might be wrong?
Below is the code:
After insert the data on the app on android, when i click on a button, do this:
The message on the end, is the way that i know that i send real data:
try
{
newpassword = newPass;
Abreviatura = (EditText)findViewById(R.id.txtAbreviatura);
newabreviatura = Abreviatura.getText().toString();
Nome = (EditText)findViewById(R.id.txtNome);
newnome = Nome.getText().toString();
User = (EditText)findViewById(R.id.txtUsername);
newusername = User.getText().toString();
rslt="START";
Caller c=new Caller(); c.newNome = newnome;
c.newUser = newusername; c.newPass = newpassword;
c.newAbrev = newabreviatura; c.oldusername = oldusername;
c.ad=ad;
c.join(); c.start();
while(rslt=="START") {
try {
Thread.sleep(10);
}catch(Exception ex) {
}
}
ad.setTitle("Alteração:");
ad.setMessage(BIQActivity.comando + ";" + newnome + ";" + newpassword + ";" + newabreviatura + ";" + newusername + ";" + oldusername);
ad.show();
}catch(Exception ex)
{
}
That function, uses this peace of code, to send data to the next code:
csup=new CallSoapUpdatePerfil();
String resp=csup.CallUpdatePerfil(newUser, newNome, newPass, newAbrev, ldusername);
Perfil.rslt = resp;
Finally, this is the code that send's the data to the webservice:
public class CallSoapUpdatePerfil {
public final String SOAP_ACTION = "http://tempuri.org/UpdatePerfil";
public final String OPERATION_NAME = "UpdatePerfil";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://10.0.2.2:80/BIQAndroid/BIQAndroid.asmx";
public String CallUpdatePerfil(String User, String Pass, String Nome, String Abrev, String oldusername)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("User");
pi.setValue(User);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("Pass");
pi.setValue(Pass);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("Abrev");
pi.setValue(Abrev);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("Nome");
pi.setValue(Nome);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("oldusername");
pi.setValue(oldusername);
pi.setType(String.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
If anyone can help... Regards.
I already find the error. The error is about the name of parameter of webservice. :s
Done.
Thanks anyway.
Related
I can successfully create a PDF using iText and I am able to store in internal storage with getting file path.
On button click I have to call a service by passing 12 parameters and one of them is a stored PDF file path from the internal storage of the phone.
PROBLEM File not found error comes in server log even when while debugging through breakpoints on arg0 parameter.
How do I get the PDF file path to read it as a parameter value?
class Generatepdf extends AsyncTask<Void, Void, String> {
#Override
protected void onPreExecute() {
showDialog(CONNECTING_PROGRESS_DIALOG);
}
#Override
protected String doInBackground(Void... params) {
String outRes;
File myInternalFile;
HttpTransportSE androidTransport = null;
try {
final String NAMESPACE = "http://ws.xxxx.xxx.com/";
final String METHOD_NAME = "getPDF";
final String SOAP_ACTION = "";
final String WSDL_URL = "http://localhost:8080/services/getpdf?wsdl";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propOne = new PropertyInfo();
PropertyInfo propTwo = new PropertyInfo();
PropertyInfo propThree = new PropertyInfo();
PropertyInfo propFour = new PropertyInfo();
PropertyInfo propFive = new PropertyInfo();
PropertyInfo propSix = new PropertyInfo();
PropertyInfo propSeven = new PropertyInfo();
PropertyInfo propEight = new PropertyInfo();
PropertyInfo propNine = new PropertyInfo();
PropertyInfo propTen = new PropertyInfo();
PropertyInfo propEleven = new PropertyInfo();
PropertyInfo propTwelve = new PropertyInfo();
PropertyInfo propThirteen = new PropertyInfo();
//parameter one
File readpdfFile = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "/NewPDF_.pdf");
propOne.setName("arg0");
propOne.setValue(readpdfFile);
// propOne.setValue(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/NewPDF_");
// propOne.setValue(Environment.getExternalStorageDirectory().getPath() + "/PDF/NewPDF_.pdf");
request.addProperty(propOne);
//parameter two
propTwo.setName("arg1");
propTwo.setValue("xxxxxxxxxxxx (some 12 digit number)");
request.addProperty(propTwo);
//parameter three
propThree.setName("arg2");
propThree.setValue("ACuoAEB6ADmwAIAuADy4AIDCAEWkAIBwAFYwAIBbAFrAAIAqAF9UAIBnAGE8AEBZAGs8AEDmAGu4AIB3AG0wAIA2AHRQAEDFAHS0AIBEAIBMAIDjAIU0AEB6AIcwAIA4AIxYAICKAJCkAEBwAJ50AIBSAKhYAIBwAKoYAECBAKqMAICTAKykAICbALakAI");
request.addProperty(propThree);
//parameter four
propFour.setName("arg3");
propFour.setValue("name");
request.addProperty(propFour);
//parameter five
propFive.setName("arg4");
propFive.setValue("Test");
request.addProperty(propFive);
//parameter Six
propSix.setName("arg5");
propSix.setValue("cityname");
request.addProperty(propSix);
//parameter Seven
propSeven.setName("arg6");
propSeven.setValue("First");
request.addProperty(propSeven);
//parameter Eight
propEight.setName("arg7");
propEight.setValue("BottomRight");
request.addProperty(propEight);
//parameter Nine
propNine.setName("arg8");
propNine.setValue("null");
request.addProperty(propNine);
//parameter ten
propTen.setName("arg9");
propTen.setValue("Biometric");
request.addProperty(propTen);
//parameter Eleven
propEleven.setName("arg10");
propEleven.setValue("false");
request.addProperty(propEleven);
//parameter Twelve
propTwelve.setName("arg11");
propTwelve.setValue("device1341I089864");
request.addProperty(propTwelve);
//parameter Thirteen
propThirteen.setName("arg12");
propThirteen.setValue("true");
request.addProperty(propThirteen);
//soap method call
SoapSerializationEnvelope envelope2 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope2.setOutputSoapObject(request);
envelope2.implicitTypes = false;
androidTransport = new HttpTransportSE(WSDL_URL);
androidTransport.debug = true;
androidTransport.call(SOAP_ACTION, envelope2);
SoapObject response2 = (SoapObject) envelope2.bodyIn;
String requestDump = androidTransport.requestDump;
String responseDump = androidTransport.responseDump;
Log.i("", "Request: " + requestDump);
Log.i("", "Response: " + responseDump);
outRes = response2.toString();
Result= outRes;
Log.d("Result", Result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Result;
}
#Override
protected void onPostExecute(String response) {
removeDialog(CONNECTING_PROGRESS_DIALOG);
runOnUiThread(new Runnable() {
public void run() {
responseTxtView15.setText("RESPONSE " + Result);
}
});
}
}
I've been using SOAP based services in a lot of Android apps and they always work fine (string output usually). However, I've come across a service that accepts a DataSet and SQL Query as input and returns a DataSet as output.
From what I know of Android, there is no DataSet object type present. My question is, how do we utilize such a service in Android? Is it even possible to do so?
Here is a snapshot of the service:
Gladly for you, you can interface Android with ASP.NET so you can read the DataSET from your SOAP WebService
I'll give a snippet
public class CallSoap
{
public final String SOAP_ACTION = "http://tempuri.org/Add";
public final String OPERATION_NAME = "Add";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://yoururl/File.asmx";
public CallSoap()
{
}
public String Call(int a,int b)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("a");
pi.setValue(a);
pi.setType(Integer.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("b");
pi.setValue(b);
pi.setType(Integer.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
First SOAP_ACTION = namespace as seen in figure 1+function name;
OPERATION_NAME = name of the web method;
WSDL_TARGET_NAMESPACE = namespace of the webservice;
SOAP_ADDRESS = absolute URL of the webservice;
I call webservice from andriod application, developed using eclipse,
but getting exception when calling
androidHttpTransport.call(SOAP_ACTION, envelope);
ex.getMessage() printing "null" exception message
in manifist file i have specified
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
following is complete code
///////////////////
public class Yasir1Activity extends Activity {
TextView tv;
private final String NAMESPACE = "http://www.webserviceX.NET/";
private final String URL = "http://www.webservicex.net/ConvertWeight.asmx";
private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight";
private final String METHOD_NAME = "ConvertWeight";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.txt);
String msg="";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String weight = "3700";
String fromUnit = "Grams";
String toUnit = "Kilograms";
PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("Weight");
weightProp.setValue(weight);
weightProp.setType(double.class);
request.addProperty(weightProp);
PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("FromUnit");
fromProp.setValue(fromUnit);
fromProp.setType(String.class);
request.addProperty(fromProp);
PropertyInfo toProp =new PropertyInfo();
toProp.setName("ToUnit");
toProp.setValue(toUnit);
toProp.setType(String.class);
request.addProperty(toProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
msg="before call";
androidHttpTransport.call(SOAP_ACTION, envelope); //throwing exception
msg+="call success";
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
//Log.i("myApp", response.toString());
//TextView tv = new TextView(this);
msg+=response.toString();
tv.setText(response.toString());//weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
}
catch(SocketException ex)
{
msg+="Error on soapPrimitiveData() " + ex.getMessage();
ex.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
msg += "Exception " +e.getMessage(); //"Exception null" is printing
}
tv.setText( msg);
}
}
I had the same problem. I was getting a null exception because i was trying in the main thread. A problem with Honeycomb SDK or higher. http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
The solution, run the process in a new thread.
Greetings!
You should see this Double with ksoap2 on Android? to add Double property to your soap request in ksoap2.
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);
I can call a webservice with KSOAP2 from android,now i want to know is it possible to call it without using KSOAP.If anyone knows the answer please help me.
If the webservice is available with a rest api I would use Restlet. I have some blog posts that show simple examples of using this library here.
public class SOAPActivity extends Activity {
private final String NAMESPACE = "http://www.webserviceX.NET/";
private final String URL = "http://www.webservicex.net/ConvertWeight.asmx";
private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight";
private final String METHOD_NAME = "ConvertWeight";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject soapObject=new SoapObject(NAMESPACE, METHOD_NAME);
String weight = "700";
String fromUnit = "Kilograms";
String toUnit = "Grams";
PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("Weight");
weightProp.setValue(weight);
weightProp.setType(double.class);
soapObject.addProperty(weightProp);
PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("FromUnit");
fromProp.setValue(fromUnit);
fromProp.setType(String.class);
soapObject.addProperty(fromProp);
PropertyInfo toProp =new PropertyInfo();
toProp.setName("ToUnit");
toProp.setValue(toUnit);
toProp.setType(String.class);
soapObject.addProperty(toProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
TextView tv = new TextView(this);
tv.setText(weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
setContentView(tv);
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is simple code for SOAP web service,