0

Still finding my way with Castle.Windsor and the WcfFacility, but this ones got my head scratching. I'm want Windsor to inject the WCF client where it sees that dependency in my repository.

I've added a service reference in Visual Studio and added the following into my bootstrapping code:

  container.AddFacility<WcfFacility>();
    container.Register(
        Component.For<IServiceContract>()
        .AsWcfClient(
            DefaultClientModel.On(
                WcfEndpoint.FromConfiguration("MyEndpoint")
                )
            )
        );

My web.config contains a <client> section with a endpoint named accordingly:

<client>
  <endpoint address="http://localhost:63988/MyService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceContract"
    contract="IServiceContract"
    name="MyEndpoint" />
</client>

When I run my app, I get a YSOD:

Could not find endpoint element with name 'service' and contract 'IServiceContract' 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 name could be found in the client element.

Pretty self explanatory but why is it looking for an element with name "service", my element is named "MyEndpoint" which I've correctly passed to the FromConfiguration method?

If I update my web.config to change the name attribute from "MyEndpoint" to "service" - the YSOD is gone and my page works!

<client>
  <!-- Changing the name attribute to "service" works? -->
  <endpoint address="http://localhost:63988/MyService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceContract"
    contract="IServiceContract"
    name="service" />
</client>

It seems like the facility is ignoring the endpoint name I've given it?

Or (more likely) I'm not registering my service correctly and the facility is using some naming fallback.

EDIT

It seems that my endpoint name attribute has to be "service"! In every test I've tried I always get the same error if the attribute is any other value - is this a bug?

Cheers

Neil
  • 2,688
  • 1
  • 23
  • 32

1 Answers1

0

OK - I've managed to get past this problem.

I wrote a simple test harness of one MVC and one WCF and used the WcfFacility with no problems - this gave me the confidence that it does work ;o).

I was using an existing codebase and refactoring to use the WcfFacility so I binned my original changes and started again. This time round, I had no problems.

I suspect I must have missed some duplication in the web.config within the <system.serviceModel> elements - although I swear it was OK!

Cheers

Neil
  • 2,688
  • 1
  • 23
  • 32