在将.net框架版本从3.5升级到4.0之后,如何在WCF中修复AddressAlreadyInUse异常? [英] How can I fix the AddressAlreadyInUse exception in WCF after upgrading the .net framework version from 3.5 to 4.0 ?

查看:139
本文介绍了在将.net框架版本从3.5升级到4.0之后,如何在WCF中修复AddressAlreadyInUse异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我最近升级了我的.net框架版本。

服务现在抛出AddressAlreadyInUse异常。之前它曾经工作得很好。

我在我的wcf中使用TCP绑定。

请帮忙。



提前致谢:)



问候,

Praneet

Hi,

I recently upgraded my .net framework version.
The service now throws AddressAlreadyInUse Exception. Earlier it used to work fine.
I am using TCP binding in my wcf.
Please help.

Thanks in advance :)

Regards,
Praneet

推荐答案





我解决了。



我从nettcpbinding中删除了listenBacklog和maxConnections属性。

现在工作正常。



问候,

Praneet
Hi,

I solved it.

I removed listenBacklog and maxConnections property from nettcpbinding.
It is now working fine.

Regards,
Praneet


Re问题1:



WCF NetTcpBinding使用共享内存部分向其客户端发布可以通过其调用服务的服务的实际名称。管道名称本身是一个GUID,每次打开服务主机时都会重新生成。它是用于发布依赖于服务URL的服务的共享内存部分的名称。如果定义了基址,则使用基址来获取此名称。



这意味着您一次只能运行一个WCF服务应用程序NetTcp端点的特定基址。如果你尝试启动第二个,它会因AddressAlreadyInUseException而失败,因为它发现WCF想要用于发布位置的名称(从基地址派生)已经被另一个应用程序占用了。



如果您没有指定基地址,并为每个服务提供绝对唯一的服务URL,那么发布位置的名称现在来自完整的绝对URL,并且之间没有名称冲突应用。这是一种完全有效且安全的方式来监听多个WCF服务。



问题2:



在服务端,您可以使用任何内容作为服务URL的主机名部分。这是由于NetTcpBinding中默认应用的HostNameComparisonMode设置,因为WCF中的算法(派生共享内存发布位置的名称)将通配符替换为主机名,请参阅此处以启用配置的主机名比较模式。



但是,在客户端,服务URL受到限制:主机部分必须真正解析为localhost(即它是localhost,正确的IP地址,或者正确的机器名称。)
Re problem 1:

The WCF NetTcpBinding uses a shared memory section to publish to its clients the actual name of the service over which the service can be called. The pipe name itself is a GUID, generated afresh each time the service host is opened. It is the name of the shared memory section used to publish the service which is dependant on the service URL. If a base address is defined, the base address is used to derive this name.

This means you can only ever have one WCF service application at a time running which uses a particular base address for its NetTcp endpoints. If you try to start a second one, it fails with AddressAlreadyInUseException because it finds that the name WCF wants to use for the publishing location (derived from the base address) has already been taken by another application.

If you specify no base address, and give each service an absolute, unique service URL, then the name of the publishing location is now derived from the full absolute URL, and there is no name clash between the applications. This is an entirely valid and safe way to have multiple WCF services listening.

Re problem 2:

On the service side you can use anything for the host name part of the service URL. This is due to the HostNameComparisonMode setting applied by default in the NetTcpBinding, since the algorithm in WCF which derives the name for the shared memory publishing location substitutes a wildcard character for the host name see here to enable the configured host name comparison mode to be implemented.

On the client side, however, the service URL is constrained: the host part must genuinely resolve to localhost (i.e. it is localhost, the correct IP address, or the correct machine name).


这篇关于在将.net框架版本从3.5升级到4.0之后,如何在WCF中修复AddressAlreadyInUse异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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