wcf - 如何使用代理访问 .net core 中的 wcf 服务
问题描述
我在我的代码(.net core 2.1)中添加了一个 wcf 服务,但是我不能直接访问这个服务,我需要使用代理来做到这一点,我不知道如何在我的代码中设置代理。当我添加 wcf 服务时,vs 会生成一个像这样的 json 文件:
{
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
"Version": "15.0.20628.921",
"GettingStartedDocument": {
"Uri": "https://go.microsoft.com/fwlink/?linkid=858517"
},
"ExtendedData": {
"Uri": "http://xxxxx/eisp-zk/ws/zkiService?wsdl",
"Namespace": "EispService",
"SelectedAccessLevelForGeneratedClass": "Public",
"GenerateMessageContract": false,
"ReuseTypesinReferencedAssemblies": true,
"ReuseTypesinAllReferencedAssemblies": true,
"CollectionTypeReference": {
"Item1": "System.Array",
"Item2": "System.Runtime.dll"
},
"DictionaryCollectionTypeReference": {
"Item1": "System.Collections.Generic.Dictionary`2",
"Item2": "System.Collections.dll"
},
"CheckedReferencedAssemblies": [],
"InstanceId": null,
"Name": "EispService",
"Metadata": {}
}
}
我想知道如何设置代理。谁能帮帮我?</p>
解决方案
Connectedservice.json 包含要访问的服务的端点信息和配置信息。您应该使用自动生成的代理类通过该代理类访问服务。
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
var result = client.SayHelloAsync();
Console.WriteLine(result.Result);
https://docs.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide
下面是网络框架项目中调用的例子。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client
如果有什么我可以帮忙的,请随时告诉我。
更新。
代理设置通常在绑定设置中完成。
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService" proxyAddress="http://abcd"/>
</wsHttpBinding>
</bindings>
在基于 Core 的项目中,我们通常通过 调用服务Microsoft WCF Web Service Reference Provider
,绑定配置在Reference.cs
.
相关链接。https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpbinding.proxyaddress?redirectedfrom=MSDN&view=netframework-4.0#System_ServiceModel_BasicHttpBinding_ProxyAddress
推荐阅读
- miniconda - Conda 安装 UnsatisfiableError
- ruby - RubyGem 此 gem 的可用/已安装版本
- vim - 在命令模式下更改删除默认行为
- javascript - 仅反弹 Div 的背景图像而不是内容
- javascript - 使用运行 nodejs 的 javascript 在事件之前发送通知
- javascript - 使用按钮从文本字段中复制信息?
- python - 如何使用 Selenium 和 Python 绕过 Tor 网络设置确认弹出窗口
- mysql - 如果一天内有超过 1 个数据集,如何保留最新的数据集
- swift - Swift 如何映射/翻译值?
- sql - 使用基础设施即代码时是否需要按顺序创建用户和数据库实例?