Sharepoint 2010自定义WCF服务返回400 - 使用OpenXML返回“错误请求”
问题描述:
我正在开发自定义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
有什么想法?
感谢
答
想通了这个问题。
我需要将DocumentFormat.OpenXml.dll作为附加程序集添加到我的Sharepoint包中。
- 打开/Package/Package.package从解决方案浏览
- 高级选项卡
- 添加 - >添加现有组件
- 进入源路径DocumentFormat.OpenXml.dll
- 选定部署目标= GlobalAssemblyCache
- OK
而接下来德st成功了。