我已經添加了一個名爲test.svc的WCF數據服務(v5.6)到我的MVC應用程序的根,但我似乎無法讓我的路由找出來,所以我可以訪問它。以下是我在瀏覽http:/test.svc以及路由代碼和test.svc文件時返回的結果。MVC無法訪問WCF數據服務
路由表條目(第一路線規則我添加):在瀏覽器中顯示
routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class test : DataService<MyEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
config.UseVerboseErrors = true;
}
錯誤:
服務器遇到錯誤處理請求。 消息的異常是' '的表達式'System.Data.Entity.Core.Objects.ObjectContext'不能用於 返回類型'System.Data.Objects.ObjectContext''。有關更多詳細信息,請參閱服務器日誌 。的異常堆棧跟蹤是:
在System.Linq.Expressions.Expression.ValidateLambdaArgs(類型 delegateType,表達&體,ReadOnlyCollection
1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable
1個參數)在 System.Linq.Expressions.Expression.Lambda [TDelegate](式體, 布爾尾調用,IEnumerable的1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, ParameterExpression[] parameters) at System.Data.Services.Providers.DbContextHelper.CreateDbContextAccessor(Type type) at System.Data.Services.Providers.DbContextHelper.GetDbContextAccessor(Type type) at System.Data.Services.Providers.DbContextHelper.IsDbContextType(Type type) at System.Data.Services.DataService
1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider & metadataProviderInstance,IDataServiceQueryProvider & queryProviderInstance,對象& dataSourceInstance,布爾& isInternallyCreatedProvider)在 系統在 System.Data.Services.DataService1.CreateProvider() at System.Data.Services.DataService
1.EnsureProviderAndConfigForRequest() 處SyncInvokeProcessRequestForMessage System.Data.Services.DataService1.HandleRequest() at System.Data.Services.DataService
1.ProcessRequestForMessage(流 消息體)(對象,對象[], 對象[]) .ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(對象 例如,對象[]輸入,對象[] &輸出)在 System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc & RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime .ProcessMessage5(MessageRpc & rpc )在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc & RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc & RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc & RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc & RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc & RPC)在 System.ServiceModel.D ispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc & RPC)處System.ServiceModel.Dispatcher.MessageRpc System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc & RPC)。流程(布爾 isOperationContextSet)