views:

121

answers:

0

I create a simple silverlight 4.0 application used to read the excel file data in the share point 2010 server. I try to use the "Excel Web Services" but I get an error here when calling the GetRangeA1 method:

An unhandled exception of type 'System.ServiceModel.Dispatcher.NetDispatcherFaultException' occurred in mscorlib.dll

Additional information: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/office/excel/server/webservices:GetRangeA1Response. The InnerException message was 'Error in line 1 position 361. Element 'http://schemas.microsoft.com/office/excel/server/webservices:anyType' contains data from a type that maps to the name 'http://schemas.microsoft.com/office/excel/server/webservices:ArrayOfAnyType'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'ArrayOfAnyType' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.

the source code is like:

namespace SampleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            ExcelServiceSoapClient xlservice = new ExcelServiceSoapClient();
            xlservice.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            Status[] outStatus;

            string targetWorkbookPath = "http://phc/Shared%20Documents/sample.xlsx";

            try
            {
                // Call open workbook, and point to the trusted location of the workbook to open.
                string sessionId = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);
                Console.WriteLine("sessionID : {0}", sessionId);

                //1. works fines.
                object res = xlservice.GetCellA1(sessionId, "CER by Feature", "B1", true, out outStatus); 

                //2. exception
                xlservice.GetRangeA1(sessionId, "CER by Feature", "H19:H21", true, out outStatus);

                // Close workbook. This also closes session.
                xlservice.CloseWorkbook(sessionId);
            }
            catch (SoapException e)
            {
                Console.WriteLine("SOAP Exception Message: {0}", e.Message);
            }

        }
    }
}

I am totally new to the silverlight and sharepoint developping, I search around but didn't get any luck, just found another post here, any one could help me?