0

I already have my app for android. So far I've been using KSOAP communication with a web service - standard asmx file. Everything works just fine, but for a month I've been trying to use a self hosted WCF service to deliver data for my app.

I did already all combinations with configurations of WCF but still something is going wrong.

Please guys, I need sample project of something as simple as a HelloWorld WCF service for KSOAP.With configured endpoints,space etc. I will really appreciate.

I've spent a many hours searching the web, but I can't build a working service from the information I've found.

This is first time that I have to ask for help... Best Regards from Poland

Kjartan
  • 18,591
  • 15
  • 71
  • 96

1 Answers1

0

I had same problem and solved in this way (WCF binding has to be basicHttpBinding, otherwise it doesn't work):

private static final String NAMESPACE = "http://tempuri.org/";
private static String URL="your url";

private static final String SOAP_ACTION_VALIDATION = "IValidateUser_wcf/ValidateUser";
private static final String VALIDATION_METHOD = "ValidateUser";

public boolean validateUser_WCF(String username, String password){

    SoapSerializationEnvelope envelope = null;
    SoapObject request = null;
    HttpTransportSE httpTransportSE = null;

    try {
        request = new SoapObject(NAMESPACE, VALIDATION_METHOD);
        request.addProperty("username", username);
        request.addProperty("password", password);

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

        //////////////////////////////                               
        // here you can add a HEADER element if you want
        Element[] header = new Element[1];  

        header[0] = new Element().createElement(NAMESPACE_INFOCAD, "a1");                
        header[0].addChild(Node.TEXT, "HeaderTextContent");

        envelope.headerOut = header;
        //////////////////////////////                               

        // second parameter is timeout:
        httpTransportSE = 
            new HttpTransportSE(URL+VALIDATION_URI, 10*10000); 
        httpTransportSE.debug = true;
        httpTransportSE.setXmlVersionTag(
           "<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        httpTransportSE.call(NAMESPACE+SOAP_ACTION_VALIDATION, envelope);

        // if response is a simple text result, you can call
        // SoapPrimitive, if not, you have to call SoapObject 
        // result and navigate in response's tree like an xml file
        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

        //To get the data.
        String textResult = result.toString();
        Log.i("textResult", textResult); 

        return true;

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }finally{
       // here you can see in LOG what is request you send and what is response received
        Log.i(getClass().getSimpleName(),"requestDump : "+httpTransportSE.requestDump);
        Log.i(getClass().getSimpleName(),"responseDump : "+httpTransportSE.responseDump);
    }

    return false;
}
Kjartan
  • 18,591
  • 15
  • 71
  • 96
kinghomer
  • 3,021
  • 2
  • 33
  • 56
  • Thank You for answer Kinghomer.My ksoap request looks pretty familiar, I think that bigger problem is with my WCF service, could You share with me C# WCF project to this ksoap example ? – Maciek PL Dec 12 '13 at 13:51
  • Which ksoap version are you using ? And WCF Binding ? – kinghomer Dec 12 '13 at 13:59
  • ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar – Maciek PL Dec 12 '13 at 17:36
  • ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar and HttpBinding, but I'am still doing something wrong in WCF. Like I wrote i don'd have problem with ksoap and asmx - i've got perfect working database app now, but i dont want to use IIS server and i'am trying rewrite asmx to self hosted WCF-without succes so far :( – Maciek PL Dec 12 '13 at 17:43
  • I have 3 different ways Attributs , which one is correct ? [WebInvoke(UriTemplate = "WelcomeUser", Method = "POST")] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml)] – Maciek PL Dec 13 '13 at 15:26
  • Take a look here: http://stackoverflow.com/questions/669764/how-to-consume-wcf-service-with-android – kinghomer Dec 16 '13 at 09:45