【发布时间】:2026-02-18 14:15:02
【问题描述】:
我写了一个网络服务。我写了一个网站。我希望网站 BLL 代码调用网络服务。
我有一个包含此服务 URL 的配置表。我将 Web 服务 URL 注入到调用代码中。我应该使用哪个 C# 中的 Web 客户端或套接字来接收动态 Web 服务 URL?
我想用:
WebClient webClient = new WebClient();
UTF8Encoding response = new UTF8Encoding();
string originalStr = response.GetString(webClient.DownloadData(BLLConfig.Current);
但也许还有更优雅的方式?
我在运行时从数据库表加载配置。
这是我尝试在 Visual Studio 中使用 Web 引用的方式:
using (var client = new GetTemplateParamSoapClient("GetTemplateParamSoap"))
{
TemplateParamsKeyValue[] responsArray = client.GetTemplatesParamsPerId(CtId, tempalteIds.ToArray());
foreach (var pair in responsArray)
{
string value = FetchTemplateValue(pair.Key, pair.Value);
TemplateComponentsData.Add(pair.Key, value);
}
}
【问题讨论】:
-
当您说您从 db 表中加载配置时 - 您是指 Web 服务的不同 URL(然后查看我的答案并点击链接)还是不同的 WSDL(这些 Web 中的功能确实不同服务)?
-
@Yahia,只是网址。相同的 WSDL