Do I need svc file to setup Castle Wcf Facility for non-HTTP services
Asked Answered
B

1

6

I am confused about the castle wcf facility registration.

I read some blog posts for BasicHttpBinding. But could not find a clear easy sample to setup a net.tcp setup.

I want to host the service from a console application...

I wrote something like this... can you see a problem here?

_container = new WindsorContainer();
_container.AddFacility<WcfFacility>();

_container.Register(Component.For<IMembershipService>().ImplementedBy<MembershipService>()
    .AsWcfService(
        new DefaultServiceModel()
            .AddEndpoints(WcfEndpoint
                    .BoundTo(new NetTcpBinding() { PortSharingEnabled = false })
                    .At("net.tcp://localhost/MembershipService")
            )
            .PublishMetadata()
    )
);
Bedford answered 3/11, 2011 at 21:8 Comment(0)
U
4

If you wish to publish metadata you will need to enable port sharing (to let the MEX endpoint share the same port as the regular TCP port - you'll get an AddressAlreadyInUse exception if you have this set to false) and you probably need to specify a port on your URL (not sure what port TCP would use otherwise), so your code should be (assuming port 8080 is OK for you):

_container.Register(Component.For<IMembershipService>().ImplementedBy<MembershipService>()
    .AsWcfService(
        new DefaultServiceModel()
            .AddEndpoints(WcfEndpoint
                    .BoundTo(new NetTcpBinding() { PortSharingEnabled = true})
                    .At("net.tcp://localhost:8080/MembershipService")
            )
            .PublishMetadata()
    )
);

This works fine using castle windsor 3.0.

Uncharitable answered 22/12, 2011 at 14:8 Comment(2)
Keep in mind the possiblity where a user is not allowed to use port sharing. I had this issue, I got a CommunicationException with the hint I could edit the allowAccounts section in the file SMSvcHost.exe.config to enable the user to do that. But this solution is not practicable cause the file is located in C:\Windows\Microsoft.NET\... My solution so far: Remove the Mex Endpoint/PublishMetadata(). I will publish the meta data with a second binding configuration, if needed in the future.Rhymester
Oh, and before I had the "Net.Tcp Port Sharing Service" disabled in my windows services. Your end user may have this disabled too and might be not allowed to enable it (and enabling it using an installer is not a pretty option)Rhymester

© 2022 - 2024 — McMap. All rights reserved.