It is not clear what exactly you're struggling with. The service reference has a constructor with endpoint configuration (enum) and URL. Use standard dependency injection to get the URL from configuration. How you design this is totally up to you. I typically wrap the code generated service reference in a standard service pattern and register the service with the dependency injection container. You can also use inheritance.
Load WSDL by environment in .NET Web API project
Salman Rafique
0
Reputation points
I have different WSDL URLs for development and production. Whenever I add WSDL web reference in my ASP.NET 7.0 Web API application, it generates ConnectedService.json
and Reference.cs
files.
Both these files contain the WSDL URL, and I need to dynamically pick the URL from appsettings.json
based on the environment.
File: Reference.cs
- URL included like:
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.UMarketSC))
{
return new System.ServiceModel.EndpointAddress("http://xx.xx.xx.xx:xxxx/services/umarketsc");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name '{0}'.", endpointConfiguration));
}
File: ConnectedService.json
URL included like:
"ExtendedData": {
"inputs": [
"http://xx.xx.xx.xx:xxxx/services/umarketsc?wsdl"
],
}
Developer technologies ASP.NET ASP.NET API
447 questions
Developer technologies .NET Other
4,103 questions