Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET WCF IPC
Hi:
 
I am trying to use WCF to setup IPC between 2 running windows applications.
I want to start out by saying that I know there are other (better?) ways to implement
this solution. But, due to some pre-existing design considerations/constraints, I'm bound to using:
- netTcpBinding
- DuplexChannelFactory<> to support bidirectional communication
 
All the applications, services, etc reside on the same machine as we will be
installing everything on a single dedicated piece hardware running MS Windows.
 

So the schematic kind of looks like this
WPFApp1
(Contains ReportingFacilityInterface definition)
Returns notifications as separate callbacks to WPFApp2
^
|
|
V
ReportingFacilityInterfaceProxy
^
|
|
V
WPFApp2 (needs to call exposed methods on WPF1 ReportingFacilityInterface object)
 

I've created my WCF "service" class and contracts.
I'm using a proxy dll to facilitate the communication.
 

Here's the sequence of events:
-----------------------------
1)WPFApp1 starts up and instantiates an instance of the exposed service class
 
ReportingFacilityInterface = new ReportingFacility.ReportingFacilityInterface(); 
 
This starts up fine.
 

2) WPFApp2 startsup and initializes instance of proxy object
reportingFacilityProxy = new ReportingFacilityInterfaceProxy.ReportingFacilityProxy();


This instantiates the proxy object, which results in this getting called:
<pre>reportingFacilityInterface = DuplexChannelFactory<IReportingFacilityInterface>.CreateChannel(objContext, "RPIEndPointConfiguration"); 
This seems to run and return successfuly.
 

3) WPFApp2 calls a on the object (through the proxy)
 reportingFacilityInterface.Initialize(configuration); 
I get an exception with the following detail:
 
Could not connect to net.tcp://localhost:8732/ReportingFacility.
The connection attempt lasted for a time span of 00:00:02.1931255.
TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8732
 
I examined my current port usage using the CurrPorts application and noticed that port #8732 does is not in the list of currently active/used ports on my machine.
 

Since I'm pretty green @ the world of WCF, I'm kind of stumped here.
As I mentioned above, all these are running on the same (dedicated) piece of Windows 7 hardware, so permissions/roles should not be an issue.
I think I'm pretty close here, but am just missing something.
 
Thanks,
JohnB
Posted 13-Apr-13 11:31am
johnbMA503
Comments
db7uk at 13-Apr-13 17:43pm
   
Hi, How what is your endpoing config like and what is your service host and client config?
johnbMA at 13-Apr-13 18:14pm
   
Hey:
 
Thanks for getting back to me. I'm trying to nail this down
today if I can, so I appreciate your quick response.
 
This is where I'm getting a little confused. The folks who originally architected the system are using a proxy DLL to communicate between a Windows Service hosted service and clients applications.
 
I started out by trying to use their pattern of using a proxy dll.
I essentially am trying set up duplexchannel communication between 2 WPF applications.
(Client2 calls Client1's exposed calls to manipulate some things within Client1)
Do I need to be self hosting on a separate thread within my WPF app?
I just googled and found a sample of this online.
 
I feel like I missing some basic point here.
 
Thanks again for you feedback/responses.
 
Here is the config file I'm using (on both WPF hosting the service) and the client that will communicate with it..
========================================================================================

 

 



 

 


 
<!-- When deploying the service library project, the content of the config file must be added to the host's
 
app.config file. System.Configuration does not support config files for libraries. -->
 

 

 




<baseAddresses>

</baseAddresses>



 




<baseAddresses>

</baseAddresses>


 

 


 





 





 


 

 


 
johnbMA at 13-Apr-13 18:22pm
   
Final attempt to get you app.config file.
 
============================================
[?xml version="1.0" encoding="utf-8" ?]
 
[configuration]
 
[appSettings]
[add key="ComponentName" value="Component1" /]
[/appSettings]
 
[system.web]
 
[compilation debug="true" /]
[/system.web]
 
[!-- When deploying the service library project, the content of the config file must be added to the host's
 
app.config file. System.Configuration does not support config files for libraries. --]
 
[system.serviceModel]
 
[services]
 
[service name="ReportingFacility.ReportingFacilityInterface"]
[endpoint name="RPIServiceEndPoint"
address="net.tcp://localhost:8732/ReportingFacilityInterface"
binding="netTcpBinding"
bindingConfiguration="tcpReportingFacilityInterfaceBinding"
contract="ReportingFacility.IReportingFacilityInterface" ]
[/endpoint]
[host]
[baseAddresses]
[add baseAddress="net.tcp://localhost:8732/ReportingFacilityInterface" /]
[/baseAddresses]
[/host]
[/service]
 
[/services]
 
[bindings]
[netTcpBinding]
 
[binding name="tcpReportingFacilityInterfaceBinding"
closeTimeout="24:00:00" openTimeout="24:00:00"
sendTimeout="24:00:00" receiveTimeout="24:00:00"
maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"]
[readerQuotas maxArrayLength="99999999" /]
[reliableSession enabled="false" inactivityTimeout="24:00:00" /]
[security mode="None"][/security]
[/binding]
 
[/netTcpBinding]
[/bindings]
 
[client]
 
[endpoint address="net.tcp://localhost:8732/ReportingFacilityInterface"
binding="netTcpBinding"
bindingConfiguration="tcpReportingFacilityInterfaceBinding"
contract="ReportingFacility.IReportingFacilityInterface"
name="RPIEndPointConfiguration" ]
[/endpoint]
 
[/client]
[/system.serviceModel]
 
[startup]
[supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/]
[/startup]
 
[/configuration]
db7uk at 13-Apr-13 18:33pm
   
Ok, You can set two applications to talk to each other but there must be a service endpoint. i.e. one of your two applications could work as a service host and client. However you mentioned a windows service that is effectively the mediator between the two applications. Where is this service hosted? so in essence app 1 talks to app 2 via the service?
johnbMA at 13-Apr-13 19:16pm
   
In the pre-existing architecture, they have a WCF service that is hosted as a windows service. The service talks to a series of different apps and services. Communication with the clients takes place via a duplexfactorychannel and a proxy DLL.
 

I think you've started to answer my question.
I really don't have that service hosted anywhere.
So, what I guess I need to do is "self-host" the service with App1.
This will make an endpoint available for communication (ServiceHost()).
Then App2 will talk to the service via that endpoint.
 
Does the service need to be hosted on a separate thread?
(Is that the best design pattern here)?
 
Should I follow the model of using a separate proxy DLL to communicate with?
I do want to use a duplexfactorychannel as I'm going to have to support bidirectional communication.
 
As I mentioned before, I'm pretty green at WCF based stuff.
Your feedback is proving to be invaluable.
 
Thanks,
JohnB
db7uk at 13-Apr-13 19:43pm
   
Ok, it sounds like the proxy dll is just a means to generate the address bindings and facilitate the communications (aka proxy). This is fine and I have some similar. The main point is that nothing will communicate if there is no service present. what a duplex service does is act as a bridge, messenger, publish subscribe mechanism to marshal the messages to the clients. Basically You need to look into the publish subscribe pattern. An excellent example is: http://www.idesign.net/Downloads#InstanceManagement. Take a look at the Publish subscribe framework.
 
Basically, host your service (publisher) somewhere (app 1 or a dedicated service) and the have your apps subscribe to it. Each message that is set from a client or publisher will be sent to other clients who have subscribed to the events.
 
Other examples are:
 
http://msdn.microsoft.com/en-us/magazine/cc163537.aspx
http://www.squarewidget.com/poor-mans-publish-subscribe-wcf-service
johnbMA at 13-Apr-13 20:27pm
   
Has anyone told you today that you rock?
Well you do.
Thanks so much for the great info.
I've got a great jump on what I've got to do.
I'll let you know how it turns out.
 
Thanks again,
JohnB
db7uk at 14-Apr-13 8:28am
   
Thanks. I hope it has helped. I have added some of this as a solution. If it has helped could you mark as answered? Very much appreciated.
johnbMA at 18-Apr-13 0:45am
   
Hey db7uk:
 
This was pretty much spot on.
One last question.
 
Am I better off hosting the service in a separate thread in my WPF app host?
What are the benefits of using a separate thread or not?
 
Thanks,
JB
db7uk at 21-Apr-13 16:56pm
   
Hiya, sorry for the late reply. Hope all is well with you. The service should be hosted in a process that can accommodate multiple concurrent calls. There are many advantages to different hosting scenarios. To be honest, I would not rely on self hosting a service and then having another application talk to it. The main reason is that you cannot rely on the other party being available. Have you considered centralizing your communications to be more in-line with an SOA approach? i.e. You have a service hosted in IIS or windows that both applications (or any other applicaiton) can communicate freely with? By doing this you simplify the service endpoint as there is only one point of reference. What if your current setup needed to scale and you were required to have multiple applications all talking together? Multiple endpoints, who is an active subscriber or pulisher.... a nightmare for configuring.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Basically You need to look into the publish subscribe pattern. An excellent example is: http://www.idesign.net/Downloads#InstanceManagement. Take a look at the Publish subscribe framework.
 
Basically, host your service (publisher) somewhere (app 1 or a dedicated service) and the have your apps subscribe to it. Each message that is set from a client or publisher will be sent to other clients who have subscribed to the events.
 
Other examples are:
 
http://msdn.microsoft.com/en-us/magazine/cc163537.aspx
http://www.squarewidget.com/poor-mans-publish-subscribe-wcf-service
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 14 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100