It helps to know what version of SQL Server you are on. But regardless, if you are relying on the ServiceModel
library (or any other .NET Framework libraries that you need to manually load into SQLServer), then that isn't going to work. You can do web service calls in SQLCLR, but only using libraries in the Supported .NET Framework Libraries list.
For doing such things, I usually recommend using the plain 'ol HttpWebRequest
/ HttpWebResponse
classes and handling the creation and parsing of the XML manually (well, using available .NET classes). It won't automatically give you a strongly typed object, but it is guaranteed to work across all version of SQL Server.
Also, the advice in that post to enable TRUSTWORTHY
is bad advice. You should instead sign the Assembly, then create an Asymmetric Key in master
from the DLL, then create a Login from that Asymmetric Key, and finally grant the EXTERNAL ACCESS ASSEMBLY
permission to that Login. Accomplishing this can be done in a few ways and depends on what version of SQL Server you are using (SQL Server 2017 introduced a new complication) and if you are using Visual Studio / SSDT / SqlPackage`exe for deployment. I have written a series of tutorials on this topic showing 2 options that both work with all versions of SQL Server (well, 2005 through current – which is 2017 at the moment), starting with:
SQLCLR vs. SQL Server 2017, Part 1: “CLR strict security” – The Problem
Part 1 (linked directly above) explains the situation and why the new server-wide setting in SQL Server 2017 is a problem given the lack of built-in support for dealing with it via Microsoft-provided tools such as Visual Studio / SSDT. Parts 2 and 3 are the actual solutions.