首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >必应地理代码API,SSIS,C#脚本

必应地理代码API,SSIS,C#脚本
EN

Stack Overflow用户
提问于 2017-02-10 19:24:27
回答 2查看 740关注 0票数 1

我试图复制我在这里发现的使用bing的地理代码APIhttps://sqlmd.wordpress.com/2012/03/27/using-the-ssis-scripting-task-to-geocode-addresses/

当我运行我所拥有的,我会得到这个错误:

错误: Get Lat Long Bing处的0xFFFFFF,错误::未能在ServiceModel客户端配置部分找到引用合同‘ServiceModel’的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此契约匹配的端点元素。

我使用的脚本是C#

代码语言:javascript
复制
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:

代码语言:javascript
复制
<?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>

EN

回答 2

Stack Overflow用户

发布于 2017-02-10 19:38:05

我怀疑您需要检查您的配置文件是否安装正确。

代码语言:javascript
复制
<configuration>
    ...
    <client>
        <endpoint address="http://localhost:9999/"
            binding="yoursetting" bindingConfiguration="yoursetting"
            contract="yoursetting" name="yoursetting">
        </endpoint>
    </client>
    ...
</configuration>

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

票数 0
EN

Stack Overflow用户

发布于 2017-02-11 06:42:14

看起来您正在使用旧的必应地图SOAP服务。这些都快到生命的尽头了,将在6月底关闭。使用Bing地图REST服务,这些服务速度更快,功能更多。Bing Maps团队创建了一个开源工具包,用于在.NET中使用Bing地图REST服务。

尽管如此,如果您在数据库中定期有大量的地理编码数据,您可能希望使用必应地图中的批处理地理编码服务。这是一个更多的工作设置,但将更快的大数据集,将使用较少的带宽。作为额外的奖励,如果你授权Bing地图,第一个100万批的地理编码地址一年是免费的客户。您可以在这里找到有关此服务的文档:https://msdn.microsoft.com/en-us/library/ff701733.aspx

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42167151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档