Reputation: 2882
How do I consume WCF services in SQL / SQL CLR?
Upvotes: 1
Views: 3277
Reputation: 158
I actually implemented just this very thing for a query integration problem recently at work.
You can create the SQLCLR project in Visual Studio and then simply create your WCF Service reference as normal. Once you have that you can invoke the service client methods within your [SqlFunction] or [SqlProcedure] attributed SQLCLR function.
There are two main gotchas to watch out for: [1] WCF endpoint configuration has to be done programmatically since no web service app.config file can be read for the managed SQLCLR assembly, as invocation is from within SqlServer.exe. [2] You may need to Gacutil some assemblies from .NET 3.0, if calling the SQLCLR function or sproc from SQL Server 2008 or below. Those assemblies in question for me were:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.IdentityModel.dll C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.IdentityModel.Selectors.dll
Good luck, hope this helps!
Upvotes: 3