我可以使用单独的对象来包含服务器引用吗?
我正在创建一个日志记录对象,它将接收发送给它的所有日志,并通过 WCF 和 MSMQ (netMsmqBinding) 将它们发送到我们的数据库。该日志记录对象具有对 LoggingHost 的服务引用(其中包含契约和所有必需的 WCF 内容)。
我有一个测试类,其中包含一个简单的 Web 表单,我在其中输入一条消息,并将其发送到此日志记录对象,然后发送到我们的数据库。我遇到的问题是,我能够让这个简单的功能正常工作的唯一方法是,如果这个测试类也有一个对同一个 LoggingHost 类的服务引用,这在某种程度上扼杀了这个日志记录对象的全部意义(我想要将所有 WCF 和 MSMQ 功能封装在此日志记录对象中,以便我只需点击 Logger.Debug("message"),它就会负责将消息发送到我们的数据库)。
任何想法都会很棒。如果我需要澄清我想要完成的任务,请告诉我。
编辑
抱歉,应该放置我使用测试页面向记录器发送消息时出现的错误。如果测试页没有服务引用,这就是我收到的错误。如果确实有参考,一切都会按预期进行。
Could not find default endpoint element that references contract 'ServerLogger.ILoggingService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I am creating a logging object that will take all logs sent to it and, via WCF and MSMQ (netMsmqBinding), send them over to our database. This logging object has a Service Reference to the LoggingHost (which contains the contract and all the obligatory WCF stuff).
I have a test class consisting of a simple web form that I enter a message into and it is sent to this logging object and then to our database. The problem I'm running into is that the only way I am able to get this simple functionality working is if this test class also has a Service Reference to the same LoggingHost class, which somewhat kills the entire point of this logging object (I want to encapsulate all WCF and MSMQ functionality inside this logging object so that I can just hit Logger.Debug("message") and it will take care of sending the message to our database).
Any ideas would be great. Let me know if I need to clarify what I'm trying to accomplish.
EDIT
Sorry, should have put the error that comes up when I use my test page to send the logger a message. If the test page does not have a Service Reference, this is the error I get. If it does have a reference, everything works as it should.
Could not find default endpoint element that references contract 'ServerLogger.ILoggingService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
日志记录对象的某些配置需要复制到测试应用程序的配置中。具体来说,在添加服务引用后,在日志记录对象的项目中,您现在应该有一个 app.config。您几乎需要
将该 app.config 的整个部分复制到测试应用程序的 app.config 中。
编辑
更具体地说,有一个部分如下所示:
它位于配置的 system.serviceModel 部分内。这是您收到的错误中引用的端点。此配置对于告诉您的客户端去哪里与服务交谈是必要的。
Some of the configuration for your logging object needs to be copied over to your test app's configuration. Specifically, within your logging object's project after adding the service reference you should have an app.config now. You pretty much need the entire
portion of that app.config copied into your test app's app.config.
EDIT
More specifically, there's a section that looks like this:
This is within the system.serviceModel section of the config. This is the endpoint that is referred to in the error you're receiving. This config is necessary to tell your client where to go to talk to the service.