偶尔的异常调用负载均衡的Web服务

如何解决偶尔的异常调用负载均衡的Web服务

| 我有一个在三个负载平衡的Web服务器上运行的Web服务,并且遇到了零星的错误。现在,我承认负载平衡部分可能有点像鲱鱼,但是当我仅使用1个Web服务器进行测试时,我无法重现该错误。如果我对所有三个Web服务器进行测试,都可以得到错误(但不是100%的时间,更可能是50%)。所有测试都是通过负载均衡器完成的,我们只是告诉负载均衡器我们要种植多少台服务器。 该代码是简单的单个请求代码。也就是说,没有状态。发出请求并返回响应。 Web服务代码是在IIS 7.5上运行的c#.NET 4。客户端代码既是网站又是桌面应用程序。 我得到两个例外之一:   System.ServiceModel.Security.MessageSecurityException:   不安全的或不正确的安全   从另一个接收到错误   派对。参见内部的FaultException   有关故障代码和详细信息。 ->   System.ServiceModel.FaultException:   安全上下文令牌已过期   或无效。消息不是   处理。 或者我得到:   System.ServiceModel.Security.SecurityNegotiationException:   安全通道无法打开   因为与   远程端点已失败。这可能   由于缺席或不正确   在指定的EndpointIdentity   EndpointAddress用于创建   渠道。请验证   指定或暗示的EndpointIdentity   通过EndpointAddress正确   标识远程端点。 ->   System.ServiceModel.FaultException:   安全令牌请求有   无效或格式错误的元素。 从您的.config文件的以下片段中可以看到,我没有使用安全性,因为它严格是内部Web服务。 (为了保护无辜者(即我),名字已更改)。 服务器端:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<configuration>
<!-- Service Side web.config -->
...
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled=\"true\" />
    <services>
      <service behaviorConfiguration=\"InternalUseOnly.InternalUseOnlyServiceBehavior\" name=\"InternalUseOnly.InternalUseOnlyService\">
        <endpoint address=\"\" bindingNamespace=\"http://somecompany.com/webservices\" binding=\"wsHttpBinding\" contract=\"InternalUseOnly.IInternalUseOnlyService\">
          <identity>
            <dns value=\"localhost\" />
          </identity>
        </endpoint>
        <endpoint address=\"mex\" binding=\"mexHttpBinding\" contract=\"IMetadataExchange\" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name=\"InternalUseOnly.InternalUseOnlyServiceBehavior\">
          <serviceMetadata httpGetEnabled=\"true\" />
          <serviceDebug includeExceptionDetailInFaults=\"true\" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
...
</configuration>
客户端
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!-- Client Side web.config -->
<configuration>
...
    <system.serviceModel>
      <bindings>
        <wsHttpBinding>
          <binding name=\"WSHttpBinding_IInternalUseOnlyService\" closeTimeout=\"00:01:00\" openTimeout=\"00:01:00\" receiveTimeout=\"00:10:00\" sendTimeout=\"00:01:00\" bypassProxyOnLocal=\"false\" transactionFlow=\"false\" hostNameComparisonMode=\"StrongWildcard\" maxBufferPoolSize=\"524288\" maxReceivedMessageSize=\"65536\" messageEncoding=\"Text\" textEncoding=\"utf-8\" useDefaultWebProxy=\"true\" allowCookies=\"false\">
            <readerQuotas maxDepth=\"32\" maxStringContentLength=\"8192\" maxArrayLength=\"16384\" maxBytesPerRead=\"4096\" maxNameTableCharCount=\"16384\" />
            <reliableSession ordered=\"true\" inactivityTimeout=\"00:10:00\" enabled=\"false\" />
            <security mode=\"Message\">
              <transport clientCredentialType=\"Windows\" proxyCredentialType=\"None\" realm=\"\" />
              <message clientCredentialType=\"Windows\" negotiateServiceCredential=\"true\" algorithmSuite=\"Default\" />
            </security>
          </binding>
        </wsHttpBinding>
      </bindings>
      <client>
        <endpoint address=\"http://intranet.somecompany.com/InternalUseOnly/InternalUseOnlyService.svc\" binding=\"wsHttpBinding\" bindingConfiguration=\"WSHttpBinding_IInternalUseOnlyService\" contract=\"InternalUseOnlyService.IInternalUseOnlyService\" name=\"WSHttpBinding_IInternalUseOnlyService\">
          <identity>
            <dns value=\"localhost\" />
          </identity>
        </endpoint>
      </client>
    </system.serviceModel>
...
</configuration>
有人在想吗? 附加信息:在查看了以下答案之后,我尝试了两件事,但都没有成功。 最明显的变化(起初我没有注意到)是更改了客户端上的一个属性以允许cookie
<system.serviceModel><bindings><wsHttpBinding><binding name=\"blah,blah,blah\" ... other properties... allowCookies=\"true\" />
。它默认为false。此外,我们的负载均衡器使用cookie来保持亲和力。但是,这并没有改变(不知道为什么)。 接下来,我尝试了客户端app.config文件中的各种安全选项。其中既包括ѭ3,又包括更详细的内容:
<security mode=\"None\">
    <transport clientCredentialType=\"None\" proxyCredentialType=\"None\" />
    <message clientCredentialType=\"None\" establishSecurityContext=\"false\" negotiateServiceCredential=\"false\"/>
</security>
尽管上一个设置只是我的猜测。我不对app.config进行任何服务器端更改,因为我不知道要更改什么,遗憾的是,由于我们只有1个开发Web服务器,而没有3个,因此只能进行生产测试。     

解决方法

        我将在这里走出去,猜测所涉及的安全性是在客户端指定的消息安全性:
<security mode=\"Message\">
    <transport clientCredentialType=\"Windows\" proxyCredentialType=\"None\" realm=\"\" />
    <message clientCredentialType=\"Windows\" negotiateServiceCredential=\"true\" algorithmSuite=\"Default\" />
</security>
如果要创建客户端并进行连接,则可能会缓存已协商的Windows凭据令牌。如果您未启用粘性会话,则令牌可能会传递回错误的服务器,并且将失败。我的猜测是它总是在第二次通话中?     ,        这是由于使用不带粘性会话的负载平衡器引起的NTLM问题。要更正此问题,您需要配置会话亲缘关系(粘性会话)。如果不这样做,则将失败,因为一部分NTLM握手发生在一个服务器上,而另一部分发生在另一台服务器上。     ,        尽管Chris和Jeff帮助我找到了答案,但实际上为我解决了这个问题的是我在Microsoft的Load Balancing Web Services上找到的这篇文章。简而言之,为解决此Web场问题,我们需要从默认的
wsHttpBinding
切换到
basicHttpBinding
。这并不困难,但全有还是全无。必须同时重新配置主要Web服务和每个客户端,否则它将损坏。 尽管
wsHttpBinding
确实具有可以设置为true的allowCooikes属性,但显然直到建立连接后才使用它们,此时请求可能会在第一个请求上跳转服务器,从而失败。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-