2017-02-10 23 views
1

我試圖複製我發現這裏使用Bing的地理編碼APIhttps://sqlmd.wordpress.com/2012/03/27/using-the-ssis-scripting-task-to-geocode-addresses/兵地理編碼API,SSIS,C#腳本

當我跑我有什麼,我得到這個錯誤:

Error: 0xFFFFFFFF at Get Lat Long Bing, Error:: Could not find default endpoint element that references contract 'bing.geocode.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 contract could be found in the client element.

我正在使用的腳本是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> 

回答

0

我會懷疑你需要檢查你的配置文件的設置正確

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

或者,可能需要恢復配置。在這種情況下,您應該從配置中刪除自定義綁定並重建解決方案。

+0

<綁定名稱= 「BasicHttpBinding_IGeocodeService」/> <端點地址=「HTTP ://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc」 結合= 「basicHttpBinding_IGeocodeService」 bindingConfiguration = 「basicHttpBinding_IGeocodeService」 合同= 「basicHttpBinding_IGeocodeService」 名稱= 「basicHttpBinding_IGeocodeService」/> Joey

+0

@Joey我建議你在你的問題中加入這段代碼,以獲得更多幫助。 – Svek

+0

嘗試從配置中刪除自定義綁定並重建項目。 – Svek

0

看起來您正在使用舊版的舊版Bing Maps SOAP服務。這些即將結束,將在六月底關閉。使用Bing Maps REST服務,而不是更快,並具有更多功能。 Bing Maps團隊創建了一個開源工具包,用於在.NET中使用Bing Maps REST服務。這實際上比使用SOAP服務更容易:https://github.com/Microsoft/BingMapsRESTToolkit/

也就是說,如果您有大量數據需要定期對數據庫進行地理編碼,則可能需要使用Bing地圖中的批量地理編碼服務。它需要更多的工作來設置,但對於大型數據集來說要快得多,會使用更少的帶寬。作爲額外的好處,如果您授權Bing地圖,則每年的第一批1M地理編碼地址是免費客戶。你可以找到有關該服務的文檔在這裏:https://msdn.microsoft.com/en-us/library/ff701733.aspx

+0

有沒有已經完成的鏈接?我不確定你發給我的第一個鏈接是如何工作的。我不是一個編碼器,所以很多都沒有意義。 – Joey

+0

在該頁面上有該工具包文檔的鏈接。該文檔很容易遵循:https://github.com/Microsoft/BingMapsRESTToolkit/wiki/Getting-Started – rbrundritt