ASP .NET Core WCF 终结点

10

我正在开发一个调用WSDL SOAP API的小型Web API。WSDL文件已经设置了端点,但我希望能够在appsettings.json文件中更改它,以便我可以为不同的环境(DEV、Production等)使用不同的端点。我知道在传统的.NET中,您可以在web.config文件中设置端点,因此我尝试在appsettings.json中模拟它。

 "client": {
   "endpoint": {
   "address": "https://testaddress.com:9000",
   "binding": "basicHttpBinding",
   "bindingConfiguration": "MyWSDLService_Binder",
   "contract": "MyWSDLNamespace.Service__PortType",
   "name": "MyWSDLService_Port"
 }
}

我将bindingConfiguration设置为实际WSDL中<wsdl:binding>节点中的name属性,将contract设置为与WCF命名空间前缀相同的该节点的type。 我将name: 设置为<wsdl:port>节点的name属性。基本上,我想能够在appsettings.json文件中设置<soap:address location>

2个回答

2
基于这个链接,在ASP.NET Core中,目前还不可能使用单独的配置文件进行配置。它只能从代码中设置。
不幸的是,目前你必须继续使用代码。

0
我意识到我回答晚了三年半。但是,既然没有人回答,我想我可以试着回答一下。
在Startup.cs的ConfigureServices处理程序中添加以下内容:
services.AddScoped<IServiceWeb, ServiceWebClient>(
(c) => 
  new ServiceWebClient(
     ServiceWebClient.EndpointConfiguration.BasicHttpBinding_IServiceWeb, 
     Configuration["client:endpoint:address"]
  )
);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接