Search code examples
androidwcf-bindingandroid-ksoap2

how to call https wcf soap from android with WSHttpBinding


Is there any way to call HTTPS wcf ksoap from Android with WSHttpBinding?

With http and basichttpbinding it is working fine but I can't get it to work with HTTPS and WSHttpBinding.


Solution

  • For WSHttpBinding Support

    KSoap will support WSHttpBinding. Use Version12 tag.

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    
        soapEnvelope.implicitTypes = true;
        soapEnvelope.dotNet = true;
        soapEnvelope.headerOut = SoapUtils.buildHeader(url, soapAction);
    

    Add the required Headers to the Envelope

    private static final String HTTP_ADDRESSING_ANONYMOUS = "http://www.w3.org/2005/08/addressing/anonymous";
    private static final String HTTP_ADDRESSING = "http://www.w3.org/2005/08/addressing";
    private static final String ACTION = "Action";
    private static final String TO = "To";
    private static final String ADDRESS = "Address";
    private static final String REPLY_TO = "ReplyTo";
    private static final String MUST_UNDERSTAND = "mustUnderstand";
    
    
    private static Element[] buildHeader(String url, String soapAction) {
        List<Element> headers = new ArrayList<Element>();
        Element elementAction = new Element().createElement(HTTP_ADDRESSING, ACTION);
        elementAction.addChild(Node.TEXT, soapAction);
        elementAction.setAttribute(HTTP_ADDRESSING, MUST_UNDERSTAND, "1");
        headers.add(elementAction);
    
        Element elementTo = new Element().createElement(HTTP_ADDRESSING, TO);
        elementTo.addChild(Node.TEXT, url);
        elementTo.setAttribute(HTTP_ADDRESSING, MUST_UNDERSTAND, "1");
        headers.add(elementTo);
    
        Element elementReplyto = new Element().createElement(HTTP_ADDRESSING, REPLY_TO);
        Element address = new Element().createElement(HTTP_ADDRESSING, ADDRESS);
        elementReplyto.addChild(Node.ELEMENT, address);
        address.addChild(Node.TEXT, HTTP_ADDRESSING_ANONYMOUS);
        elementReplyto.setAttribute(HTTP_ADDRESSING, MUST_UNDERSTAND, "1");
        headers.add(elementReplyto);
    
        int size = headers.size();
        Element[] array = new Element[size];
        for (int i = 0; i < size; i++) {
            array[i] = headers.get(i);
        }
        return array;
    }       
    

    For Https Support

    Create a Fake Certificate and allow SSL.

    Example