2012-08-25 20 views
7

Lần đầu tiên tôi thiết lập Dịch vụ OData và tôi tất nhiên có một số sự cố ...Yêu cầu lỗi với WCF Data Services

Vấn đề là tôi không thể chạy dịch vụ, tôi tiếp tục nhận được "Lỗi yêu cầu". Request Error

Tôi có researched về vấn đề có thể xảy ra và tôi thấy rằng một vấn đề phổ biến là các quy tắc truy cập được nhập sai. Vì vậy, tôi đã thử khắc phục điều này cả với tên Số ít, Tên số nhiều và tôi cũng đã thử với typeof(Post).getType().Name

Đây là mã của tôi. Tôi hy vọng bạn có thể giúp tôi, tôi đã bị mắc kẹt hàng giờ liền.

public class ODataService : DataService<Entity> 
{ 
    // This method is called only once to initialize service-wide policies. 
    public static void InitializeService(DataServiceConfiguration config) 
    { 
     //config.SetEntitySetAccessRule("Users", EntitySetRights.All); 
     //config.SetEntitySetAccessRule("Posts", EntitySetRights.All); 
     //config.SetEntitySetAccessRule("Albums", EntitySetRights.All); 


     config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); 
     config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead); 
     //config.SetServiceOperationAccessRule("GetPosts", ServiceOperationRights.AllRead); 

     config.UseVerboseErrors = true; 
     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; 
    } 

    [WebGet] 
    public IQueryable<Post> GetPosts() 
    { 
     return CurrentDataSource.Posts.AsQueryable(); 
    } 
} 

Cấu trúc của lớp EntityFramework tôi (db đầu tiên) The structure of my EntityFramework class (db first)

Phương pháp và thành viên cho lớp Entity. Ở đây các thực thể được viết bằng số nhiều. Methods and Members for Entity class

Đây là Web.config của tôi:

<?xml version="1.0"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 
<configuration> 
    <connectionStrings> 
    <add name="Entity" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&quot;data source=XXX;Initial Catalog=XXX;persist security info=True;user id=XXX;password=XXX;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime requestValidationMode="4.5" targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    <pages controlRenderingCompatibilityVersion="4.5" /> 
    <machineKey compatibilityMode="Framework45" /> 
    </system.web> 
<system.serviceModel> 
    <services> 
     <service name="LinkIT.Core.OData.ODataService" behaviorConfiguration ="DebugEnabled"> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors > 
     <behavior name="DebugEnabled"> 
      <serviceDebug includeExceptionDetailInFaults="True"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    </system.serviceModel> 
</configuration> 

Một thông báo lỗi chi tiết:

Máy chủ gặp lỗi khi xử lý yêu cầu. Thông báo ngoại lệ là 'Giá trị không được rỗng. Tên thông số: thuộc tínhResourceType '. Xem nhật ký máy chủ để biết thêm chi tiết. Trường hợp ngoại lệ stack trace là:

tại System.Data.Services.WebUtil.CheckArgumentNull [T] (T giá trị, String parameterName) tại System.Data.Services.Providers.ResourceProperty..ctor (String name, loại ResourcePropertyKind, resourceType propertyResourceType) tại System.Data.Services.Providers.ObjectContextServiceProvider.PopulateMemberMetadata (resourceType resourceType, IProviderMetadata workspace, IDictionary knownTypes, IDictionary 2 childTypes, IDictionary 2 entitySets) tại System.Data.Services.Providers.BaseServiceProvider .PopulateMetadata() tại System.Data.Servic es.Providers.BaseServiceProvider.LoadMetadata() tại System.Data.Services.DataService 1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider& metadataProviderInstance, IDataServiceQueryProvider& queryProviderInstance, BaseServiceProvider& builtInProvider, Object& dataSourceInstance) at System.Data.Services.DataService 1.CreateProvider() tại System.Data.Services.DataService 1.HandleRequest() at System.Data.Services.DataService 1.ProcessRequestForMessage (Stream messageBody) tại SyncInvokeProcessRequestForMessage (Object, Object [ ], Object []) tại System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke (Object dụ, Object [] đầu vào, Object [] & kết quả đầu ra) tại System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime .ProcessMessage11 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1 (MessageRpc & rpc) tại System.ServiceModel.Dispatcher.MessageRpc.Process (Boolean isOperationContextSet)

+3

Bạn có thể làm theo hướng dẫn tại đây để nhận thông báo lỗi chi tiết hơn không? http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx –

+0

@VitekKarasMSFT Cảm ơn bạn về mẹo – LazyTarget

+0

Là một trong các thuộc tính của bạn là Enum/Loại không gian? –

Trả lời

10

Nhóm dịch vụ dữ liệu WCF confirms - đây là lỗi chính xác gặp phải khi bạn sử dụng Enums (chưa được hỗ trợ).

Xóa các loại Enum (hoặc sử dụng công việc được đề xuất của họ và sử dụng trình bao quanh các thuộc tính enum) và điều này sẽ biến mất.