2

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?

845614720
  • 756
  • 1
  • 7
  • 22
  • 1
    _"it expects http://"_ - could that be because you're using a `BasicHttpBinding`? – stuartd Nov 11 '19 at 16:58
  • @stuartd I don't think that is the issue but that gives me an idea for the Security Mode for the binding... – 845614720 Nov 11 '19 at 17:08
  • @stuartd I believe adding `new BasicHttpBinding(BasicHttpSecurityMode.Transport)` worked for me, can you please answer this so I can mark it? – 845614720 Nov 11 '19 at 17:14
  • 1
    you can answer your own question on SO, which seems appropriate here? – stuartd Nov 11 '19 at 17:19
  • Where does this solution code exist? I also created my web service connections via the wizard, so I do not see where this `var client = new GetUrlContractClient(new BasicHttpBinding(), new Endpoint("https://someurl/v3/GetUrl-Prod.svc");` would be placed – James Hurley Jul 08 '22 at 13:20
  • 1
    @JamesHurley It would be placed wherever in code you need to use your client. – 845614720 Jul 13 '22 at 13:44
  • I never use the client in that way--I found a differ solution, the "preferred" solution is to extend the ConfigureEndpoint class from the auto generated Reference.cs class and change the endpoint there – James Hurley Jul 14 '22 at 13:09

1 Answers1

4

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!

845614720
  • 756
  • 1
  • 7
  • 22