You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为SDK风格的.NET Framework 4.8项目添加Web Reference?

在SDK风格.NET Framework 4.8项目中添加Web Reference的方法

核心结论

SDK风格的.NET Framework 4.8项目完全支持添加Web Reference,只是Visual Studio默认隐藏了可视化添加选项,可通过命令行工具或手动编辑项目文件两种方式实现。

方法一:使用SvcUtil.exe生成Web服务代理

  1. 找到对应.NET Framework 4.8的SvcUtil工具路径,通常为:
    C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\SvcUtil.exe
    
  2. 打开命令提示符,运行以下命令请替换为你的SSRS服务实际WSDL地址,可根据服务器版本选择ReportService2005/2006/2010.asmx:
    SvcUtil.exe http://your-ssrs-server/ReportServer/ReportService2010.asmx?wsdl
    
  3. 命令执行后会生成代理类文件如ReportService2010.cs和配置文件output.config。
  4. 将生成的.cs文件添加到控制台项目中,把output.config内的绑定、端点配置复制到项目的app.config对应节点下。

方法二:手动编辑SDK风格项目文件(.csproj)

  1. 右键项目选择编辑项目文件,添加以下XML配置:
    <PropertyGroup>
      <!-- 可选:启用Web Reference文档生成 -->
      <GenerateWebReferenceDocumentation>true</GenerateWebReferenceDocumentation>
    </PropertyGroup>
    <ItemGroup>
      <WebReference Include="http://your-ssrs-server/ReportServer/ReportService2010.asmx?wsdl">
        <!-- 自定义代理类的命名空间 -->
        <Namespace>YourApp.ReportService</Namespace>
        <!-- 项目中显示的Web Reference名称 -->
        <Name>ReportService</Name>
      </WebReference>
    </ItemGroup>
    
  2. 替换配置中的服务URL、命名空间和引用名称,保存后重新加载项目。
  3. Visual Studio会自动生成Web服务代理类,可直接在代码中调用。

代码示例(获取SSRS报表名称)

生成代理后,可通过以下代码获取服务器上的报表列表:

using YourApp.ReportService;

var reportService = new ReportService2010SoapClient();
// 根据服务器身份验证方式调整,示例为Windows认证
reportService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

// 获取根目录下所有报表
var items = reportService.ListChildren("/", true);
foreach (var item in items.Where(i => i.TypeName == "Report"))
{
    Console.WriteLine($"报表名称:{item.Name},路径:{item.Path}");
}

内容的提问来源于stack exchange,提问作者Stephen York

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 20:48:22