WCFDataService1 how to query in Windows Form RRS feed

  • Question

  • I have stored procedures in SQL Server that I want to call from a Windows Form. I  make use of Entity Framework with Function Import, WCFDatataService1, and I try ta make a client I a windows form with a datagrid to display the output of the stored procedure.

     private void button1_Click(object sender, EventArgs e)
                DataServiceContext context = new DataServiceContext(new Uri("http://localhost:24360/WcfDataService1.svc/"));
                List<Hours_Get_Pivot_Result> myList = context.Execute<Hours_Get_Pivot_Result>
                          (new Uri("http://localhost:24360/WcfDataService1.svc/Hours_Get_Pivot?TheDate=datetime'2014-07-27T00:00:00'&ActivityID=3")).ToList();

    The URI has been tested and it works 100% when it is called from a browser. I try to use the same URI in a windows form with a datagrid and a button. I get an exception on the last line of code:

    An unhandled exception of type 'System.Data.Services.Client.DataServiceClientException' occurred in Microsoft.Data.Services.Client.dll

    Additional information: Cannot materialize a collection of a primitives or complex without the type 'WindowsFormsApplication2.ServiceReference1.Hours_Get_Pivot_Result' being a collection.

    I try to learn this from the beginning and I am a bit lost. What can be wrong here?



    Thursday, September 11, 2014 10:49 AM

All replies

  • Maybe you should just use "var" and let .NET strong type it without you telling it that it is suppose to be a List<T>.


    var myList = context.Execute<Hours_Get_Pivot_Result> (new Uri("http://localhost:24360/WcfDataService1.svc/Hours_Get_Pivot?TheDate=datetime'2014-07-27T00:00000'&ActivityID=3")).ToList();

    You can use Quickwatch and inspect the object to find what kind of an object has been returned, like ait be  it being collection (List<T>) or something else.


    Thursday, September 11, 2014 1:29 PM
  • I get the same exception when I change to "var" as proposed. myList seems to be empty (null) when I get the exception, so I think the code fails to return any data at all.

    I have not written very much code in my windows client, only the two lines I have shown. I have made a serviceReference1 for the windows client and I have modified the client DataSources so that the result set from my SQL Server stored procedure (actually the result set from function import in entity model) is visible. I also included two extra namespaces in the windows form:

    using System.Data.Services.Client;

    using WindowsFormsApplication1.ServiceReference1;

    By the way, I run Visual Studio 2013.



    Friday, September 12, 2014 9:31 AM
  • It seems to me that you need to figure out what is happening on the WCF service-side by using a debugger on the solution, that's if you have the client and service code.

    Friday, September 12, 2014 4:09 PM