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

Posted

技术标签:

【中文标题】System.ServiceModel.CommunicationException:Silverlight 应用程序通过 excel 服务读取 excel 数据【英文标题】:System.ServiceModel.CommunicationException: Silverlight application reading excel data by excel service 【发布时间】:2011-03-11 09:36:06 【问题描述】:

我创建了一个 c# 控制台项目来读取共享点服务器上的 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】:

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

【讨论】:

以上是关于System.ServiceModel.CommunicationException:Silverlight 应用程序通过 excel 服务读取 excel 数据的主要内容,如果未能解决你的问题,请参考以下文章