WCF 传输安全:套接字连接已中止

2023-12-20

我在让交通安全工作方面遇到问题。

我有 2 个服务(A 和 B)在同一台服务器上运行。服务A将调用服务B来执行某些任务。没有任何安全保障,我也可以很好地沟通。但是当我使用以下设置打开传输安全性时:

  • 安全模式=传输
  • 传输 ClientCredentialType = Windows
  • 保护级别 = 加密并签名

当服务A调用服务B时出现错误:

System.ServiceModel.CommunicationException:套接字连接已中止。这可能是由于处理消息时出错、远程主机超过接收超时或底层网络资源问题造成的。本地套接字超时为“00:00:09.7810000”。 ---> System.IO.IOException: 读取操作失败,请参阅内部异常。 ---> System.ServiceModel.CommunicationException:套接字连接已中止。这可能是由于处理消息时出错、远程主机超过接收超时或底层网络资源问题造成的。本地套接字超时为“00:00:09.7810000”。 ---> System.Net.Sockets.SocketException:现有连接被远程主机强制关闭

我尝试将接收和发送超时更改为 5 分钟,但在大致相同的超时持续时间下仍然出现相同的错误。唯一的区别是我需要等待 5 分钟而不是 1 分钟。

任何人都可以深入了解原因是什么以及如何解决这个问题吗?

附件是这两个服务的配置文件:

ServiceA

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation targetFramework="4.5" debug="true" defaultLanguage="c#" />
  </system.web>
  <system.serviceModel>
    <protocolMapping>
      <remove scheme="net.tcp" />
      <add scheme="net.tcp" binding="netTcpBinding" bindingConfiguration="ReliableTCP" />
    </protocolMapping>
    <client/>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexTag">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="tryBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="mexTcp">
          <tcpTransport portSharingEnabled="true" />
        </binding>
      </customBinding>
      <netTcpBinding>
        <binding name="ReliableTCP" portSharingEnabled="true" sendTimeout="00:05:00" receiveTimeout="00:05:00" 
                 maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <reliableSession enabled="true" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="mexTag" name="Test.Service.ServiceAImpl">
        <endpoint address="net.tcp://app-svr:10010/ServiceA/ServiceAImpl/" behaviorConfiguration="tryBehavior"
          binding="netTcpBinding" bindingConfiguration="ReliableTCP" contract="Test.Service.IServiceA" />
        <endpoint address="net.tcp://app-svr:10012/ServiceA/ServiceAImpl/mex"
          binding="customBinding" bindingConfiguration="mexTcp" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

ServiceB

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation targetFramework="4.5" debug="true" defaultLanguage="c#" />
  </system.web>
  <system.serviceModel>
    <client>
      <endpoint address="net.tcp://app-svr:10010/ServiceA/ServiceAImpl/"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IServiceA"
        behaviorConfiguration="tryBehavior"
        contract="ServiceAReference.IServiceA" name="NetTcpBinding_IServiceA" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MEXGET" >
          <!-- Add the following element to your service behavior configuration. -->
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="tryBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="MexTcp">
          <tcpTransport portSharingEnabled="true" />
        </binding>
      </customBinding>
      <netTcpBinding>
        <binding name="ReliableTCP" portSharingEnabled="true">
          <reliableSession enabled="true" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
          </security>
        </binding>
        <binding name="NetTcpBinding_IServiceA" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <reliableSession enabled="true" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
          </security>
        </binding>
      </netTcpBinding>
      <mexTcpBinding>
        <binding name="MexTcp" />
      </mexTcpBinding>
    </bindings>
    <services>
      <service name="Test.Service.ServiceBImpl" behaviorConfiguration="MEXGET" >

        <endpoint address="mex"
                  binding="customBinding"
      bindingConfiguration="MexTcp"
                  contract="IMetadataExchange" />

        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
        <endpoint
             address="net.tcp://app-svr:10010/ServiceB/ServiceBImpl"
             binding="netTcpBinding" behaviorConfiguration="tryBehavior"
             bindingConfiguration="ReliableTCP"
             contract="Test.Service.ServiceB" />

        <host>
            <baseAddresses>
              <add baseAddress="http://app-svr:10011/ServiceB/ServiceBImpl" />
              <add baseAddress="net.tcp://app-svr:10010/ServiceB/ServiceBImpl" />
            </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

有一个解决方案here http://www.codeproject.com/Questions/633699/Socket-Exception-WCF...你应该试试...

  1. 在服务和客户端配置中添加了这些行为。

    <behaviors>
     <endpointBehaviors>
      <behavior name="endpointBehavior">
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
     </endpointBehaviors>
    </behaviors>
    
  2. 将客户端和服务器配置中的这些值更新为最大大小。

    <binding name="tcpBinding" receiveTimeout="00:15:00" sendTimeout="00:15:00"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
      <security mode="None">
        <transport clientCredentialType="None" protectionLevel="None" />
        <message clientCredentialType="None" />
      </security>
    </binding>
    

希望能帮助到你。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WCF 传输安全:套接字连接已中止 的相关文章

  • 异步调用的任务限制?

    我有一个同步工作的 NET 4 5 WCF 客户端 我正在更新它以使用新的异步 等待功能来进行多个同时服务器调用以同时获取数据块 在结束之前 我担心同时运行的所有线程将使服务器饱和 更不用说明年升级到该角色时会终止我的 Azure 辅助角色
  • IIS6 中托管的 WCF 服务在生产中收到 404

    我已经构建了一个简单的 WCF 服务并将其部署到 IIS6 我注意到它可以在我的开发和登台环境中运行 但不能在生产环境中运行 每次我尝试点击服务元数据链接时 都会收到 404 页面 我检查了我能想到的所有 IIS 配置 它们是相同的 所以我
  • “反序列化操作回复消息正文时出错...” - 对于我调用的每个方法

    我正在尝试为我们的波兰拍卖服务 Allegro 创建非常简单的客户端应用程序 他们提供 SOAP 架构中的 API 问题是 每次我尝试调用任何方法时 我都会收到 反序列化操作 方法名称 的回复消息正文时出错 一般来说 我对网络服务不熟悉 所
  • 需要 WCF 的完整 DI 示例

    有人有完整且有效的 WCF DI 示例吗 Every http www eggheadcafe com tutorials aspnet b428fb65 08b4 45c8 97cd 47ee1a1eaf41 composing wcf
  • 禁用“应用程序已停止工作”窗口

    我们获得了 NET WCF 服务 理想情况下该服务应具有 100 的正常运行时间 但有时我们的应用程序中会出现由第三方数据库连接组件引起的内存泄漏问题 我们配置 nnCron 来监视进程是否存在 并且当该服务的进程退出时 它应该再次启动它
  • WCF 错误:相对端点地址

    嗯 对 WCF 还很陌生 我想我有点搞砸了 这就是我到目前为止所做的 我在 IIS 中托管了我的 WCF 服务 首先是合同 using System using System Collections Generic using System
  • 我是否需要在 WCF DataContract 中公开构造函数才能使其在客户端上的对象实例化期间工作?

    我在 WCF 服务中有一个类 我们称之为A A是一个数据协定 其中包含另一个自定义对象的集合作为其数据成员之一B 为了避免客户端出现空引用问题 我实例化了BList在构造函数中像这样 DataContract public class A
  • WCF 包装代理客户端

    我的项目中有许多在客户端应用程序中使用的 Web 方法 我不想写这样的代码 using ServiceClient sc new ServiceClient Invoke service methods sc Method1 相反 我想写
  • 使用 wsHttpBinding 时,为什么 InstanceContextMode.PerSession 的行为类似于 PerCall?

    我有 AJAX 客户端使用 SOAP 1 2 使用的 WCF 服务 网页配置
  • ASP.NET Identity 2.0解密Owin cookie

    我正在应用多租户的服务器端应用程序中工作 在这个服务器端我有一个后台 ASP NET MVC 和后端 WCF 我想解密身份 cookie 以便我可以检查它是否有效并使用它在 WCF 服务中进行身份验证 更具体地说 我真的想知道 ASP NE
  • 如何唯一标识会话 0 中运行的 Internet Explorer 窗口?

    我正在创造WCF web services自动化internet explorer 有多个Web服务调用需要访问同一个实例Internet Explorer 然而 自从WCF服务托管于IIS所有对 Web 服务的调用都在会话 0 中执行 现
  • WCF 服务契约将被 XML 和 Json 序列化

    我如何创建要加入的服务合同XmlSerializer 格式也WebMessageFormat Json在 WCF RESTful 服务中 我需要的是从 ASP Net 1 1 的代码后面调用 CallADSWebMethod 操作契约 该契
  • 通过 WCF 提供类对象的数组或列表

    任何提供自定义类对象列表或数组的 WCF 客户端服务器示例都会对我有所帮助 但这是我到目前为止所得到的 这是我想提供的班级系统 namespace NEN Server FS Serializable public class XFS pr
  • 如何为WCF服务添加跨域支持

    我试图允许从托管在 localhost 80 的 javascript 应用程序向托管在不同端口的 WCF RStful 服务发出 POST 请求 但不知何故它不起作用 我尝试将自定义属性添加到标头 以及以编程方式将其添加到我的服务中JSO
  • WCF 服务中无法解释的程序集负载 (IIS 7)

    我正在开发一个新的 WCF Web 服务 该服务将托管在现有的 ASP NET Web 应用程序中 当我尝试运行服务的 svc 文件时 出现异常 无法找到程序集的文件 无法加载文件或程序集 System IdentityModel Vers
  • WCF 和 n 层架构以及序列化性能

    当使用 WCF 服务作为接口层使用 5 层架构 前端 gt 接口层 gt 业务层 gt 数据库层 gt 数据库 时 让客户端应用程序调用它的方法 我是否也应该使用 WCF 服务业务层和数据库层 我问是因为 3 个服务之间进行的所有序列化 反
  • 错误:在 Visual Studio 2013 中找不到类型或命名空间名称“ApplicationUser”

    我正在学习 RESTful WCF 服务 教程 但是当我构建我的应用程序时 我收到此错误 找不到类型或命名空间名称 ApplicationUser 您是否缺少 using 指令或程序集引用 c users basma documents v
  • WCF RIA 服务 - 加载多个实体

    我正在寻找一种模式来解决以下问题 我认为这很常见 我正在使用 WCF RIA 服务在初始加载时将多个实体返回给客户端 我希望两个实体异步加载 以免锁定 UI 并且我想利用 RIA 服务来执行此操作 我的解决方案如下 似乎有效 这种方法会遇到
  • WCF 中 SOAP 消息的数字签名

    我在 4 0 中有一个 WCF 服务 我需要向 SOAP 响应添加数字签名 我不太确定实际上应该如何完成 我相信响应应该类似于下面的链接中显示的内容 https spaces internet2 edu display ISWG Signe
  • 使用 HttpClient 调用 WCF 服务

    我必须调用 WCF 服务 WCF 服务已开启 我可以编辑其配置 我想创建一个调用该服务的客户端 我无法将服务引用添加到我的客户端 因此我尝试使用 HttpClient 调用它 客户端代码 using var client new HttpC

随机推荐