Клиент WCF не может подключиться к конечной точке NetTcpBinding - PullRequest
1 голос
/ 21 февраля 2012

У меня проблемы с подключением и запуском NetTcpBinding.Я смог получить привязку Http и привязку Named Pipe, однако Tcp доставляет мне много хлопот.До сих пор я пробовал много разных вещей, но ни одна из них не сработала.

Я прочитал, что проблема может заключаться в максимальном размере буфера для привязки клиента, и я поднял maxBufferPoolSize, maxBufferSize и maxReceivedMessageSize до их максимума.Это не имело никакого эффекта.Я читал, что проблема может быть в совместном использовании портов, поэтому я включил общий доступ к портам на моей машине, но это также не имело никакого эффекта.Я также отключил брандмауэр на машине, но это тоже ничего не изменило.

Точная ошибка, которую я получаю:

CommunicationException

Подключение через сокетбыл прерванЭто может быть вызвано ошибкой обработки вашего сообщения или превышением тайм-аута приема удаленным хостом, или проблемой основного сетевого ресурса.Тайм-аут локального сокета был '00: 00: 59.8127832 '.

Из того, что я прочитал, это своего рода общее исключение, когда WCF точно не знает, что пошло не так.

Я не знаю, что делать дальше.Я надеюсь, что вы можете помочь.

Вот конфигурация сервера

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="DummyServer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MetaDataBehavior">
                    <serviceMetadata/>
                    <serviceDebug />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="MetaDataBehavior" name="DummyServiceLibrary.DummyServiceA">
                <endpoint binding="basicHttpBinding"
                contract="DummyServiceLibrary.IDummyService" />
                <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
                <endpoint binding="netTcpBinding"
                contract="DummyServiceLibrary.IDummyService" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8080/dummy" />
                        <add baseAddress="net.tcp://localhost:8523/dummy" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
    <applicationSettings>
        <DummyServer.Properties.Settings>
            <setting name="ServiceType" serializeAs="String">
                <value>A</value>
            </setting>
        </DummyServer.Properties.Settings>
    </applicationSettings>
</configuration>

Вот конфигурация клиента

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="DummyClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IDummyService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
            <netTcpBinding>
                <binding name="NetTcpBinding_IDummyService" 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="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None" />
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8080/dummy" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IDummyService" contract="DummyService.IDummyService"
            name="BasicHttpBinding_IDummyService" />
            <endpoint address="net.tcp://localhost:8523/dummy" binding="netTcpBinding"
            bindingConfiguration="NetTcpBinding_IDummyService" contract="DummyService.IDummyService"
            name="NetTcpBinding_IDummyService" />
        </client>
    </system.serviceModel>
    <applicationSettings>
        <DummyClient.Properties.Settings>
            <setting name="ClientEndPoint" serializeAs="String">
                <value>NetTcpBinding_IDummyService</value>
            </setting>
        </DummyClient.Properties.Settings>
    </applicationSettings>
</configuration>

Надеюсь, вы сможете найти то, что мне не удалось.

Редактировать # 1 Мне удалось настроить и запустить конечную точку TCP, определив DNS.

Вот новое определение конечной точки сервера.

            <endpoint binding="netTcpBinding" contract="DummyServiceLibrary.IDummyService">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>

Вот новое определение привязки клиента и определение конечной точки клиента.

        <netTcpBinding>
            <binding name="NetTcpBinding_IDummyService" 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="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>


        <endpoint address="net.tcp://localhost:8523/dummy" binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_IDummyService" contract="DummyService.IDummyService"
        name="NetTcpBinding_IDummyService">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
...