wcf System.ServiceModel.AddressAlreadyInUseException

时间:2009-01-22 12:51:47

标签: wcf httpcfg.exe

如果此问题在stackOverflow上出现两次,请道歉

我试图在Windows Server 2003框上运行wcf服务。当servicehost调用Open()时,我得到一个 System.ServiceModel.AddressAlreadyInUseException 异常,它告诉我以下错误:

  

HTTP无法注册URL http://+:8080/LogoResizer/mex/,因为另一个应用程序正在使用TCP端口8080

我已经读过我需要使用httpcfg.exe来注册我的命名空间,并且我使用了here找到的GUI工具来完成它,但我仍然得到了上述异常。运行“netstat -a”并不显示在端口8080上侦听的任何内容,并且运行“httpcfg.exe query urlacl”会返回以下注册名称空间。

  

C:\ Program Files \ Support Tools> httpcfg query urlacl       网址:http://+:80/Temporary_Listen_Addresses/

     

ACL:D:(A ;; GX ;;; WD)

URL : http://+:8080/LogoResizer/

ACL:D:(A ;; GX ;;; WD)

URL : http://+:8080/LogoResizer/mex/

ACL:D:(A ;; GX ;;; WD)

我的应用的配置如下:

<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="2147483647"
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647"
                              maxBytesPerRead="2147483647"
                              maxNameTableCharCount="2147483647" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>

        </netTcpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:900/mex/"/>
                    <add baseAddress="net.tcp://localhost:9000/" />
                </baseAddresses>
            </host>
            <endpoint bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
            <endpoint  address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
</system.serviceModel>

有没有人知道我做错了什么,或者我如何注册我的命名空间,以便为我的服务设置一个http端点?

1 个答案:

答案 0 :(得分:5)

完成了工作。

问题是我的两个端点都在同一个端口上运行。在Windows XP下进行开发时这不是一个问题,但是在尝试在Vista或Windows Server 2003下运行服务时会给你一些例外。我只需要将服务器配置更新为以下内容

   <baseAddresses>
                                    <add baseAddress="http://localhost:9000/mex/"/>
                                    <add baseAddress="net.tcp://localhost:9001/" />
                            </baseAddresses>