【问题标题】:Bing Geocode API, SSIS, C# Script必应地理编码 API、SSIS、C# 脚本
【发布时间】: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


    【解决方案1】:

    我怀疑你需要检查你的配置文件是否设置正确

    <configuration>
        ...
        <client>
            <endpoint address="http://localhost:9999/"
                binding="yoursetting" bindingConfiguration="yoursetting"
                contract="yoursetting" name="yoursetting">
            </endpoint>
        </client>
        ...
    </configuration>
    

    或者,可能需要恢复配置。在这种情况下,您应该从配置中删除自定义绑定并重建解决方案。

    【讨论】:

    • dev.virtualearth.net/webservices/v1/geocodeservice/…" binding= "BasicHttpBinding_IGeocodeService" bindingConfiguration="BasicHttpBinding_IGeocodeService" contract="basicHttpBinding_IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
    • @Joey 我建议您将此代码添加到您的问题中,以获得更多帮助。
    • 尝试从配置中删除自定义绑定并重建项目。
    【解决方案2】:

    您似乎正在使用旧的 Bing 地图 SOAP 服务。这些已接近使用寿命,将于 6 月底关闭。改用 Bing Maps REST 服务,它更快,功能更多。 Bing Maps 团队创建了一个开源工具包,用于在 .NET 中使用 Bing Maps REST 服务。它实际上比使用 SOAP 服务更容易:https://github.com/Microsoft/BingMapsRESTToolkit/

    也就是说,如果您的数据库中有大量数据需要定期进行地理编码,您可能需要使用 Bing 地图中的批量地理编码服务。它的设置工作要多一些,但对于大型数据集来说会更快,并且会使用更少的带宽。作为额外的奖励,如果您获得 Bing Maps 的许可,则每年前 100 万个批量地理编码地址是免费客户。您可以在此处找到有关此服务的文档:https://msdn.microsoft.com/en-us/library/ff701733.aspx

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多