0

我正在尝试通过 RoR 应用程序连接到Bing Maps SDK 。我的目标是在地理编码后计算两个位置之间的行驶距离。我是 SOAP 和 ROR 的新手,所以我可能会犯一个简单的错误。

两天的谷歌搜索(Binging?),我快来了。这是我正在做的事情:

环境

Windows Vista 上的 Ruby 1.8.7(下周获得 Mac)。gem install httpclient --source http://dev.ctor.org/download/ gem install soap4r --include-dependencies

浏览器测试

转到https://staging.common.virtualearth.net/find-30/common.asmx?wsdl提示我输入用户名和密码。我可以成功输入并接收 WSDL 文件。所以URL、用户名和密码都是正确的

代码

require 'rubygems'
gem 'soap4r'
require 'httpclient'
require "soap/wsdlDriver"
  user = "XXXXXX"
  pass = "XXXXXXX"
  wsdl = "https://staging.common.virtualearth.net/find-30/common.asmx?wsdl"
  driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
  driver.options["protocol.http.basic_auth"] << [wsdl,user,pass]

控制台输出

驱动程序 = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver


HTTPClient:: BadResponseError: 意外响应: <#HTTP::Message::Headers:0x4f6cabc @reason_phrase="未授权",@request_uri=nil,@body_date=nil,@status_code=401,@dumped=false,@request_method=nil,@chunked=false,@body_charset=nil,@request_via_proxy=nil,@header_item=[["连接" , "close"], ["Date", "Thu, 09 Jul 2009 02:53:59 GMT"], ["Server", "Microsoft-IIS/6.0"], ["P3P", "CP=\" BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo\""], ["X-Powered-By", "ASP.NET"], ["WWW-Authenticate", "Digest qop=\"auth\", realm= \" MapPoint\", nonce=\"87b3d5847da867f7930801742100f2e55de88fd216317a696fe1411f79e3\""], ["Content-Length", "0"]], @body_size=0, @http_version="1.1", @body_type=nil, @request_query=nil , @is_request=false> 来自 c:/ruby/lib/ruby/gems/1。8/gems/httpclient-2.1.5.2/lib/httpclient.rb:840:in `follow_redirect'

我看过的参考资料

其中一个很可能有答案。我只是没有足够的SOAP背景来找到它......

http://hideoustriumph.wordpress.com/2008/05/05/ws-deathstar-for-the-rest-of-us/ http://s2.diffuse.it/blog/show/62-Consume_SSL_protected_Web_Services_with_soap4r http://s2.diffuse.it/blog/show/62-Consume_SSL_protected_Web_Services_with_soap4r /dev.ctor.org/doc/soap4r/RELEASE_en.html#samples http://markthomas.org/2007/09/12/getting-started-with-soap4r/ http://www.elctech.com/articles/消费-soap-with-ruby-and-soap-mapping-object http://wso2.org/project/wsf/ruby/1.1.0/docs/manual.html http://www.globalnerdy.com/2009/ 06/29/learnhub-powered-by-rails-searches-with-bing/ http://rpheath.com/posts/298-sumption-soap-services-in-ruby

4

2 回答 2

0

查看 Ruby 库Savon,它是迄今为止 Ruby 中最好的 SOAP 客户端。

于 2010-07-21T02:13:32.670 回答
0

用户savon用于处理 wsdl,然后使用地理编码计算两点之间的距离。因为 bing 地图 API 没有给出直接的“距离差异”,但它为我们提供了点的纬度/经度。并且 Geocoder 可以给出两对 lat/lng 之间更准确的距离

于 2015-10-20T07:56:19.170 回答