本文介绍了EntityClassGenerator不为NorthwindDataSvc生成任何输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试使用EntityClassGenerator为NorthwindDataService生成代理。该服务位于: http://services.odata.org/Northwind/Northwind.svc/$metadata 没有生成输出.. 以下是我的代码: string odataProxyCode = string 。空; HttpWebRequest webRequest =( HttpWebRequest ) HttpWebRequest 。创建(@" http://services.odata.org/Northwind/Northwind.svc/$metadata"); =(代理!= null )?proxy: WebRequest 。DefaultWebProxy; 使用 ( WebResponse response = webRequest.GetResponse()) { 使用 ( XmlReader sourceReader = 新 XmlTextReade r (response.GetResponseStream())) { 使用 ( StringWriter targetWriter = 新 StringWri ter ()) { //生成OData终点代理。 EntityClassGenerator entityGenerator = new EntityClassGenerator ( LanguageOption 。GenerateCSharpCode); entityGenerator.OnPropertyGenerated + = new EventHandler < PropertyGeneratedEventArgs >(entityGenerator_OnPropertyGenerated); entityGenerator.OnTypeGenerated + = new EventHandler < TypeGeneratedEventArgs >(entityGenerator_OnTypeGenerated); IList < System.Data.Metadata.Edm。 EdmSchemaError > errors = entityGenerator.GenerateCode(sourceReader,targetWriter,namespacename); entityGenerator.OnTypeGenerated - = new EventHandler < TypeGeneratedEventArgs >(entityGenerator_OnTypeGenerated); entityGenerator.OnPropertyGenerated - = new EventHandler < PropertyGeneratedEventArgs >(entityGenerator_OnPropertyGenerated); odataProxyCode = targetWriter.ToString(); } } } 解决方案 Hello Venki, 欢迎来到EF论坛! EntityClassGenerator 用于根据.csdl文件生成上下文和实体类源代码, http://msdn.microsoft.com/en- us / library / bb399292.aspx 。 对于WCF数据服务元数据,EntityClassGenerator无法识别。 我们可以看到示例代码没有任何输出,但会产生一些错误(请检查错误变量)。 要生成WCF数据服务客户端代理类,请考虑使用DataSvcUtil.exe, http://msdn.microsoft.com/en-us/library/ee383989.aspx 。 美好的一天! 最诚挚的问候,b Lingzhi Sun MSDN Subscriber Support 如果您对我们的支持有任何反馈,请联系 [email protected] I am trying to use the EntityClassGenerator to generate the proxy for the NorthwindDataService. The service is available at :http://services.odata.org/Northwind/Northwind.svc/$metadataNo output is generated ..Following is my code: string odataProxyCode = string.Empty; HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(@"http://services.odata.org/Northwind/Northwind.svc/$metadata"); = (proxy != null) ? proxy : WebRequest.DefaultWebProxy; using (WebResponse response = webRequest.GetResponse()) { using (XmlReader sourceReader = newXmlTextReader(response.GetResponseStream())){ using (StringWriter targetWriter = newStringWriter()){ // Generate the OData End point proxy. EntityClassGenerator entityGenerator = newEntityClassGenerator(LanguageOption.GenerateCSharpCode);entityGenerator.OnPropertyGenerated += newEventHandler<PropertyGeneratedEventArgs>(entityGenerator_OnPropertyGenerated);entityGenerator.OnTypeGenerated += newEventHandler<TypeGeneratedEventArgs>(entityGenerator_OnTypeGenerated); IList<System.Data.Metadata.Edm.EdmSchemaError> errors = entityGenerator.GenerateCode(sourceReader, targetWriter, namespacename);entityGenerator.OnTypeGenerated -= newEventHandler<TypeGeneratedEventArgs>(entityGenerator_OnTypeGenerated);entityGenerator.OnPropertyGenerated -= newEventHandler<PropertyGeneratedEventArgs>(entityGenerator_OnPropertyGenerated);odataProxyCode = targetWriter.ToString();}}} 解决方案 Hello Venki, Welcome to EF forum! TheEntityClassGenerator is used to generate context and entity classes source codes based on .csdl files, http://msdn.microsoft.com/en-us/library/bb399292.aspx. For the WCF Data Service metadata, EntityClassGenerator cannot recognize. We can see the sample codes does not have any output, but it produces some errors (please check the errors variable). To generate WCF Data Services client proxy classes, please consider using DataSvcUtil.exe instead, http://msdn.microsoft.com/en-us/library/ee383989.aspx. Good day! Best Regards,Lingzhi SunMSDN Subscriber Supportin ForumIf you have any feedback on our support, please [email protected] 这篇关于EntityClassGenerator不为NorthwindDataSvc生成任何输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-21 09:36