简体   繁体   中英

MONO WCF Self-Hosted Service Pair getting Connection reset by peer when using net.tcp

I Have 2 WCF-Self-Hosted Aplications done with mono. One is on Windows 8 and the other is on Ubuntu Linux. When i put both applications under Windows8 or Ubuntu, they communicate fine. When i put them apart, one in windows and one in Linux, i get a "System.IO.IOException: Read Failure ---> System.Net.Sockets.SocketException: Connection reset by peer.

I've read every single page i could find about this error with no luck on how to fix it. i attack bellow the app.config of both apps. They communicate using net.TCP and the svcutil worked fine pulling the metadata.

CLIENT App.config (This one tries to pull data from the other, and when he collects the data, calls a 3rd Not-Implemented Yet service. )

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_IMiServicio" >
                <security mode="None"/>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://192.168.1.101:8090/ProyectoDistribuidoTCP"
                binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMiServicio"
                contract="IMiServicio" name="NetTcpBinding_IMiServicio">
                <identity>
                    <userPrincipalName value="ALEXMAINGEAR\Alex" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

SERVER App.config (this one serves the data to the second service)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="ProyectoDistribuido.MiServicio" behaviorConfiguration="metadataSupport">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8080/ProyectoDistribuidoHTTP"/>
                        <add baseAddress="net.tcp://localhost:8090/ProyectoDistribuidoTCP"/>
                    </baseAddresses>
                </host>
                <endpoint binding="basicHttpBinding" 
                          contract="ProyectoDistribuido.IMiServicio"/>
                <endpoint binding="netTcpBinding"
                          contract="ProyectoDistribuido.IMiServicio"/> 
                <endpoint   address= "tcpmex"
                            binding="mexTcpBinding"
                          contract="IMetadataExchange"/>  
            </service>
         </services>

         <bindings>
         <netTcpBinding>
            <binding name="netTcpBinding">
            <security mode= "None"/>
            </binding>
         </netTcpBinding>
         </bindings>

         <behaviors>
            <serviceBehaviors>
            <behavior name="metadataSupport">
            <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
            </behavior>
            </serviceBehaviors>
         </behaviors>
    </system.serviceModel>
</configuration>

I know this post is rather old, but I recently found myself in a similar situation and there is still very little information on this online.

In my case, the problem was that the net.tcp binding defaults to using Windows Authentication based security.

This is fine when both services are in windows, but when one is hosted in Linux it doesn't have access to this (unless you've configured it) and the connection fails.

The error message definitely leaves something to be desired!

Here's the config I used to disable security (as I don't need it yet) with net.tcp binding.

<system.serviceModel>
 <bindings>
  <netTcpBinding>
   <binding name="bindingConfig">
    <security mode="None">
     <transport clientCredentialType="None" protectionLevel="EncryptAndSign" />
     <message clientCredentialType="None" algorithmSuite="Default" />
    </security>
   </binding>
  </netTcpBinding>
 </bindings>
<!-- remainder of system.serviceModel -->

Note : You need to configure your service client to disable security as well. In my case, my client didn't have a .config file so I had to do it in code:

var binding = new NetTcpBinding()
{
    MaxBufferSize = int.MaxValue,
    ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max,
    MaxReceivedMessageSize = int.MaxValue,
    Security = new NetTcpSecurity()
    {
        Message = new MessageSecurityOverTcp()
        {
            ClientCredentialType = MessageCredentialType.None
        },
        Transport = new TcpTransportSecurity()
        {
            ClientCredentialType = TcpClientCredentialType.None
        },
        Mode = SecurityMode.None
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM