【发布时间】:2017-02-10 19:24:27
【问题描述】:
我正在尝试复制我在此处找到的内容以使用 bing 的地理编码 API: https://sqlmd.wordpress.com/2012/03/27/using-the-ssis-scripting-task-to-geocode-addresses/
当我运行我拥有的东西时,我得到了这个错误:
错误:获取 Lat Long Bing 时出现 0xFFFFFFFF,错误::找不到默认值 引用合约的端点元素 ServiceModel 客户端中的“bing.geocode.IGeocodeService” 配置部分。这可能是因为没有配置文件 为您的应用程序找到,或者因为没有匹配的端点元素 该合同可以在客户端元素中找到。
我使用的脚本是C#。
Public Sub Main()
If Dts.Variables.Contains("Address") And Dts.Variables.Contains("Lat") And Dts.Variables.Contains("Long") Then
Try
' Set a Bing Maps key before making a request
Dim key As String = "Bing Key goes here"
Dim geocodeRequest As New bing.geocode.GeocodeRequest
Dim SearchAddress As String
SearchAddress = Dts.Variables("Address").Value.ToString
Dts.Events.FireInformation(0, "Address:", SearchAddress, "", 0, True)
' Set the credentials using a valid Bing Maps Key
geocodeRequest.Credentials = New bing.geocode.Credentials()
geocodeRequest.Credentials.ApplicationId = key
' Set the full address query
geocodeRequest.Query = SearchAddress
' Set the options to only return high confidence results
Dim filters As bing.geocode.ConfidenceFilter() = New bing.geocode.ConfidenceFilter(0) {}
filters(0) = New bing.geocode.ConfidenceFilter()
filters(0).MinimumConfidence = bing.geocode.Confidence.High
Dim geocodeOptions As New bing.geocode.GeocodeOptions()
geocodeOptions.Filters = filters
geocodeRequest.Options = geocodeOptions
' Make the geocode request
Dim geocodeService As New bing.geocode.GeocodeServiceClient
Dim geocodeResponse As bing.geocode.GeocodeResponse = geocodeService.Geocode(geocodeRequest)
If geocodeResponse.Results.Length > 0 AndAlso geocodeResponse.Results(0).Locations.Length > 0 Then
Dts.Events.FireInformation(0, "Lat:", geocodeResponse.Results(0).Locations(0).Latitude.ToString(), "", 0, False)
Dts.Variables("Lat").Value = geocodeResponse.Results(0).Locations(0).Latitude
Dts.Events.FireInformation(0, "Long:", geocodeResponse.Results(0).Locations(0).Longitude.ToString(), "", 0, True)
Dts.Variables("Long").Value = geocodeResponse.Results(0).Locations(0).Longitude
End If
Catch ex As Exception
Dts.Events.FireError(-1, "Error:", ex.Message, "", 0)
Dts.TaskResult = ScriptResults.Success
End Try
Else
Dts.Events.FireError(-1, "Error:", "Missing vairable in Task Component Definition.", "", 0)
End If
End Sub
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
结束类
这是我的 app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_IGeocodeService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
binding="basicHttpBinding_IGeocodeService" bindingConfiguration="basicHttpBinding_IGeocodeService"
contract="basicHttpBinding_IGeocodeService" name="basicHttpBinding_IGeocodeService" />
</client>
</system.serviceModel>
【问题讨论】:
标签: c# sql-server visual-studio ssis bing-maps