Search code examples
c#.netweb-serviceswcf.net-core

Changing WCF Reference Url .Net Core


I am attempting to integrate a Web Service into my project, but the problem is I will need to handle this Web Service for multiple environments. I'm using Visual Studios Connected Services tool to connect my service to my project. This auto generates me a ConnectedServices.json file that looks something like this:

"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
  "Version": "15",
  "ExtendedData": {
    "inputs": [
      "https://someurl/v3/GetUrl-dev.svc"
    ],
    "collectionTypes": [
      "System.Array",
      "System.Collections.Generic.Dictionary`2"
    ],
    "namespaceMappings": [
      "*, GetUrl"
    ],

The problem is that I need to use both a Dev and a Prod environment in my project so I need to be able to reference both Web Services that have the same methods, just one has the Prod Reference Url https://someurl/v3/GetUrl-Prod.svc.

I've tried to Google it and look here as well but the solutions are mostly for ASP.NET applications, mine is a AWS Lambda project so these solutions don't fit me.

I have tried to add the endpoint explicitly like;

var client = new GetUrlContractClient(new BasicHttpBinding(), new Endpoint("https://someurl/v3/GetUrl-Prod.svc");

An exception gets thrown for including https:// and says that it expects http:// so I remove that and then the Web Service fails. I have also looked into modifying that JSON file on runtime, but it seems like a bad idea.

Is there a "standard practice" when it comes to using multiple environments with Connected Services on .Net Core?


Solution

  • So as it seems this was the correct way to go about it but in the BasicHttpBinding constructor you have to explicitly say that it is BasicHttpSecurityMode.Transport and now it is working for me!