开发者

Can I use a separate object to contain a Server Reference?

开发者 https://www.devze.com 2023-02-20 07:59 出处:网络
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

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 h开发者_如何学Cave 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.


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

<system.ServiceModel>
    <!--service reference config info-->
</system.ServiceModel>

portion of that app.config copied into your test app's app.config.

EDIT

More specifically, there's a section that looks like this:

<client>
    <endpoint address="some URI" binding="some binding type"
        contract="contract for your service name="name" />
</client>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消