我开发了一个小型 C# 应用程序,可以使用配置为服务引用的 Bing 地理编码服务对地址表进行地理编码。我已加载程序集,但当我尝试通过存储过程调用它时,我收到以下错误:
A .NET Framework error occurred during execution of user-defined routine or aggregate "Geocoder":
System.InvalidOperationException: Could not find endpoint element with name 'BasicHttpBinding_IGeocodeService' and contract 'BingMapsGeo.IGeocodeService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
System.InvalidOperationException:
at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
at System.ServiceModel.ClientBase`1..ctor(String endpointConfigurationName)
at Geocoder.BingMapsGeo.GeocodeServiceClient..ctor(String endpointConfigurationName)
at Geocoder.UserDefinedFunctions.geocode(SqlString AddressLine, SqlString City, SqlString State, SqlString Zip)
我相当确定实际的 C# 程序集是正确的,但我认为我遗漏了一些与实际 Web 服务有关的内容。
我一直在到处寻找解决方案,但还没有找到一个似乎有效的解决方案。
我在具有最新补丁和 .NET 版本的 Server 2008R2 上运行 SQL 2008R2。
任何想法都将受到欢迎。
最佳答案
从 SQLCLR 进行 Web 服务调用是可能的,但这始终是一个坏主意。 SQL Server 资源非常宝贵,不能让它们阻塞等待来自 Internet 的响应。最终,除了(可疑的)冷静因素之外,从 SQLCLR 执行此操作的优势为零。此外,不支持将 WCF 加载到 SQLCLR,请参阅 Support policy for untested .NET Framework assemblies in the SQL Server CLR-hosted environment 。最后,SQLCLR 程序集看不到任何 .config 配置节。有一个已知的解决方法是将配置放在 sqlservr.exe.config 中,但也不支持。
从客户端(您的应用程序)进行 Web 服务调用,然后更新数据库。这不仅是支持的,而且实际上是正确的方式。
关于sql-server - SQL 2008 CLR 和 Bing map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6156568/