System.ServiceModel.CommunicationException:Silverlight应用程序通过excel服务读取excel数据

时间:2010-07-03 08:59:22

标签: excel sharepoint-2010

我创建了一个c#控制台项目来读取sharepoint服务器上的excel文档,一切正常。问题是当我尝试在silverlight应用程序中读取excel文件数据时,弹出如下异常:

{System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'http://phc/_vti_bin/excelservice.asmx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.
  at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
  at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
  at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
  --- End of inner exception stack trace ---
  at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
  at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
  at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
  --- End of inner exception stack trace ---
  at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
  at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
  at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
  at CERViewer.ESW.ExcelServiceSoapClient.ExcelServiceSoapClientChannel.EndOpenWorkbook(IAsyncResult result)
  at CERViewer.ESW.ExcelServiceSoapClient.CERViewer.ESW.ExcelServiceSoap.EndOpenWorkbook(IAsyncResult result)
  at CERViewer.ESW.ExcelServiceSoapClient.EndOpenWorkbook(IAsyncResult result, ObservableCollection`1& status)
  at CERViewer.ESW.ExcelServiceSoapClient.OnEndOpenWorkbook(IAsyncResult result)
  at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}

源代码:

private void GetFeatures()
    {
      ExcelServiceSoapClient = new ExcelServiceSoapClient();
      string targetWorkbookPath = "http://phc/Shared%20Documents/sample.xlsx";

      xlservice.OpenWorkbookCompleted += new EventHandler<OpenWorkbookCompletedEventArgs>(xlservice_OpenWorkbookCompleted);
      xlservice.OpenWorkbookAsync(targetWorkbookPath, "en-US", "en-US");
    }

    void xlservice_OpenWorkbookCompleted(object sender, OpenWorkbookCompletedEventArgs e)
    {
      sessionId = (string)e.Result; //exception here!!!
    }

我尝试了以下方法,但都失败了。

1:创建文件并将其放在“C:\ Program Files \ Common Files \ Microsoft Shared \ Web Server Extensions \ 14 \ isapi \”上,但它再次失败。

2:在sharepoint服务器中打开跨域工作簿和数据连接访问,此处

我对sharepoint和silverlight开发完全陌生,我在网上搜索但找不到答案。任何人都可以帮助我???

1 个答案:

答案 0 :(得分:0)

我通过将clientaccesspolicy.xml文件放在服务器根目录中来解决问题。