asp .net core wcf endpoints



我正在开发一个调用WSDL soap api的小型Web API。WSDL 文件有一个端点集,但我希望能够在 appsetting.json 文件中更改它,以便我可以为不同的环境(DEV、生产等(使用不同的端点。 我知道在传统的.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设置为同一节点的type,并在前面标注了 WCF 点的命名空间。我设置为<wsdl:port>节点的name属性的name:。本质上,我希望能够在appsettings.json文件中设置<soap:address location>

基于此链接,在 ASP.NET Core 中,尚无法在单独的配置文件中进行配置。它仅从代码设置。

不幸的是,您暂时必须坚持使用代码。

我意识到我迟到了三年半,在这里得到了答案。 但是,由于没有人回答它,我想我会给它一个破解。

在"启动"中.cs"配置服务处理程序"添加:

services.AddScoped<IServiceWeb, ServiceWebClient>(
(c) => 
new ServiceWebClient(
ServiceWebClient.EndpointConfiguration.BasicHttpBinding_IServiceWeb, 
Configuration["client:endpoint:address"]
)
);

最新更新