我是肥皂新手,但我一直在努力奋斗这几天,无法弄清楚我哪里出错了。我正在尝试使用Ruby与VMware Site Recovery Manager交谈
我有一个可以成功用于登录的powershell脚本。我想采用这个PowerShell脚本并在ruby中重写它。
以下是wsdl文件:
https://srm-vcenter-a:8095/srm?wsdl
https://srm-vcenter-a:8095/srm-Service?wsdl
powershell代码
$Server = "srm-vcenter-a"
$UserName = "administrator"
$Password = "mypw"
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Write-Host "Connecting to SRM"
$webSvc = New-WebServiceProxy ("https://" + $Server + ":8095/srm-Service?wsdl") -Namespace SRM
$srm = New-Object SRM.SrmService
$srm.Url = "Https://" + $Server + ":9007"
$srm.Timeout = 600000
$srm.CookieContainer = New-Object System.Net.CookieContainer
$srmSvcRef = New-Object SRM.ManagedObjectReference
$srmSvcRef.Type = "SrmServiceInstance"
$srmSvcRef.Value = $srmSvcRef.Type
$srmSvcContent = $srm.RetrieveContent($srmSvcRef)
$srm.SrmLoginLocale($srmSvcRef, $UserName, $Password, $null)
$srmObject = New-Object System.Object
$srmObject | Add-Member -Type NoteProperty -value $Server -Name SRMServer
$srmObject | Add-Member -Type NoteProperty -value $srm -Name SRMService
$srmObject | Add-Member -Type NoteProperty -value $srmSvcContent -Name SRMContent
...
我尝试过使用Savon,soap4r和handsoap,我不知道我错过了什么。
这是Savon代码不起作用。
require 'savon'
require 'rubygems'
client = Savon.client do
wsdl "https://srm-vcenter-a:8095/srm?wsdl"
#endpoint "https://srm-vcenter-a:8095/srm-Service?wsdl"
endpoint "http://srm5-vcenter-a:9007"
namespace "https://srm-vcenter-a/sdk/srm"
#proxy "https://srm-vcenter-a:8095/srm-Service?wsdl"
ssl_version :TLSv1
ssl_verify_mode :none
convert_request_keys_to :lower_camelcase
end
message = { username: 'administrator', password: 'mypw' }
response = client.call(:srm_login_locale, message: message)
提前致谢所有帮助
答案 0 :(得分:0)
简要介绍一下您的代码后,您可以在PowerShell中找到
$srm.SrmLoginLocale($srmSvcRef, $UserName, $Password, $null)
在Ruby中你有
message = { username: 'administrator', password: 'mypw' }
response = client.call(:srm_login_locale, message: message)
在PowerShell代码中,有4个值传递给SrmLoginLocale方法:
在ruby代码中,您缺少调用中的第一个参数和第四个参数。尝试在ruby中创建等效的$ srmSvcRef。我不是一个红宝石程序员,但我认为代码看起来像一样:
srm_svc_ref = { value: 'SrmServiceInstance', type: 'SrmServiceInstance'}
message = { _this: srm_svc_ref, username: 'administrator', password: 'mypw', locale: nil}
response = client.call(:srm_login_locale, message: message)