SoapFault - faultcode: 'ns1:unexpected-error' android SOAP call - android

I am trying to call SOAP web service using one WSDL file.
I have added all required parameters in it.
But I am getting error as below:
SoapFault - faultcode: 'ns1:unexpected-error' faultstring: 'Fault occurred while processing.' faultactor: 'null' detail: null in android
Here is my code sample:
class RegisterMember extends AsyncTask<Void, Void, Void> {
String SOAP_ACTION = "";
String METHOD_NAME = "registerMember";
String NAMESPACE = "http://XXXXX.XX";
String URL="http://XXXX.XX?WSDL";
SoapPrimitive result1;
String str;
#Override
protected void onPreExecute() {
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setMessage("Checking For Activation");
mProgressDialog.show();
}
#Override
protected Void doInBackground(Void... params) {
try {
StringBuffer sb;
SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("name", "XXXX");
request.addProperty("email", "XXXX#gmail.com");
request.addProperty("username", "XXXXX");
request.addProperty("password", "XXXX");
request.addProperty("mobile", "XXXXXXX");
request.addProperty("pin", "XXXX");
request.addProperty("dob", "XX/XX/XXXX");
request.addProperty("gender", "male");
request.addProperty("address", "XXXXX");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
envelope.bodyOut = request;
Log.d("In try","In Try");
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(NAMESPACE+METHOD_NAME, envelope);
Log.d("In try","In Try1");
result1 = (SoapPrimitive)envelope.getResponse();
//SoapObject resultObj = (SoapObject)envelope.getResponse();
/*int numProp = resultObj.getPropertyCount();
sb = new StringBuffer();
for(int jj=0; jj<numProp; jj++) {
sb.append((String) resultObj.getProperty(jj) + "\n");
Log.d("For Loop", String.valueOf(sb.append((String) resultObj.getProperty(jj))));
}*/
Log.d("Envelope", String.valueOf(result1));
// str = envelope.getResponse();
// status= Boolean.valueOf(result1.toString());
// str = result1.toString();
Log.w("String Response of CheckActivation Status - - - - - - - - - -", str);
Log.w("CheckActivation Status - - - - - - - ->>>>>>>>>", String.valueOf(result1));
} catch (Exception e) {
Log.d("No Data Found",e +"");
}
try {
Thread.sleep(1000);
} catch(Exception ex) {
}
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Log.d("Response = = = = =",String.valueOf(result));
mProgressDialog.dismiss();
}
}
I doubt that the SOAPACTION might be causing issue. Is that possible if we have SOAPACtion blank and we call web service?
I have used same code for other web service, with .svc url, and works fine, so I dont think code should have any problem.
SOAP version:1.1
ksoap library version: ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar
Any help is appreciated.
Thanks

Try replacing result1 = (SoapPrimitive)envelope.getResponse();by
result1 = (SoapPrimitive)envelope.bodyIn();
and also set a SOAP_ACTION !
Also this is how you add a property to the request :
PropertyInfo pi = new PropertyInfo();
pi.name = NAME;
pi.type = String.class;
request.addProperty(pi, VALUE);

You need to check whether SOAP wsdl has which style, document or RPC.
both have different WSDL format, and it may possible, if you try to call WSDL with document type, might not give response with same code work for other one.
So please cross check this and confirm.
Regards

Related

SocketTimeoutException: connect timed out Android ksoap

I´m using ksoap to connect toa webservice but I have a problem when I try to get a value from my webservice.
I got this error exception java.net.SocketTimeoutException: connect timed out
I already check the timeout solution and it still doesn´t work
Also I've already made sure that my METHOD,NAMESPACE and URL are correct according to my WSDL file.
Do you have any other solution?
Here is my code:
class SegundoPlano extends AsyncTask {
#Override
protected Void doInBackground(Void... voids) {
logeo();
return null;
}
#Override
protected void onPostExecute(Void result) {
if (Re.compareTo("true") == 0) {
// try {
Intent I = new Intent(getApplicationContext(), Menu.class);
I.putExtra("folioen", Usuario);
startActivity(I);
// }
// catch (Exception ex)
//{
// Toast.makeText(MainActivity.this,ex.getMessage(), Toast.LENGTH_LONG);
// }
}
}
}
private String logeo() {
String mensaje;
String URL = "http://www.example.com/Servicios_web/WebService.asmx";
String metodo = "Acceso";
String namespace = "http://tempuri.org/";
String Accion = "http://tempuri.org/Access";
try {
SoapObject obtencion = new SoapObject(namespace, metodo);
obtencion.addProperty("usuario", User);
obtencion.addProperty("contra", Password);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(obtencion);
//HttpsTransportSE transporte = new KeepAliveHttpsTransportSE("192.168.4.38",440,"SERVIEPATH",7000);
HttpTransportSE transporte = new HttpTransportSE(URL, 100000);
transporte.call(Accion, soapEnvelope);
SoapPrimitive resultado = (SoapPrimitive) soapEnvelope.getResponse();
mensaje = resultado.toString();
Re = resultado.toString();
} catch (Exception ex) {
mensaje = ex.getMessage();
}
return mensaje;
}
Are you sure following is valid soap service URL?
String URL = "http://www.example.com/Servicios_web/WebService.asmx";
Do you have stack trace of where the call fails?

Getting error in Android using kSOAP2

Error I am getting is this
org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject
public final static String URL = "http://23.253.164.20:8096/login.asmx";
public static final String NAMESPACE = "http://23.253.164.20:8096";
public static final String SOAP_ACTION_PREFIX = "http://23.253.164.20:8096/getName";
private static final String METHOD = "getName";
private class AsyncTaskRunner extends AsyncTask<String, String, String> {
private String resp;
#Override
protected String doInBackground(String... params) {
publishProgress("Loading contents..."); // Calls onProgressUpdate()
try {
// SoapEnvelop.VER11 is SOAP Version 1.1 constant
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, METHOD);
//bodyOut is the body object to be sent out with this envelope
envelope.bodyOut = request;
HttpTransportSE transport = new HttpTransportSE(URL);
try {
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD, envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
//bodyIn is the body object received with this envelope
if (envelope.bodyIn != null) {
//getProperty() Returns a specific property at a certain index.
SoapPrimitive resultSOAP = (SoapPrimitive) ((SoapObject) envelope.bodyIn)
.getProperty(0);
resp=resultSOAP.toString();
}
} catch (Exception e) {
e.printStackTrace();
resp = e.getMessage();
}
return resp;
}
/**
*
* #see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
#Override
protected void onPostExecute(String result) {
// execution of result of Long time consuming operation
// In this example it is the return value from the web service
textView.setText(result);
}
Possibility checked
1) Internet permission given
2) Ksoap2 library imported
3) server side method is running (you can the URL)
4) Not running on the emulator instead on the mobile phone
You have some bugs in whole code.
there is no method "getName" - it looks like You meant "getGreetingForName" but i'm not sure becouse You have'nt provided param "stringName",
NAMESPACE = "http://23.253.164.20:8096/"; - add slash on the end,
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD, envelope);
that is not proper - becouse method called here is "http://23.253.164.20:8096http://23.253.164.20:8096/getNamegetName"
see also my answer to Your second posting - there is working code of login:
getting parameter error in ksoap 2 android
Regards,
Marcin

WSDL calling from Android causes NetworkOnMainThreadException

Here is this sample code (MainActivity):
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView)findViewById(R.id.text1);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Celsius", "32");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL);
try {
aht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
tv.setText("Status: " + resultString);
} catch (Exception e) {
tv.setText("Problem: " + e.toString());
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
...
When I run this code I got this message Problem: android.os.NetworkOnMainThreadException.
In the manifest.xml added the
<uses-permission android:name="android.permission.INTERNET" />
line.
Here
is the whole android project.
Does someone have any idea how to change this code?
Thank you in advance for any help you can provide.
This exception is thrown when an android application attempts to perform a network operation on its main thread. You must run your code in AsyncTask. Your code will look something like this
You can declare resultString as an instance variable
class SoapTask extends AsyncTask<String, Void, Void> {
private Exception exception;
#Override
protected Void doInBackground(Void... arg0) {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Celsius", "32");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL);
try {
aht.call(SOAP_ACTION, soapEnvelope);
resultString = "Status:" + (SoapPrimitive)soapEnvelope.getResponse();
} catch (Exception e) {
resultString = "Problem:" + e.toString();
}
}
protected void onPostExecute(Void result) {
tv.setText("Status: " + resultString);
}
}
Try this..
NetworkOnMainThreadException throws when you are performing network operation on its main thread.
So you have to run you network operations in AsyncTask
You can call AsyncTask like below
new SerializationConnection().execute(URL);
then SerializationConnection class
class SerializationConnection extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Celsius", "32");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(urls[0]);
aht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
return "Status: " + resultString;
} catch (Exception e) {
return "Problem: " + e.toString();
}
}
protected void onPostExecute(String result) {
tv.setText(result);
}
}
You are making a server call in main thread.if your target version is 9
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
For Better way try to use AsynTask

Webservice call return java.net.SocketTimeoutException: Transport endpoint is not connected

I'm trying to get the data from the ASMX web service. Ihave used the code from here and used its ConvertWaight web service but its not working.
Its showing me error java.net.SocketTimeoutException: Transport endpoint is not connected. Ihave added the network permission but still got this error.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Please help me with this any example code will be really helpful.
My web service accept the NSDictionary in the iOS. Like this...
{
memberDetails = {
DeviceName = "iPhone Simulator";
DeviceToken = 951fc5a77184ds1a17474256759a34e03d31b708a0358v742df38bb3cc845ds4;
EmailAddress = "user#org.com";
IsRemember = True;
Password = "123456789";
};
}
So in android i have tried to pass the HasMap to the webservice
here is the my web service if it help
POST /service/xxx.asmx HTTP/1.1
Host: www.xxx.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/SelectByEmailAndPassword"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SelectByEmailAndPassword xmlns="http://tempuri.org/">
<memberDetails>
<EmailAddress>string</EmailAddress>
<Password>string</Password>
<DeviceToken>string</DeviceToken>
<DeviceName>string</DeviceName>
<IsRemember>boolean</IsRemember>
</memberDetails>
</SelectByEmailAndPassword>
</soap:Body>
</soap:Envelope>
And Here is my code to call the web service
public String Call(String deviceName, String deviceToken, String emailAddress, String isRemember, String password)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
//Create a HashMap
Map <String,String> memberDetails = new HashMap<String,String>();
//Put data into the HashMap
memberDetails.put("DeviceName","android Simulator");
memberDetails.put("DeviceToken","951fc5a77184ds1a17474256759a34e03d31b708a0358v742df38bb3cc845ds4");
memberDetails.put("EmailAddress","user#org.com");
memberDetails.put("IsRemember","True");
memberDetails.put("Password","123456789");
pi.setName("memberDetails");
pi.setValue(memberDetails.toString());
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();
}
}
I check link. Than I create Testconnection project. All webservice call must be on the background thread. Could you create I thread and run your target in it?
private void getResult()
{
new Thread(){
public void run()
{
WebserviceCall com = new WebserviceCall();
// Initialize variables
final String weight = "18000";
String fromUnit = "Grams";
String toUnit = "Kilograms";
//Call Webservice class method and pass values and get response
final String aResponse = com.getConvertedWeight("ConvertWeight", weight, fromUnit, toUnit);
//Alert message to show webservice response
button.post(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(), weight+" Gram= "+aResponse+" Kilograms",
Toast.LENGTH_LONG).show();
}
});
Log.i("AndroidExampleOutput", "----"+aResponse);
}
}.start();
}
And than my web service class samely in link;
public class WebserviceCall {
String namespace = "http://www.webserviceX.NET/";
private String url = "http://www.webservicex.net/ConvertWeight.asmx";
String SOAP_ACTION;
SoapObject request = null, objMessages = null;
SoapSerializationEnvelope envelope;
AndroidHttpTransport androidHttpTransport;
WebserviceCall() {
}
/**
* Set Envelope
*/
protected void SetEnvelope() {
try {
// Creating SOAP envelope
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//You can comment that line if your web service is not .NET one.
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
androidHttpTransport = new AndroidHttpTransport(url);
androidHttpTransport.debug = true;
} catch (Exception e) {
System.out.println("Soap Exception---->>>" + e.toString());
}
}
// MethodName variable is define for which webservice function will call
public String getConvertedWeight(String MethodName, String weight,
String fromUnit, String toUnit)
{
try {
SOAP_ACTION = namespace + MethodName;
//Adding values to request object
request = new SoapObject(namespace, MethodName);
//Adding Double value to request object
PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("Weight");
weightProp.setValue(weight);
weightProp.setType(double.class);
request.addProperty(weightProp);
//Adding String value to request object
request.addProperty("FromUnit", "" + fromUnit);
request.addProperty("ToUnit", "" + toUnit);
SetEnvelope();
try {
//SOAP calling webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
//Got Webservice response
String result = envelope.getResponse().toString();
return result;
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
}
}

How I Can Send An Array to WebService Method

i need to send a multiple values to a webservice -asp.net- via android application
this is the webservice method
<WebMethod()> _
Public Function AddTheNums(ByVal nums() As String,) As String
For i = 0 To nums.Length - 1
--some process
Next
Return status
End Function
and i use this code to in android
public class Login extends AsyncTask<String, Void, String>
{
public Login(String MethodName)
{
}
public void onPreExecute()
{
}
#Override
protected String doInBackground(String... params)
{
final SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("nums", params[0]);
request.addProperty("nums", params[1]);
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
response = result.toString();
}
return response;
}
#Override
public void onPostExecute(String res)
{
}
}
can any one help me on this i need to send a multiple nums to the parameter in webserive
i used this code
request.addProperty("nums", params[0]);
request.addProperty("nums", params[1]);
but it doesnt work correctly ...
Best Regards
I'm not really sure that it's possible to use multiple params with same name in soapobject. Isn't it better to pass param like
request.addProperty("nums", params);
And I suppose this discussion can help https://groups.google.com/forum/#!topic/ksoap2-android/pq1V2ZXY3D8

Categories

Resources