0

这是我的 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 数据服务,然后我收到了这个错误。如上所示。所以请帮我解决这个错误,解决这个错误很重要。

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

4

2 回答 2

0

我可以得到我的问题的答案。

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

于 2013-11-14T12:27:25.207 回答
0

这将以等宽字体显示。前四个空格将被删除,但所有其他空格将被保留。

Markdown and HTML are turned off in code blocks:
<i>This is not italic</i>, and [this is not a link](http://example.com)

要创建不是块,而是内联代码跨度,请使用反引号:

字符$只是. window.jQuery如果你想在列表中有一个预先格式化的块,缩进八个空格:

  1. 这是正常的文字。
  2. 这也是如此,但现在遵循一个代码块:

    Skip a line and indent eight spaces.
    That's four spaces for the list
    and four to trigger the code block.`enter code here`123"
    
于 2015-08-20T01:30:07.470 回答