Pregunta

I have a Metro Winapp developed in VS2012 and I need to consume a WebService with SOAP POST type like this is the code I have so far but I can't make it work:

function webServTest() {

        var options = {
            url: "http://XXX.XXX.XX.XXX:XXXX/FILESERVERWS/services/FILESERVERWS?wsdl",
            type: "post",
            data:   '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.mycompany.com">' +
                    '   <soapenv:Header/>' +
                    '       <soapenv:Body>' +
                    '           <ws:uploadFileService>' +
                    '               <ws:filebytes>cid:1206873603250</ws:filebytes>' +
                    '               <ws:fpath>?</ws:fpath>'+
                    '               <ws:filename>?</ws:filename>' +
                    '           </ws:uploadFileService>' +
                    '       </soapenv:Body>' +
                    '</soapenv:Envelope>'

    };

    WinJS.xhr(options)
    .done(
        function (request) {
            var output = request.responseText;
            xhrDiv.innerHTML = window.toStaticHTML(output);

        },

        function errorfunction(result) {
            xhrDiv.innerHTML = result;
            xhrDiv.style.backgroundColor = "#FF0000";
        },

        function progress(result) {
            xhrDiv.innerText = "Ready state is " + result.readyState;
            xhrDiv.style.backgroundColor = "#0000FF";
        });
}

Always I get the same result (errorfunction), how to make it work

¿Fue útil?

Solución

this may help:

        xhrTest.onclick = function (e) {
            var time = new Date().getTime();
            var data =  '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.mycompany.com">' +
                        '   <soapenv:Header/>'  +
                        '       <soapenv:Body>' +
                        '           <ws:uploadFileService>' +
                        '           <ws:filebytes>cid:1206873603250</ws:filebytes>' +
                        '           <ws:fpath>?</ws:fpath>'+
                        '           <ws:filename>?</ws:filename>'+
                        '           </ws:uploadFileService>'+
                        '       </soapenv:Body>'+
                        '</soapenv:Envelope>';

            var options = {
                url: "http://XXX.XXX.XX.XXX:XXXX/FILESERVERWS/services/FILESERVERWS?wsdl",
                type: "post",
                headers: {
                    "Content-Type": "text/xml; charset=utf-8",
                    "SOAPAction": "uploadFileService"
                },
                data: data
            };

            WinJS.xhr(options)
                .done(
                function (request) {
                    var doc = request.responseXML.documentElement;
                    var output = doc.getElementsByTagName("uploadFileServiceReturn");

                    Windows.UI.Popups.MessageDialog(output[0].textContent, "the XML message").showAsync();
                    xhrDiv.style.backgroundColor = "#00A000";
                },
                function (error) {
                    Windows.UI.Popups.MessageDialog(error.status + " : " + error.statusText, "Status").showAsync();
                    xhrDiv.style.backgroundColor = "#FF0000";
                },
                function (progress) {
                    xhrDiv.innerText = "Ready state is " + progress.readyState;
                    xhrDiv.style.backgroundColor = "#0000A0";
                });
        };

I figured on here: var output = doc.getElementsByTagName("uploadFileServiceReturn");

the response tag name with results may be uploadFileServiceReturn, but you can replace it with your tag, test it and tell us

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top