如何使用WSHttpBinding从android调用https wcf soap

时间:2014-01-07 08:47:32

标签: android wcf-binding android-ksoap2

有没有办法通过WSHttpBinding从Android调用HTTPS wcf ksoap?

使用http和basichttpbinding它工作正常,但我无法使用HTTPS和WSHttpBinding。

1 个答案:

答案 0 :(得分:0)

对于WSHttpBinding支持

KSoap将支持WSHttpBinding。使用Version12标记。

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

    soapEnvelope.implicitTypes = true;
    soapEnvelope.dotNet = true;
    soapEnvelope.headerOut = SoapUtils.buildHeader(url, soapAction);

将所需的标题添加到信封

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

支持Https

创建假证书并允许SSL。

Example