0
我正在開發自定義Sharepoint 2010服務以處理Excel文件。我在本地工作站上使用VS2015。Sharepoint 2010自定義WCF服務返回400 - 使用OpenXML返回「錯誤請求」
服務工作和調試得到SPFile,讀取它的屬性並將其轉換爲流。但是,只要我包含使用SpreadsheetDocument.Open()創建SpreadsheetDocument的代碼,它甚至不會再進行調試,而是簡單地回退400「錯誤請求」的響應。
服務代碼
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.SharePoint;
using System;
using System.IO;
using System.ServiceModel.Activation;
namespace Lifeco.Corp.Sharepoint
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ExcelItemToSapService : IExcelItemToSapService
{
public ServiceResult SubmitSpreadsheet(string documentUrl)
{
// Ensure we have the neccessary information.
if (string.IsNullOrEmpty(documentUrl))
{
return new ServiceResult() { Status = "error", Message = "List item url is required as the 'documentUrl' parameter." };
}
SPFile doc = SPContext.Current.Web.GetFile(documentUrl);
if (doc == null || !doc.Exists)
{
return new ServiceResult() { Status = "error", Message = string.Format("Document item at '{0}' was not found.", documentUrl) };
}
using (Stream dataStream = doc.OpenBinaryStream())
{
// As is this works. Uncommenting the following 'using' block and I receive 400 - Bad Request without even getting to step into the code and debug.
//using (SpreadsheetDocument document = SpreadsheetDocument.Open(dataStream, false))
//{
// // work with spreadsheet...
//}
}
ServiceResult response = new ServiceResult() { Status = "success" };
response.Message = string.Format("Title: {0} | Version: {1} | Modified By: {2}", doc.Title, doc.UIVersionLabel, doc.ModifiedBy.Name);
return response;
}
}
}
.SVC
@ ServiceHost
Language="C#"
Debug="true"
Service="Lifeco.Corp.Sharepoint.ExcelItemToSapService, $SharePoint.Project.AssemblyFullName$"
CodeBehind="ExcelItemToSapService.svc.cs"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
錯誤接收到相同是否直接在瀏覽器中調用該服務或與SharePoint頁面
$.ajax({
type: "GET",
url: webServerRelativeUrl + '/_vti_bin/ExcelItemToSapService/ExcelItemToSapService.svc/SubmitSpreadsheet',
contentType: "application/json; charset=utf-8",
data: { "documentUrl": "http://s040997/Corporate/Insurance Risk Sample 2.xlsm" },
dataType: 'json',
success: function (data) {
//alert('Success\n' + JSON.stringify(data));
$resultEl.html('<pre>' + JSON.stringify(data) + '</pre>');
},
error: function (jqXHR, status, error) {
$resultEl.html('');
alert('Error\n' + jqXHR.responseText + '\nstatus: ' + status);
//alert('Error\n' + jqXHR.responseText + '\nheader: ' + jqXHR.getResponseHeader() + '\nerror: ' + error);
}
});
以下的jQuery
有什麼想法?
感謝