You need to enable JavaScript to run this app. 浏览器URL可访问WCF Service SSRS,但WCF客户端调用失败如何解决?
优惠活动
大模型
产品
解决方案
定价
更多

浏览器URL可访问WCF Service SSRS,但WCF客户端调用失败如何解决?

WCF调用SSRS NTLM验证失败解决方案

配置修复

现有basicHttpBinding安全配置同时启用了传输层NTLM验证和消息层用户名验证,SSRS的SOAP接口仅需要传输层验证,冗余配置会导致验证逻辑冲突,修改配置如下:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
          <binding name="ReportExecutionServiceSoap" receiveTimeout="10:00:00" sendTimeout="10:00:00" allowCookies="true" maxReceivedMessageSize="5242880" useDefaultWebProxy="false" bypassProxyOnLocal="true">
              <security mode="TransportCredentialOnly">
                  <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
                  <!-- 删除冗余的message节点配置 -->
              </security>
          </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://xyz:80/ReportServer/ReportExecution2005.asmx" 
        binding="basicHttpBinding" bindingConfiguration="ReportExecutionServiceSoap"
        contract="MyApplicationService.ReportExecutionServiceSoap" name="basicHttpEndpoint" />
    </client>
</system.serviceModel>

代码修复

1. 修复代理资源释放逻辑

现有代码catch块中已经调用Abort(),finally块无差别调用Close()会导致Faulted状态的代理再次抛出异常,是服务频繁进入Faulted状态、endpoint监视为null的直接原因,修改逻辑如下:

try
{
    // 原有业务逻辑不变
    webServiceProxy.ClientCredentials.Windows.AllowedImpersonationLevel =
                 System.Security.Principal.TokenImpersonationLevel.Impersonation;
    webServiceProxy.ClientCredentials.Windows.ClientCredential = clientCredentials;

    ServerInfoHeader serverInfoHeader;
    ExecutionInfo executionInfo;
    ExecutionHeader executionHeader = webServiceProxy.LoadReport(null, report, null, out serverInfoHeader, out executionInfo);

    webServiceProxy.SetExecutionParameters(executionHeader, null, parameters, null, out executionInfo);

    serverInfoHeader =
        webServiceProxy.Render(executionHeader, null, GetExportFormatString(format), null,
                               out output, out extension, out mimeType, out encoding, out warnings,
                               out streamIds);
}
catch (CommunicationException e)
{
    webServiceProxy.Abort();
    throw new CommunicationException(e.Message);
}
finally
{
    // 先判断代理状态再执行对应操作
    if (webServiceProxy.State == CommunicationState.Opened)
    {
        webServiceProxy.Close();
    }
    else if (webServiceProxy.State == CommunicationState.Faulted)
    {
        webServiceProxy.Abort();
    }
}

2. 补充NTLM验证域名参数

如果SSRS部署在域环境下,NetworkCredential必须传入域名参数,否则会走本地账户验证导致失败:

// 域环境第三个参数填域名,工作组环境填SSRS服务器的计算机名
new NetworkCredential("Username", "Password", "DOMAIN_NAME")

补充说明

WCFTestClient测试正常是因为工具自动生成的配置无冗余安全节点,且内部自带完善的代理生命周期管理逻辑,因此不会触发你代码中的问题。

内容的提问来源于stack exchange,提问作者Shanu Garg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.17 09:36:02