无法使用Nhibernate运行WCF服务 [英] Can not get WCF service running with Nhibernate

查看:54
本文介绍了无法使用Nhibernate运行WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大师们!
我试图理解我的问题,但是经过多次谷歌搜索之后,我仍然找不到解决方法.
我的问题是:
我使用WCF服务库模板创建一个项目.
添加对Nhibernate dll的引用.
使用Nhibernate将代码添加到代码中
并尝试添加以下代码
NHibernate.Cfg.Configuration配置=新的NHibernate.Cfg.Configuration();
ISessionFactory sessionFactory = config.BuildSessionFactory();
ISession会话= sessionFactory.OpenSession();

最后,我用错误
构建它 找不到类型或名称空间名称"NHibernate"(是否缺少using指令或程序集引用?)
以下是我的服务类别的代码

Hi Masters!
I try to understand my problem but finally after googling many times, i couldn''t find out the solution.
My problem is:
I create a project using WCF service library template.
Add reference to Nhibernate dll.
Add using Nhibernate to the code
and try to add the following code
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
ISessionFactory sessionFactory = config.BuildSessionFactory();
ISession session = sessionFactory.OpenSession();

Finally i build it with Error
The type or namespace name ''NHibernate'' could not be found (are you missing a using directive or an assembly reference?)
Below is the code of my service class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using NHibernate;
namespace WcfServiceLibrary1
{
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
        public class Service1 : IService1
        {
                public string GetData(int value)
                {
                        return string.Format("You entered: {0}", value);
                }
                public CompositeType GetDataUsingDataContract(CompositeType composite)
                {
                        if (composite == null)
                        {
                                throw new ArgumentNullException("composite");
                        }
                        if (composite.BoolValue)
                        {
                                composite.StringValue += "Suffix";
                        }
                        return composite;
                }

                public void GetDataFromNhibernate()
                {
                        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
                        ISessionFactory sessionFactory = config.BuildSessionFactory();
                        ISession session = sessionFactory.OpenSession();
                }
        }
}



我不知道为什么谁能帮我吗?
THanks



I don''t know why. Can anyone help me?
THanks

推荐答案

最可能的原因是,NHibernate.dll(您在项目中添加的)依赖于一些其他需要添加的dll.作为您项目中的参考.只要您不在项目中添加这些依赖的dll,就会继续显示"The type or namespace name ''NHibernate'' could not be found.."错误消息.
Most probable reason is, the NHibernate.dll (That you have added in your project) is dependent on some other dll(s) which you need to add as reference in your project. As long as you don''t add those dependent dlls in your project, the "The type or namespace name ''NHibernate'' could not be found.." error message will continue to be shown.


感谢您对我的问题的回答.
但是因为我已经与Nhibernate一起工作过很多次,所以我了解您的意思.在问之前我也是这样做的.
我还尝试使用 WCF服务应用程序模板(不是WCF服务库)创建一个项目,添加了Nhibernate.dll,当然还添加了其他一些dll,令人惊讶的是该项目运行良好.这让我很难理解,因此我试图找到它发生的原因,但是毫无用处.最后,我在这个网站上发布了我的问题,希望我能得到任何答复.
谢谢.
Thanks for your answer on my question.
But because i''ve worked with Nhibernate many times, so i understand what you did mean. I also did that before i asked.
I also tried to create a project using WCF Service application template (not WCF Service library), added Nhibernate.dll and of course some other dlls, it''s surprising that project just worked fine. It made me difficult to understand, so i tried and tried to find the reason why it happened, but uselessly. Finally i posted my question on this website, hoped i can get any responses.
Thanks.


这篇关于无法使用Nhibernate运行WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆