You may be surprised (I was!) but Visual Studio 2015 (and Visual Studio 2017) is not able to add (out of the box) a service reference.
When you click right mouse button on the ‘References‘ folder, there is an option ‘Add Connected Service‘ but it doesn’t allow us to add service reference, it has only two options like in the screen below.
None of the above looks like a place to paste your web service url. So you may be curious how to deal with that problem?
Solving the problem – VS 2015
There is an extension for Visual Studio 2015 – you can download it from here. It will add a third option to ‘Add connected Service‘ window.
When you select the new option – WCF Service – Preview and click ‘Configure‘, the below window will appear, where you can add a web service url, set how web service data will be managed in your code and so on. That’s pretty enough for me!
And what about Visual Studio 2017?
Well, 12 days ago, there was still a problem with adding a web service reference to VS2017 project. There wasn’t a dedicated extension, so all we could do was searching for a workaround. There was a few but my favorite was creating a class library in VS 2015. Having that project created, you could put all the logic that requires WCF Service endpoint in that project and migrate it to your VS 2017. It requires having both version of Visual Studio installed but should work.
The other way of using web service is even easier – you can create a class library project in VS 2015, add a reference to web service and set access level for web service classes as public. Then you create a .dll file from this project and include it to your VS 2017 project. As simple as that.
I don’t like both of the solutions :). If you neither, you can always download quite new VS 2017 extension from here. Buuuut, it has some known issues. Like this or that. Of course, the tool is still in the preview phase and its creators seem to work hard on solving the problems but we all know the pain – we need a solution here and now, because deadline will not be postponed because of the lack of some tooling.
So if you want to connect to a web service secured with basic authentication, you may try one of my above workarounds.
Or maybe you find another way to connect to web service from Visual Studio 2017?
Featured image be Maher El Aridi.