如何使用SOAP webService(POST)WinJS VS2012

时间:2013-12-09 23:41:13

标签: web-services visual-studio-2012 microsoft-metro winjs soap-client

我在VS2012中开发了Metro Winapp,我需要使用SOAP POST类型的WebService,就像这是我到目前为止的代码,但是我无法使其工作:

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

我总是得到相同的结果(错误功能),如何让它工作

1 个答案:

答案 0 :(得分:1)

这可能有所帮助:

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

我想到这里:     var output = doc.getElementsByTagName(“uploadFileServiceReturn”);

带有结果的响应标记名称可能是uploadFileServiceReturn,但您可以将其替换为您的标记,测试并告诉我们