Click here to Skip to main content
15,885,900 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

C#
ReportingFacilityInterface = new ReportingFacility.ReportingFacilityInterface(); 

This starts up fine.


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


This instantiates the proxy object, which results in this getting called:
C#
<pre>reportingFacilityInterface = DuplexChannelFactory<IReportingFacilityInterface>.CreateChannel(objContext, "RPIEndPointConfiguration"); 

This seems to run and return successfuly.


3) WPFApp2 calls a on the object (through the proxy)
C#
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
Comments
db7uk 13-Apr-13 17:43pm    
Hi, How what is your endpoing config like and what is your service host and client config?
johnbMA 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..
========================================================================================


<configuration>

<appsettings>
<add key="ComponentName" value="Component1">


<system.web>

<compilation debug="true">


<!-- 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="SystemMonitoringService.SystemMonitoringService">
<endpoint name="MyServiceEndpoint"
="" address="net.tcp://localhost:9000/SystemMonitoringService" binding="netTcpBinding" bindingconfiguration="tcpBinding" contract="SystemMonitoringService.ISystemMonitoringService">

<host>
<baseAddresses>
<add baseaddress="net.tcp://localhost:9000/SystemMonitoringService">
</baseAddresses>
<timeouts closetimeout="00:10:00" opentimeout="00:10:00">



<service name="ReportingFacility.ReportingFacilityInterface">
<endpoint name="RPIServiceEndPoint"
="" address="net.tcp://localhost:8732/ReportingFacilityInterface" binding="netTcpBinding" bindingconfiguration="tcpReportingFacilityInterfaceBinding" contract="ReportingFacility.IReportingFacilityInterface">

<host>
<baseAddresses>
<add baseaddress="net.tcp://localhost:8732/ReportingFacilityInterface">
</baseAddresses>





<bindings>
<nettcpbinding>

<binding name="tcpBinding"
="" closetimeout="00:10:00" opentimeout="00:10:00" sendtimeout="00:02:00" receivetimeout="00:02:00" maxreceivedmessagesize="2147483647" maxbufferpoolsize="2147483647">
<readerquotas maxarraylength="99999999">
<reliablesession enabled="false" inactivitytimeout="24:00:00">
<security mode="None">


<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">





<client>

<endpoint address="net.tcp://localhost:9000/SystemMonitoringService"
="" binding="netTcpBinding" bindingconfiguration="tcpBinding" contract="SystemMonitoringService.ISystemMonitoringService" name="EndPointConfiguration">
johnbMA 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 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 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

1 solution

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[^]
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900