Skip to content Skip to sidebar Skip to footer

How To Consume Wcf .svc In Android

i red a lot of documents about, but i can't consume this .svc file. I've no problem with .ASMX file. Only SVC i'm not able to consume. It's very very very stressfull....! I can't m

Solution 1:

I solved by myself (WCF binding has to be basicHttpBinding, otherwise it doesn't work):

privatestaticfinalStringNAMESPACE="http://tempuri.org/";
privatestatic String URL="your url";

privatestaticfinalStringSOAP_ACTION_VALIDATION="IValidateUser_wcf/ValidateUser";
privatestaticfinalStringVALIDATION_METHOD="ValidateUser";

publicbooleanvalidateUser_WCF(String username, String password){

    SoapSerializationEnvelopeenvelope=null;
    SoapObjectrequest=null;
    HttpTransportSEhttpTransportSE=null;

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

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

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

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

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

        httpTransportSE = newHttpTransportSE(URL+VALIDATION_URI, 10*10000); // second parameter is timeout
        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 fileSoapPrimitiveresult= (SoapPrimitive)envelope.getResponse();

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

        returntrue;

    } 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);
    }

    returnfalse;
}

Solution 2:

Do you have control over WCF part?

The easiest way will be to update WCF bingding. Currently it is WSHttpBinding, That binding is way more complicated than *.asmx.

Check if it is possible to publish endpoint with basicHttpBinding binding.

http://msdn.microsoft.com/en-us/library/ms731361.aspx

That binding is compatible with *.asmx and you only will need to update URL in your java code to consume it.

Post a Comment for "How To Consume Wcf .svc In Android"