Google Groups Home
Help | Sign in
Message from discussion getting started, ruby/soap/vmware-Lab Manager
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Bill  
View profile
 More options May 1, 6:59 pm
From: Bill <bill.gilb...@pacbell.net>
Date: Thu, 1 May 2008 15:59:59 -0700 (PDT)
Local: Thurs, May 1 2008 6:59 pm
Subject: Re: getting started, ruby/soap/vmware-Lab Manager
I learned that I needed to create a header-handler.
Here's the code that got past the missing authorization header
problem...
require 'rubygems'
gem 'soap4r'
require 'defaultDriver.rb'
require 'soap/header/simplehandler'

class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler
        def initialize(userid, passwd)
                namespace = "http://vmware.com/labmanager"
                headername = "AuthenticationHeader"
                header = XSD::QName.new(namespace, headername)
                super(header)
                @sessionid = nil
                @userid = userid
                @passwd = passwd
                @mustunderstand = true
        end
        def on_simple_outbound
                if @sessionid
                  { "sessionid" => @sessionid }
                else
                        { "username" => @userid, "password" => @passwd }
                end
        end
        def on_simple_inbound(my_header, mustunderstand)
                @sessionid = my_header["sessionid"]
        end
end

endpoint_url = nil
obj = VMware_interfaceSoap.new(endpoint_url)
obj.wiredump_dev = STDOUT

obj.options['protocol.http.ssl_config.verify_mode'] =
OpenSSL::SSL::VERIFY_NONE #ignore certificates for now
headerHandler =
ClientAuthHeaderHandler.new("myusername","mypassword")
obj.headerhandler.add( headerHandler )

puts obj.listConfigurations(nil)

On Apr 30, 5:24 pm, Bill <bill.gilb...@pacbell.net> wrote:

> I'm stuck trying to understand a "Missing authorization header" error
> when I try to access a VMware SOAP service using Ruby.

> First I fetched the wsdl from our Lab Manager machine to my local
> machine and ran wsdl2ruby.rb. It generated a bunch of files that I,
> being new to SOAP, don't really understand. I copied some code from
> the generated sample client and cut it back to a simple "list
> configurations" call. First it complained about "certificate verify
> failed", so I disabled certificate checking for the moment via this
> line.

> obj.optionshttp://'protocol.http.ssl_config.verify_mode' =
> OpenSSL::SSL::VERIFY_NONE

> I'll get back to certificates later (I tell myself), but now I've
> "missing authorization header" error. I haven't edited any of the
> generated code. I believe the namespace is "http://vmware.com/
> labmanager", but lines like this

> SOAPAction: "http://vmware.com/labmanager/ListConfigurations"

> make nervous. I found a class called AuthenticationHeader, but I can't
> figure out how/where to use it. The C# examples indicate the
> AuthenticationHeader should be part of the driver object.

> //**
> //** Allocate AuthenticationHeader object to hold caller’s
> //** username and password
> //**
> binding.AuthenticationHeaderValue = new
> LabManagerSoap.AuthenticationHeader();

> But I can't figure out how to translate that to the Ruby code
> generated by wsdl2ruby.rb.

> Here's the program...

> #!/usr/bin/env ruby
> require 'rubygems'
> gem 'soap4r'
> require 'defaultDriver.rb' #generated by wsdl2ruby.rb
> endpoint_url = nil
> obj = VMware_interfaceSoap.new(endpoint_url)
> obj.wiredump_dev = STDOUT #print all requests/repsonses to stdout

> obj.optionshttp://'protocol.http.ssl_config.verify_mode' =
> OpenSSL::SSL::VERIFY_NONE #disable certificate checking
> puts obj.listConfigurations(nil)

> Here's the request/response trace.

> = Request

> ! CONNECT TO x.y.com:443
> ! CONNECTION ESTABLISHED
> at depth 0 - 20: unable to get local issuer certificate
> POST /LabManager/SOAP/LabManager.asmx HTTP/1.1
> SOAPAction: "http://vmware.com/labmanager/ListConfigurations"
> Content-Type: text/xml; charset=utf-8
> User-Agent: SOAP4R/1.5.8 (/187, ruby 1.8.6 (2007-09-24)http://universal-darwin9.0)
> Date: Wed, 30 Apr 2008 23:44:50 GMT
> Content-Length: 373
> Host: x.y.com

> <?xml version="1.0" encoding="utf-8" ?>
> <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <env:Body>
> <n1:ListConfigurations xmlns:n1="http://vmware.com/labmanager"
> xsi:nil="true"></n1:ListConfigurations>
> </env:Body>
> </env:Envelope>

> = Response

> HTTP/1.1 500 Internal Server Error
> Date: Wed, 30 Apr 2008 23:47:29 GMT
> Server: Microsoft-IIS/6.0
> X-Powered-By: ASP.NET
> X-AspNet-Version: 2.0.50727
> Cache-Control: private
> Content-Type: text/xml; charset=utf-8
> Content-Length: 370

> <?xml version="1.0" encoding="utf-8"?><soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/
> XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</
> faultcode><faultstring>Missing authorization header</
> faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>

> : Missing authorization header (SOAP::FaultError)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google