尝试使用WCF在两个应用程序之间进行通信时,为什么会出现异常(TCP错误代码10061)? [英] Why am I getting an exception (TCP error code 10061) when attempting to communicate between 2 applications using WCF?

查看:229
本文介绍了尝试使用WCF在两个应用程序之间进行通信时,为什么会出现异常(TCP错误代码10061)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨:



我正在尝试使用WCF在2个正在运行的Windows应用程序之间设置IPC。

我想从头开始说我知道还有其他(更好的?)方法来实现这个解决方案。但是,由于一些预先存在的设计考虑/约束,我必然会使用:

- netTcpBinding

- DuplexChannelFactory<>支持双向通信



所有的应用程序,服务等都在同一台机器上,因为我们将在一台专用机器上安装所有应用程序,服务等运行MS Windows的硬件。





所以原理图类似于这样

WPFApp1
(包含ReportingFacilityInterface定义)

将通知作为单独的回调返回WPFApp2

^

|

|

V

ReportingFacilityInterfaceProxy

^

|

|

V

WPFApp2(需要在WPF1 ReportingFacilityInterface对象上调用公开的方法)





我已经创建了我的WCF服务类和合同。

我正在使用代理dll来促进沟通。





以下是事件的顺序:

-----------------------------

1)WPFApp1启动并实例化公开服务类的实例



 ReportingFacilityInterface =  new  ReportingFacility.ReportingFacilityInterface(); 



这很好。





2)WPFApp2启动并初始化代理对象的实例

 reportingFacilityProxy =  new  ReportingFacilityInterfaceProxy.ReportingFacilityProxy(); 





这会实例化代理对象,从而导致调用此对象:

< pre> reportingFacilityInterface = DuplexChannelFactory< IReportingFacilityInterface> .CreateChannel(objContext,  RPIEndPointConfiguration); 



这似乎成功运行并返回。





3)WPFApp2在对象上调用a(通过代理)

 reportingFacilityInterface.Initialize(configuration); 



我得到一个例外,其中包含以下细节:



无法连接到网络。 TCP://本地主机:8732 / ReportingFacility。

连接尝试的持续时间为00:00:02.1931255。

TCP错误代码10061:无法建立连接,因为目标机器主动拒绝它127.0.0.1:8732



我检查了当前使用CurrPorts应用程序的端口使用情况,并注意到端口#8732不在我的机器上当前活动/使用的端口列表中。





因为我很漂亮@WCF的世界,我有点难过。

如上所述,所有这些都在同一(专用)Windows 7硬件上运行,所以权限/角色应该不是问题。

我想我离这里很近,但我只是遗漏了一些东西。



谢谢,

JohnB

解决方案

基本上您需要查看发布订阅模式。一个很好的例子是: http://www.idesign.net/Downloads#InstanceManagement [ ^ ]。看看发布订阅框架。



基本上,托管您的服务(发布者)某处(应用程序1或专用服务)并让您的应用程序订阅它。从客户端或发布者设置的每条消息都将发送给已订阅活动的其他客户。



其他示例包括:



http://msdn.microsoft.com/en-us/magazine /cc163537.aspx [ ^ ]

http://www.squarewidget.com/poor- mans-publish-subscribe-wcf-service [ ^ ]

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

解决方案

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[^]


这篇关于尝试使用WCF在两个应用程序之间进行通信时,为什么会出现异常(TCP错误代码10061)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆