title: Connecting to Bing Maps SDK from a Rails app
body: <p>I am attempting to connect to <a href="http://msdn.microsoft.com/en-us/library/cc980922.aspx" rel="nofollow noreferrer">Bing Maps SDK</a> through a RoR application.  My goal is to calculate driving distance between two locations after geocoding them.  I am new to SOAP and ROR so I may be making a simple mistake.  </p>
  
  <p>Two days of Googling (Binging?) and I'm coming up short.  Here is what I am doing:</p>
  
  <h2>Environment</h2>
  
  <p>Ruby 1.8.7 on Windows Vista (getting a Mac next week).
  gem install httpclient --source <a href="http://dev.ctor.org/download/" rel="nofollow noreferrer">http://dev.ctor.org/download/</a> 
  gem install soap4r --include-dependencies</p>
  
  <h2>Browser Test</h2>
  
  <p>Going to <a href="https://staging.common.virtualearth.net/find-30/common.asmx?wsdl" rel="nofollow noreferrer">https://staging.common.virtualearth.net/find-30/common.asmx?wsdl</a> I am prompted with  User Name and Password.  I can enter both successfully and receive the WSDL file.  So the <strong>URL, userid, and password are correct</strong>.</p>
  
  <h2>Code</h2>
  
  <pre><code>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"] &lt;&lt; [wsdl,user,pass]
  </code></pre>
  
  <h2>Console Output</h2>
  
  <blockquote>
    <blockquote>
      <p>driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver</p>
    </blockquote>
  </blockquote>
  
  <hr>
  
  <p>HTTPClient::<strong>BadResponseError: unexpected response</strong>: &lt;#HTTP::Message::Headers:0x4f6cabc @reason_phrase="<strong>Unauthorized</strong>", @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=[["Connection", "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>
  from c:/ruby/lib/ruby/gems/1.8/gems/httpclient-2.1.5.2/lib/httpclient.rb:840:in `follow_redirect'</p>
  
  <h2>References I've reviewed</h2>
  
  <p>Quite possible that one of these has the answer.  I just don't have enough background in SOAP to find it...</p>
  
  <p><a href="http://hideoustriumph.wordpress.com/2008/05/05/ws-deathstar-for-the-rest-of-us/" rel="nofollow noreferrer">http://hideoustriumph.wordpress.com/2008/05/05/ws-deathstar-for-the-rest-of-us/</a>
  <a href="http://s2.diffuse.it/blog/show/62-Consume_SSL_protected_Web_Services_with_soap4r" rel="nofollow noreferrer">http://s2.diffuse.it/blog/show/62-Consume_SSL_protected_Web_Services_with_soap4r</a>
  <a href="http://dev.ctor.org/doc/soap4r/RELEASE_en.html#samples" rel="nofollow noreferrer">http://dev.ctor.org/doc/soap4r/RELEASE_en.html#samples</a>
  <a href="http://markthomas.org/2007/09/12/getting-started-with-soap4r/" rel="nofollow noreferrer">http://markthomas.org/2007/09/12/getting-started-with-soap4r/</a>
  <a href="http://www.elctech.com/articles/consuming-soap-with-ruby-and-soap-mapping-object" rel="nofollow noreferrer">http://www.elctech.com/articles/consuming-soap-with-ruby-and-soap-mapping-object</a>
  <a href="http://wso2.org/project/wsf/ruby/1.1.0/docs/manual.html" rel="nofollow noreferrer">http://wso2.org/project/wsf/ruby/1.1.0/docs/manual.html</a>
  <a href="http://www.globalnerdy.com/2009/06/29/learnhub-powered-by-rails-searches-with-bing/" rel="nofollow noreferrer">http://www.globalnerdy.com/2009/06/29/learnhub-powered-by-rails-searches-with-bing/</a>
  <a href="http://rpheath.com/posts/298-consuming-soap-services-in-ruby" rel="nofollow noreferrer">http://rpheath.com/posts/298-consuming-soap-services-in-ruby</a></p>