how to call https wcf soap from android with WSHttpBinding

末鹿安然 提交于 2020-01-17 03:03:29

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/20967294/how-to-call-https-wcf-soap-from-android-with-wshttpbinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!