首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用来自web服务的SAPUI5和SOAP请求和响应

使用来自web服务的SAPUI5和SOAP请求和响应
EN

Stack Overflow用户
提问于 2018-06-07 00:57:01
回答 1查看 1.9K关注 0票数 0

我的问题是,我正在做一个重构项目,它是在flash中制作的,必须将其转换为SAUI5,为此,我使用了soap web服务。它包含web服务的多个部分。Ajax调用如下所示:

代码语言:javascript
复制
`var oAppSettings = sap.ui.getCore().getModel("appSettings").getData();
        var response;
        var oData;
        var oXMLModel = new sap.ui.model.xml.XMLModel();

        var sReq = "<soapenv:Envelope 
        xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" 
        xmlns:web=\"http://webservice.cpb.dqw.sap.com\">\n" +
            "   <soapenv:Header/>\n" +
            "   <soapenv:Body>\n" +
            "      <web:boeLogonWithToken>\n" +
            "         <!--Optional:-->\n" +
            "         <web:args0>"+oAppSettings.loginToken+"</web:args0>\n" 
            +
            "      </web:boeLogonWithToken>\n" +
            "   </soapenv:Body>\n" +
            "</soapenv:Envelope>";

        $.ajax({
            url: oAppSettings.serverPath + ".AdminHttpSoap11Endpoint/",
            method: "POST",
            dataType: "xml",
            data: sReq,
            //processData:false,
            contentType: "text/xml; charset=\"utf-8\"",
            success: function (data, textStatus, jqXHR) {
                response = data;
                console.log(response);
                console.log("Is a success!");
            },
            error: function (xhr, status) {
                console.log("Error: : " + status);
            },
            complete: function (xhr, status) {
                console.log(response);
                setUpData();
            }
        });

        function setUpData(){
            oXMLModel.setData(response);

            console.log(oXMLModel.getXML());
        }`

我得到的回应是:

代码语言:javascript
复制
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <ns:boeLogonWithTokenResponse 
         xmlns:ns="http://webservice.cpb.dqw.sap.com">
            <ns:return xmlns:ax22="http://shared.cpb.dqw.sap.com/xsd" 
             xmlns:ax21="http://types.cpb.dqw.sap.com/xsd" 
             xmlns:ax24="http://types.sdk.boe.dqw.sap.com/xsd" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:type="ax21:CPBAdminResult">
                <ax21:contentUpgradeVersion>0</ax21:contentUpgradeVersion>
                <ax21:cpInfo xsi:nil="true" />
                <ax21:errorData xsi:nil="true" />
                <ax21:intValue xsi:nil="true" />
                <ax21:projectInfo xsi:nil="true" />
                <ax21:reservedData xsi:nil="true" />
                <ax21:status>OK</ax21:status>
                <ax21:stringArray xsi:nil="true" />
                <ax21:stringValue xsi:nil="true" />
            </ns:return>
        </ns:boeLogonWithTokenResponse>
    </soapenv:Body>
</soapenv:Envelope>`

我想知道如何解析由SAPUI5的xml模型返回的xml。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-06-09 04:31:35

您的问题似乎想知道如何使用XMLModel (并且您应该等待答案;),因为它比最初看起来更简单,这意味着您不必转换为JSON。

使用中提供的XML创建一个XMLModel实例:

代码语言:javascript
复制
var oModel = new XMLModel();
oModel.loadData("response.xml");

导航到要转到的元素:

代码语言:javascript
复制
var path = "/soapenv:Body/ns:boeLogonWithTokenResponse/ns:return";
oModel.attachRequestCompleted(function(){
        var status = oModel.getProperty(path + "/ax21:status"); 
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50725741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档