0

I have the following WCF webservice

I want to consume it in android client.My code so far is

public class SOAP_TestActivity extends Activity {

  private final String NAMESPACE = "http://tempuri.org/";
  private final String URL = "http://50.19.226.15/Office365Admin/MsOnline.svc";
  private final String SOAP_ACTION = "http://tempuri.org/IMsOnline/ValidateUser";
  private final String METHOD_NAME = "ValidateUser";


  private final  String user_id= "khurram@office365trial.com.au";
  private final  String password= "friday@123";

  @Override
   public void onCreate(Bundle savedInstanceState)
      {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button signin = (Button) findViewById(R.id.regsubmitbtn);
        signin.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {

                        boolean auth=doLogin();
                        System.out.println(auth);
                        Toast.makeText(getApplicationContext(), String.valueOf(auth), Toast.LENGTH_SHORT).show();

                }
           });   
     }

    private boolean doLogin() {   

   boolean result=false;

   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

   request.addProperty("userid", user_id);
   request.addProperty("password",password);

   SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(SoapEnvelope.VER11);

   envelope.dotNet = true;         

   envelope.setOutputSoapObject(request);

   Log.d("myApp", request.toString());
   System.out.println(request);

   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
   androidHttpTransport.debug = true;

   try {
           androidHttpTransport.call(SOAP_ACTION, envelope);

           SoapPrimitive soapPrimitiveResults = (SoapPrimitive)envelope.getResponse();                        

           Log.d("myApp", soapPrimitiveResults.toString());
           System.out.println("myApp" +soapPrimitiveResults);

                   if(soapPrimitiveResults.toString().equalsIgnoreCase("true"))
       {
                   result = true;

       }

   }catch(SocketException ex)
   {
       Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
       ex.printStackTrace();
   }
   catch (Exception e) {
       Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
           e.printStackTrace();
   }
   return result;

   }
   }

This code works without any exception but I am not able to login into my application as the method ValidateUser always return false.This same webservice has been consumed in Windows Phone and is working without any problem.Also the username and password are 100% correct.

Looks like there is some problem in the NAMESPACE and SOAP_ACTION. I have gone through some tutorials and they say that the SOAP_ACTION is made by concatenating NAMESPACE with METHOD_NAME.So if I follow the tutorials my SOAP_ACTION should be

"http://tempuri.org/ValidateUser"

but the SOAP_ACTION given in the WSDL linkfor the method "ValidateUser" is

"http://tempuri.org/IMsOnline/ValidateUser".

I am new to WCF Webservices and SOAP.Can anybody please tell me how to implement the methods given in WSDL Document(link is at the top). Looks like missing something important but don't know what.

Waseem
  • 1,392
  • 5
  • 21
  • 30

2 Answers2

1

If the same web service works fine with windows phone, then you have a NameSpace problem, and the web service method is not getting the parameters from the SOAP message. And since your ValidateUser gets no parameters, it just returns null/false.

I had the same problem. I solved it by explicitly defining a namespace hence getting rid of the default namespace WCF sets, tempuri.org

Here is my solution for reference:

passing objects to wcf soap service from android using ksoap2; it sends and receives 0

Community
  • 1
  • 1
Ravi Chimmalgi
  • 175
  • 1
  • 12
0

Try this:

...

Object response = envelope.getResponse();
String value = response.toString();

...
Marcos
  • 4,643
  • 7
  • 33
  • 60