gpt4 book ai didi

linux - MONO WCF 自托管服务对在使用 net.tcp 时由对等方重置连接

转载 作者:可可西里 更新时间:2023-11-01 10:46:56 33 4
gpt4 key购买 nike

我有 2 个 WCF-Self-Hosted 应用程序用单声道完成。一个在 Windows 8 上,另一个在 Ubuntu Linux 上。当我将这两个应用程序放在 Windows8 或 Ubuntu 下时,它们可以正常通信。当我将它们分开时,一个在 Windows 中,一个在 Linux 中,我得到一个“System.IO.IOException: Read Failure ---> System.Net.Sockets.SocketException: Connection reset by peer.

我已经阅读了我能找到的关于这个错误的每一页,但没有找到解决方法。我攻击两个应用程序的 app.config。他们使用 net.TCP 进行通信,并且 svcutil 可以很好地提取元数据。

CLIENT App.config(这个人试图从另一个人那里拉取数据,当他收集数据时,调用第三个尚未实现的服务。)

<?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(这个为第二个服务提供数据)

<?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>

最佳答案

我知道这篇文章比较老,但我最近发现自己也遇到了类似的情况,网上关于这个的信息仍然很少。

在我的例子中,问题是 net.tcp 绑定(bind)默认使用基于 Windows 身份验证的安全性。

当两个服务都在 Windows 中时这很好,但是当一个服务托管在 Linux 中时它无法访问此服务(除非您已配置它)并且连接失败。

错误消息肯定有不足之处!

这是我用来通过 net.tcp 绑定(bind)禁用安全性(因为我还不需要它)的配置。

<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 -->

注意:您还需要将服务客户端配置为禁用安全性。就我而言,我的客户端没有 .config 文件,所以我必须用代码来完成:

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
}
};

关于linux - MONO WCF 自托管服务对在使用 net.tcp 时由对等方重置连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20457960/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com