Reputation: 8363
I am fairly new to WCF so please bear with me if I'm not asking very clearly.
I have an environment where I have a group of computers (10 to 20) connected within a LAN. Each computer has a static IP, and comes with 2 applications: AppA and AppB.
AppA and AppB are designed to share information with each other, but I do not want the AppA to be paired up with AppB on the same computer. I need AppA to select a single computer from a list of computers in the LAN, then attempts to establish a connection to AppB running on the selected computer.
For example, I am running AppA on computer X, and from the list of computers, I have selected to connect to computer Y. AppA will connect to AppB that is running on computer Y (which is hosting a duplex WCF service).
On my AppB, I have already defined the service and callback interfaces.
I have a few questions here:
DuplexChannelFactory
, with the Endpoint
set to the endpoint of the selected computer.I tried out Tom Redfern's answer, and I am able to run the service on AppB, and AppA is able to connect to the service.
However, I have implemented it such that the service is started at runtime via code (self-host). AppA (client) also connects to the service at runtime using DuplexChannelFactory
, via code. It means that both AppA and AppB have no WCF content in App.config
at all.
This is how I host the service on AppB:
public static void HostService()
{
var baseAddress = new Uri(GetHostAddress());
Host = new ServiceHost(typeof(MyService), baseAddress);
NetTcpBinding netTCPBinding = new NetTcpBinding();
netTCPBinding.ReliableSession.Ordered = true;
Host.AddServiceEndpoint(typeof(IMyService), netTCPBinding, baseAddress);
Host.Open();
}
The HostService()
method is only called when user perform certain action in AppB. However, when the application launches, WcfSvcHost
window shows that there is an instance of MyService
, but it is at stopped state. The error detail says that:
The service cannot be started. This service has no endpoint defined. Please add at least one endpoint for the service in config file and try again.
I set a breakpoint on the line calling HostService()
, and WcfSvcHost
is already showing that message before I am calling HostService()
. It seems like there is something that is trying to start the service, other than the code I wrote.
Upvotes: 1
Views: 179
Reputation: 31760
How do I set up AppB such that its IP depends on the machine that it is running?
Use localhost as the base address for all AppB instances.
How do I set up AppA such that it can dynamically connect to the different AppB running on different IP addresses?
You have to move the client endpoint configuration into code. Then have some kind of runtime resolver to choose an appropriate service endpoint address based on some kind of lookup.
Upvotes: 1