user2117637
user2117637

Reputation: 91

Returning complex type in WCF data services getting request error while debugging

I have a method in my WCF data service where i want to return a complex type. I have created a seperate class for the complex type and selected new in the query. When i execute the program it throws a 'Request Error'.

Can you please help me on this.

[WebGet]
        public List<KeywordsForPKs> GetDomainObjForPKs()
        {
            var keys = from key in this.CurrentDataSource.DS_Keyword
                       select new KeywordsForPKs()
                       {
                           PK = key.pk,
                           AccountFK = key.accountFK,
                           ProjectFK = key.projectFK,
                           KeywordExpr = key.keywordExpr,
                           weight = key.weight,
                           IsNotBolded = key.isNotBolded,
                           IsAbstractKeyword = key.isAbstractKeyword,
                           IsBoldedInText = key.isBoldedInText,
                       };
            return keys.ToList();
        }

When i debug, i get Request error saying "The exception message is 'Unable to load metadata for return type 'System.Collections.Generic.List1[DataServices.KeywordsForPKs]' of method 'System.Collections.Generic.List1[DataServices.KeywordsForPKs] GetDomainObjForPKs()'.'. See server logs for more details. The exception stack trace is:

at System.Data.Services.Providers.BaseServiceProvider.AddServiceOperation(MethodInfo method, String protocolMethod) at System.Data.Services.Providers.BaseServiceProvider.AddOperationsFromType(Type type) at System.Data.Services.DataService1.CreateProvider() at System.Data.Services.DataService1.HandleRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)"

Upvotes: 0

Views: 813

Answers (1)

Jen S
Jen S

Reputation: 4555

Try changing the return type to be IEnumerable<KeywordsForPKs>. The documentation here implies that service operations that return collections must have a return type of IEnumerable<T> or IQueryable<T>.

Upvotes: 0

Related Questions