处理此请求 wcf 数据服务时出错



这是我的web.config代码。

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>
  <connectionStrings>
    <add name="SupplierProjectEntities" connectionString="metadata=res://*/SupplierDatabase.csdl|res://*/SupplierDatabase.ssdl|res://*/SupplierDatabase.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=127.0.0.1;User Id=root;password=sa_12345;database=supplier&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

这是我的 WCF 数据服务代码。

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace SupplierService
{
    public class SupplierProjectService : DataService<SupplierProjectEntities >
    {
        // 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.
            // Examples:
            config.UseVerboseErrors = true;
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }
    }
}

错误描述。当我运行此 wcf 数据服务时,我收到如下错误。

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="en-US">An error occurred while processing this request.</message>
<innererror>
<message>
Object reference not set to an instance of an object.
</message>
<type>System.NullReferenceException</type>
<stacktrace>
at MySql.Data.MySqlClient.MySqlClientFactory.get_MySqlDbProviderServicesInstance()
 at MySql.Data.MySqlClient.MySqlClientFactory.System.IServiceProvider.GetService(Type serviceType)
 at System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory factory)
 at System.Data.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action`3 addError)
 at System.Data.Metadata.Edm.StoreItemCollection.Loader.OnProviderManifestTokenNotification(String token, Action`3 addError)
 at System.Data.EntityModel.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader reader)
 at System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader)
 at System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader)
 at System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader reader)
 at System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader)
 at System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation)
 at System.Data.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation)
 at System.Data.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection)
 at System.Data.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths)
 at System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerManifestToken, Memoizer`2& cachedCTypeFunction)
 at System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths)
 at System.Data.Metadata.Edm.MetadataCache.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader)
 at System.Data.Metadata.Edm.MetadataCache.StoreItemCollectionLoader.LoadItemCollection(StoreMetadataEntry entry)
 at System.Data.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry)
 at System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken)
 at System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbProviderFactory factory, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader)
 at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
 at System.Data.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure)
 at System.Data.EntityClient.EntityConnection.Open()
 at System.Data.Objects.ObjectContext.EnsureConnection()
 at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
 at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
 at System.Data.Objects.ObjectQuery`1.GetEnumeratorInternal()
 at System.Data.Objects.ObjectQuery.System.Collections.IEnumerable.GetEnumerator()
 at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)
 at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService)
 at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)
 at System.Data.Services.DataService`1.HandleRequest()
</stacktrace>
</innererror>
</error>

错误解释。这个数据库是我第一次在sql server中制作的,当我为sql server制作wcf数据服务时,它工作正常,而且该数据库与mysql数据库相同。但是现在已经为mySQL数据库提供了WCF数据服务,然后我收到了此错误。如 above.so 所示,请帮助我解决此错误,解决此错误是很困难的。

我问这个问题是为了从mysql数据库中检索数据,它的版本是6.7.4.0

我可以得到问题的答案。

答案是我刚刚忘记添加Mysql.data.dllmysql.data.entity.dll引用文件夹中。因此,在引用文件夹中添加此DLL后,我可以解决上述错误所以你也可以试试。我希望这会有所帮助。

最新更新