另一个“现有连接被远程主机强行关闭”问题

时间:2011-10-19 14:38:51

标签: wcf app-config nettcpbinding

我正在尝试访问公司网络上的WCF服务。我正在使用svcutil生成的代理和配置文件。代码如下所示:

using (Client client = new Client())
{
    client.Open();
    client.DoStuff();
}

客户端是生成的代理代码中的客户端类,这意味着它是从System.ServiceModel.ClientBase派生的,并实现了Contract接口。

配置文件如下所示:

<configuration>
    <system.serviceModel>
        <client>
            <endpoint address="net.tcp://Address"
                      binding="netTcpBinding"
                      bindingConfiguration="Config"
                      contract="Namespace.Contract"
                      name="name">
                <identity>
                    <servicePrincipalName value="Host" />
                </identity>
            </endpoint>
        </client>
        <bindings>
            <netTcpBinding>
                <binding name="Config"
                         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="524288"
                         maxBufferSize="65536"
                         maxConnections="10"
                         maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32"
                                  maxStringContentLength="8192"
                                  maxArrayLength="16384"
                                  maxBytesPerRead="4096"
                                  maxNameTableCharCount="16384" />
                    <reliableSession ordered="true"
                                     inactivityTimeout="00:10:00"
                                     enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="None" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
    </system.serviceModel>
</configuration>

每次代码到达client.Open()时,我都会收到“远程主机强行关闭现有连接”的异常。真正困扰的是,当我从另一台计算机上尝试它时,也不例外。最重要的是,配置文件曾经将传输安全性更改为“无”,并且其工作的计算机仍具有旧的配置文件

<security mode="Transport">
    <transport clientCredentialType="Windows"
               protectionLevel="EncryptAndSign" />
    <message clientCredentialType="Windows" />
</security>

而在第一台机器和服务器上它是

<security mode="None">
    <transport clientCredentialType="None" />
</security>

这会导致什么?我在这里读到了很多关于这个例外的问题,但似乎没有一个像我的问题。

解决了!我已将安全选项设置在错误的位置。 该服务由ServiceHost自托管,并且未设置Security属性,因此默认为None以外的其他内容。

1 个答案:

答案 0 :(得分:1)

在IIS上检查此项目的安全设置(您正在使用IIS吗?)。我认为它仍然说认证类型Windows。