Haguna
Haguna

Reputation: 101

WCF Data Services - stored procedure - StackOverflowException

I am trying to run an example in the MCTS 70-516 book, more specifically the example on page 470.

Requirements / what to create:

The following .svc file is then created:

using System.Data.Services;
using System.Linq;
using System.ServiceModel.Web;

namespace WcfDataServicesLibrary
{
    public class NorthwindService : DataService<NorthWindEntities>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*",EntitySetRights.All);
            config.SetServiceOperationAccessRule("*",ServiceOperationRights.All);
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        }

        [WebGet]
        public IQueryable<CustOrderHist_Result> CustOrderHist(string customerID)
        {
            using(NorthWindEntities db = new NorthWindEntities())
            {
                return CustOrderHist(customerID).ToList().AsQueryable();
            }
        }
    }
}

I then try to run it as indicated in the text:

"http://localhost:65363/NorthwindService.svc/CustOrderHist?customerID='ALFKI'"

I then get the error message StackOwerFlowException.

Why ?

I have tried the following:

No change. The same result.

I have a 32 bit machine (Windows Vista). So 64 bit is not an issue.

Any clues would be greatly appreciated.

Upvotes: 0

Views: 411

Answers (1)

i123fr3
i123fr3

Reputation: 286

There is recursion in the CustOrderHist method

Try the following:

    [WebGet]
    public IQueryable<CustOrderHist_Result> CustOrderHist(string customerID)
    {
        using(NorthWindEntities db = new NorthWindEntities())
        {
            return db.CustOrderHist(customerID).ToList().AsQueryable();
        }
    }

Upvotes: 1

Related Questions