user1488378
user1488378

Reputation: 31

android KSoap fault exception passing parameter

public class Result extends Activity {  

   private final String NAMESPACE = "http://tempuri.org/";
   private final String URL = "http://10.101.21.18/MDSService/Service1.svc?wsdl";
   private final String SOAP_ACTION = "http://tempuri.org/IService1/GetAssmtDataByLoginIdAndPassword";
   private final String METHOD_NAME = "GetAssmtDataByLoginIdAndPassword";

   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
      SoapObject soapObject=new SoapObject(NAMESPACE, METHOD_NAME);
      Intent in = getIntent();
      soapObject.addProperty("loginName","ginnas");
      soapObject.addProperty("password","orcas");
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
     envelope.dotNet = true;
      envelope.setOutputSoapObject(soapObject);
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
      androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
   try {
       androidHttpTransport.call(SOAP_ACTION, envelope);
       System.out.println("call success");     
       SoapObject soapResponse = (SoapObject)envelope.getResponse();//throws the soap fault exception at this line
       Log.i("myApp", soapResponse.toString());

    } catch (org.xmlpull.v1.XmlPullParserException ex2) {
        System.out.println("EXCEPTION: " + ex2.getMessage());
    } catch (SoapFault e) {
        System.out.println("SOAPFAULT====");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("IOEXCEPTION====");
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

This code gives me the following exception:

SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'Query error occured : Procedure or function 'GetResidentAssmtDataByUser' expects parameter '@loginName', which was not supplied.' faultactor: 'null' detail: org.kxml2.kdom.Node@4053c030

Login name and password are correct.

What I have done so far:
Internet permission
envelop.dotNet=true/false
SoapPrimitive response = (SoapPrimitive)envelope.bodyIn;

But this will give the same exception. Please solve my problem.

Upvotes: 0

Views: 1506

Answers (2)

farrukh
farrukh

Reputation: 627

 public String Convert()
            {
            String result = null;
            try
                {

                    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                    request.addProperty("loginName","ginnas");
                    request.addProperty("password","orcas");

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                    envelope.dotNet = true;

                    envelope.setOutputSoapObject(request);

                    HttpTransportSE httpTransport = new HttpTransportSE(URL);

                    Object response = null;

                    try
                        {
                            httpTransport.call(SOAP_ACTION, envelope);
                            response = envelope.getResponse();
                            result = response.toString();
                        }
                    catch (Exception exception)
                        {
                            response = exception;
                            result = response.toString();
                        }
                }
            catch (Exception e)
                {
                    System.out.println("Server responce" + e.getMessage());
                }
            return result;
        }

or see this link

http://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/

Upvotes: 1

Sachin D
Sachin D

Reputation: 1376

You must check parameter name that you passes accept in webservice

soapObject.addProperty("loginName","ginnas"); soapObject.addProperty("password","orcas");

The parameter name must match with name given in webservice eg. In web service

GetAssmtDataByLoginIdAndPassword(String @loginName,String @password)//Method in Webservice

then you can pass the value as (In android)

soapObject.addProperty("@loginName","ginnas");
  soapObject.addProperty("@password","orcas");

and if you calling store procedure in webservice then

2) In webservice while passing the parameter to store procedure check the name of parameter

same as previous example.just check name of parameter.

If you seems it difficult or any other problem then you can write me.

Upvotes: 0

Related Questions