locked
Function decorated with [WebGet] gives me error RRS feed

  • Question

  • I have done this walkthrough

     http://msdn.microsoft.com/en-us/library/cc668184(v=vs.100).aspx

    and it works 100%, but modified to work with my own database.

    On my local PC I use VS2013 version 3, C#, SQL Server 2008 R2, Entity Framework 5 .

    Problem arises when I try to extend the solution to call a stored procedure on the SQL Server.  The stored procedure does a complex read operation on tables.  For the stored procedure I have done Function Import and I see the stored procedure in Model browser under Function Imports. I have understood that I have to add a function decorated with WebGet in WCFDataService1.svc.cs:

    [WebGet]
            public IEnumerable<HoursEntities> Hours_Get_Pivot(DateTime TheDate, Int32 ActivityID)
            {
                return CurrentDataSource.Hours_Get_Pivot(TheDate, ActivityID)
                    .AsEnumerable();
            }
    

    I get the following error:

    'System.Collections.Generic.IEnumerable<WebApplicationWCF_07.Hours_Get_Pivot_Result>' to 'System.Collections.Generic.IEnumerable<WebApplicationWCF_07.HoursEntities>'. An explicit conversion exists (are you missing a cast?)    

    It seems like I must do a cast of all the output fields from the stored procedure?
    How can this be done?
           

    Regards


    Tore

    Thursday, September 4, 2014 5:18 PM

Answers

  • You are URI will be extended with the parameters like this:

    http://localhost/service.svc/storedprocedurename?variable1='dfas'&variable2='adfsad'


    kashif

    Friday, September 5, 2014 3:23 PM

All replies

  • Try specifying a response format with webget.  It accepts XML or JSON.

    http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute(v=vs.110).aspx


    kashif

    Thursday, September 4, 2014 9:52 PM
  • I need the answer in more detail. I am a novice on Visual Studio and C#. I try to read and understand everything on Interfaces, odata and WcfDataService 5.6 in particular. I need code examples.

    Regards


    Tore

    Friday, September 5, 2014 9:48 AM
  • [WebGet]
            public IEnumerable<Hours_Get_Pivot_Result> Hours_Get_Pivot (DateTime TheDate,int ActivityID)
            {
                return CurrentDataSource.Hours_Get_Pivot(TheDate, ActivityID)
                    .AsEnumerable();
            }

    I found out of this. The Method above gives no errors.

    It can be explained as follows:

    [WebGet]

    Public IEnumerable<StoredProcedure_Result> StoredProcedureName(Comma separated list of storedProcedure parameters with datatypes)

    {Return CurrentDataSource.StoredProcedureName(Comma separated list of storedProcedure Procedure parameters).AsEnumerable();

    }

    StoredProcedure_Result is automatically generated, It is found in Solution Explorer.

    StoredProcedureName spelled as the name is defined on SQL Server.

    Now I have to find out of the URI Syntax to Call a stored procedure With parameters, but I think I will find out of it without too much effort.

    Regards


    Tore

    Friday, September 5, 2014 12:31 PM
  • You are URI will be extended with the parameters like this:

    http://localhost/service.svc/storedprocedurename?variable1='dfas'&variable2='adfsad'


    kashif

    Friday, September 5, 2014 3:23 PM
  • Thanks, what I needed.

    Regards


    Tore

    Friday, September 5, 2014 6:14 PM