调用workflow.asmx Web服务时出现SharePoint 404错误

时间:2015-03-20 16:34:04

标签: ajax web-services sharepoint workflow

使用以下代码我收到404(未找到)错误。我可以看到workflow.asmx URL是正确的,我可以通过浏览器访问它。我过去在其他项目中使用过类似的代码。

function StartExpenseReportToPdfWorkflow(itemId) {
    var targetUrl = "../_vti_bin/workflow.asmx";
    var listName = "Expense Reports";
    var itemUrl = getUrlForListItemId(listName, itemId);
    var soapEnv = [];
    soapEnv.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    soapEnv.push("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    soapEnv.push(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
    soapEnv.push(" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
    soapEnv.push("<soap:Body>");
    soapEnv.push("<StartWorkflow xmlns=\"http://schemas.microsoft.com/sharepoint/soap/workflow/\">");
    soapEnv.push("<item>" + itemUrl + "</item>");
    soapEnv.push("<templateId>" + expenseReportWorkflowTemplateId + "</templateId>");
    soapEnv.push("<workflowParameters><data>");
    soapEnv.push("</data></workflowParameters>");
    soapEnv.push("</StartWorkflow>");
    soapEnv.push("</soap:Body>");
    soapEnv.push("</soap:Envelope>");
    //get web service url:
    var spsdiscoUrl = $("head link[rel='alternate']:eq(0)").attr("href");
    var spWSUrlPrefix = spsdiscoUrl.substr(0, spsdiscoUrl.length - 13);
    $.ajax({
        cache: false,
        url: targetUrl, //spWSUrlPrefix + "workflow.asmx",
        beforeSend: function (xhr) {
            xhr.setRequestHeader("SOAPAction",
                "http://schemas.microsoft.com/sharepoint/soap/workflow/StartWorkflow");
        },
        type: "POST",
        dataType: "xml",
        data: soapEnv.join(""),
        complete: function (msg) {
            if (msg.status === 200) { } else {
                //Failure
                jsUtil.throwError("Well, this is awkward. Something went wrong and we're really sorry. " + msg.statusText, "Error calling Published Workflow: " + msg.statusText);
            }
        },
        contentType: "text/xml; charset=utf-8"
    });
}

function getUrlForListItemId(listName, itemId) {
    var domain = document.domain;
    var spsdiscoUrl = $("head link[rel='alternate']:eq(0)").attr("href");
    var webPrefix = spsdiscoUrl.substr(0, spsdiscoUrl.length - 22);
    return window.location.protocol + "//" + domain + webPrefix + "Lists/" + listName + "/" + itemId + "_.000";
}

1 个答案:

答案 0 :(得分:0)

问题是由错误的列表名称引起的。正确的名称是&#34; ExpenseReports&#34;没有空间。 401错误让我相信访问workflow.asmx Web服务本身存在问题。经过几个小时的检查和重新检查,我终于发现了错误。