i’m looking to connect to a WCF service from w/in the same .exe from which it is hosted. I host the service in a WPF application as:
ServiceHost svc = new ServiceHost(typeof("Namespace.Service"));
svc.Open();
and config file of
<service name="Namespace.Service" >
<endpoint address="Contract/tcp"
binding="netTcpBinding"
contract="Namespace.IContract"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9002"/>
</baseAddresses>
</host>
</service>
This allows me to fire up a separate VS instance, create a console app and perform the following successfully:
IChannelFactory<IContract> facContract = new ChannelFactory<IContract>(new NetTcpBinding());
IContract contract = facContract.CreateChannel(new EndpointAddress("net.tcp://localhost:9002/Contract/tcp"));
string x = contract.GetProperty; //returns value I would expect
However if I amend my original WPF ServiceHost code to the following, a timeout exception is thrown when I access the service (NOTE: That if I do the same thing in the Console App Service host, I do not get the timeout…):
ServiceHost svc = new ServiceHost(typeof("Namespace.Service"));
svc.Open();
IChannelFactory<IContract> facContract = new ChannelFactory<IContract>(new NetTcpBinding());
IContract contract = facContract.CreateChannel(new EndpointAddress("net.tcp://localhost:9002/Contract/tcp"));
string x = contract.GetProperty; //<-!!WCF Timeout exception thrown..
WCF Tracing doesn’t provide add’l details (just confirms that a timeout exception is thrown). Any thoughts? {this isn’t a question about WCF Exception management best practices; I’m looking to access a service from within the service host & am blocked by this curious timeout exception}
EDIT:
This timeout occurs when the service host is a WPF application (perhaps others); but console app as a service host behaves as I would expect (e.g. can access a self-hosted service). I’ve updated the title and tags to reflect this new info…
Thanks in advance,
T
This was because WPF servicehost was hosting service on same thread as consuming service. Problem is defined here: http://social.msdn.microsoft.com/Forums/en/wcf/thread/74bc9d15-c458-4f1f-81a0-ebded46b68c4. Resolution is detailed here: http://msdn.microsoft.com/en-us/library/ms752260.aspx
Resolution was to start service host endpoint on a separate thread ala:
once host is opened on thread, then can consume service on main UI thread ala: