Please do not use sp_OA* OLE automation sp_OA* . They do not seem to have been officially deprecated, but SQLCLR replaces both OLE Automation procedures and extended stored procedures.
Yes, this can be done quite easily in SQLCLR. You can find examples of using WCF (as shown in @CodeCaster's answer) or using HttpWebRequest / HttpWebResponse (I have additional information in this answer: How to call a web service from a SQL Server stored procedure ). Also keep in mind that sometimes you also need to add a serialization assembly: Using web services and Xml serialization in CLR integration
Coding and maintenance
Web services provide a good API, but if you change the structure, you will have to recompile and redistribute at least some of this. Assuming that the exchange of information is quite simple, I am inclined to think that considering this as a standard web request adds more flexibility. You can create a general web request function (scalar or TVF) that takes parameters and a URI and creates a properly formatted XML request and sends it to the URI. Then it receives a response and simply returns the XML. This way you change a bit of responsibility, because now you need to parse the XML response and not get a good object. But XML is easy to parse in SQL Server, and you can reuse this function in any number of places. And, if the remote service is constantly being updated, updating the stored procedure to change the query string passed to the web service and / or changing the parsing of the XML response is a simple ALTER procedure and should be easily tested. There is no need to recompile / remodel the SQLCLR assembly.
Security
Regardless of how you need a βcleanβ web service call, the main thing is to be safe and not be lazy and turn TRUSTWORTHY ON (as also shown on the linked page from @CodeCaster's answer, and unfortunately, most of the other examples here are on intervets). The proper way to make this safe is to do the following:
- Sign your assembly
- In the
[master] database, create an asymmetric key from the DLL of your assembly. - In addition, in
[master] create a login from this asymmetric key - Provide a new login to the
EXTERNAL ACCESS ASSEMBLY . - Build your assembly with
PERMISSION_SET EXTERNAL_ACCESS , not UNSAFE
Solomon rutzky
source share