2017-03-02 6 views
0

Excelファイルを操作するカスタムSharepoint 2010サービスを開発しています。ローカルのワークステーションでVS2015を使用しています。Sharepoint 2010カスタムWCFサービスが400を返します - OpenXMLで「悪いリクエスト」

サービスは動作し、デバッグするだけでSPFileを取得し、プロパティを読み込んでストリームに変換します。しかし、SpreadsheetDocument.Open()を使用してSpreadsheetDocumentを作成するコードを追加するとすぐに、それはもはやデバッグされませんが、単純に400 "Bad Request"というレスポンスが返されます。

サービスコード

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を使って同じことを受けています

ご意見はありますか?

ありがとうございます。

答えて

0

この問題を解消しました。

追加のアセンブリとしてDocumentFormat.OpenXml.dllをSharepointパッケージに追加する必要がありました。

  1. オープン/Package/Package.package追加
  2. [詳細設定]タブ
  3. ソリューションエクスプローラから - >既存のアセンブリを追加
  4. は、Deploymentターゲット選択DocumentFormat.OpenXml.dll
  5. にソースパスを入力しました=グローバルアセンブリキャッシュ
  6. OK

と次のTE stは成功した。

関連する問題