项目中经常需要调用Webservice进行验证测试,下面就介绍下如何使用测试工具SoapUI调用Vsphere vcenter的 Web Service

VSphere的Webservice地址默认为 https://vcenterip/sdk/vimService

1 首先要进行认证。使用Login方法,获取合法Cookie

Request内容如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">
   <soapenv:Header/>

   <soapenv:Body>
      <urn:Login>
         <urn:_this type="SessionManager">SessionManager</urn:_this>
         <urn:userName>administrator@vsphere.local</urn:userName>
         <urn:password>密码</urn:password>
         <!--Optional:-->
         <urn:locale>?</urn:locale>
      </urn:Login>
   </soapenv:Body>
</soapenv:Envelope>

Response内容如下:

<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <LoginResponse xmlns="urn:vim25">
         <returnval>
            <key>52c8ab58-eb03-e526-c733-5051d62652b6</key>
            <userName>VSPHERE.LOCAL\Administrator</userName>
            <fullName>Administrator vsphere.local</fullName>
            <loginTime>2016-08-15T09:19:39.526713Z</loginTime>
            <lastActiveTime>2016-08-15T09:19:39.526713Z</lastActiveTime>
            <locale>?</locale>
            <messageLocale>zh_CN</messageLocale>
            <extensionSession>false</extensionSession>
            <ipAddress>10.200.108.92</ipAddress>
            <userAgent>Apache-HttpClient/4.1.1 (java 1.5)</userAgent>
            <callCount>0</callCount>
         </returnval>
      </LoginResponse>
   </soapenv:Body>
</soapenv:Envelope>

注意:需要记录response中的header信息,用于后面设置header,我这里的header信息如下

Set-Cookie        vmware_soap_session="52f2ce6a-8ce9-94cc-bd62-3f750d61cd4f"; Path=/; HttpOnly; Secure;

2 然后我使用FindByDnsName方法,获取一台机器的ManagedObjectID

Request内容如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">
<soapenv:Header>
</soapenv:Header>
   <soapenv:Body>

      <urn:FindByDnsName>
         <urn:_this type="SearchIndex">SearchIndex</urn:_this>
         <!--Optional:-->
         <urn:dnsName>testupgrade</urn:dnsName>
         <urn:vmSearch>true</urn:vmSearch>
      </urn:FindByDnsName>

   </soapenv:Body>
</soapenv:Envelope>

注意上面xml中<urn:_this type="SearchIndex">SearchIndex</urn:_this>红色字体是根据文档中的定义填写的

然后添加header,作为认证信息,此处的cookie中填写的是,认证时response中的Set-Cookie ,具体如下图

执行成功,Response的内容如下:

<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <FindByDnsNameResponse xmlns="urn:vim25">
         <returnval type="VirtualMachine">vm-2823</returnval>
      </FindByDnsNameResponse>
   </soapenv:Body>
</soapenv:Envelope>

3 调用VSphere 其他的Webservice的方式也一样

如果你设置的Header不对,那么系统将会报错:

faultstring:The session is not authenticated

参考:

soapUI: faultstring: The session is not authenticated

使用SoapUI调用Vsphere Web Service的更多相关文章

  1. 翻译-使用Spring调用SOAP Web Service

    原文链接: http://spring.io/guides/gs/consuming-web-service/ 调用SOAP web service 本指南将指导你使用Spring调用一个基于SOAP ...

  2. Spring Boot发布和调用RESTful web service

    Spring Boot可以非常简单的发布和调用RESTful web service,下面参考官方指导体验一下 1.首先访问 http://start.spring.io/ 生成Spring Boot ...

  3. IGS_学习笔记08_IREP通过soapUI测试客户化Web Service调用(案例)

    20150819 Created By BaoXinjian

  4. SoapUI软件-测试Web Service接口

    一.新建项目 New SOAP Project Project Name填入项目名称:Initial WSDL中填入接口地址,或后缀为.wsdl的文件:OK: 添加后可在左侧看到接口详情: 二.测试接 ...

  5. Java与WCF交互(二):WCF客户端调用Java web service【转】

    原文:http://www.cnblogs.com/downmoon/archive/2010/08/25/1807982.html 在上篇< Java与WCF交互(一):Java客户端调用WC ...

  6. 转载——Java与WCF交互(二):WCF客户端调用Java Web Service

    在上篇< Java与WCF交互(一):Java客户端调用WCF服务>中,我介绍了自己如何使用axis2生成java客户端的悲惨经历.有同学问起使用什么协议,经初步验证,发现只有wsHttp ...

  7. VMware 虚拟化编程(3) —VMware vSphere Web Service API 解析

    目录 目录 前文列表 VMware vSphere Web Services API VMware vSphere Web Services SDK vSphere WS API 中的托管对象 Man ...

  8. cxf动态调用外部web service 报告异常java.lang.NoSuchFieldError: QUALIFIED

    原因:cxf 依赖的xmlschema-core 与xfire-all依赖的xmlschema冲突.(百度搜索亦得知:cxf 依赖的xmlschema-core 与axis2-kernel依赖的xml ...

  9. cxf动态调用外部web service 报告异常java.lang.NoSuchFieldErr

    原因:cxf 依赖的xmlschema-core 与axis2-kernel依赖的xmlschema冲突. 解决方法:因为在项目中只用cxf即可,所以删除axis2的依赖.

随机推荐

  1. linux常用基本命令整理小结

    linux系统遵循的基本原则 由目标单一的小程序组成,组合小程序完成复杂任务: 一切皆文件: 尽量避免捕捉用户接口: 配置文件保存为纯文本文件: Linux命令行常识 命令格式 命令+选项+参数 选项 ...

  2. Shell和命令基础

    什么是Shell Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口(命令解析器),Shell接收用户输入的命令并把它送入到内核去执行,结构如下图 Shell的功能 Shell最重要的 ...

  3. [转] Web 开发模式演变历史和趋势

    文章转自梦想天空--前端文摘:Web 开发模式演变历史和趋势 一.简单明快的早期时代 可称之为 Web 1.0 时代,非常适合创业型小项目,不分前后端,经常 3-5 人搞定所有开发.页面由 JSP.P ...

  4. js变量提升小记

    作为世界上最优美的语言javascript的使用者,呵呵,js的魅力是无穷的,今天来聊聊他的魅(dan)力(teng)之一,变量提升. 每种语言所定义的变量基本都会有一定得作用域,而js的作用域则存在 ...

  5. [译]Python作为一种编程语言有多强大?

    Quora上有个问题:Python作为一种编程语言有多强大? 以下是Patrycja Okowicka的回答 说实话,Python是一门强大的语言,几乎所有东西都可以用Python创建!这就是为什么它 ...

  6. 基于Flask实现博客开发--准备工作

    背景说明 本项目是基于<深入理解flask>一书,主要是用来记录学习历程和交流心得,所以写得不好请大神勿喷. 准备工作 virtualenv介绍 也许 Virtualenv 是你在开发中最 ...

  7. 七牛php-sdk使用-文件上传

    使用七牛进行文件上传可以有多种方式: 直接form表单上传,需要自己按照文档做配置 使用七牛jssdk,部署较简单,大文件分片上传 php-sdk后台上传 首先,所有的上传方法以及所有的跟七牛接口相关 ...

  8. MyEclipse10.7 10.6导出war文件报错 “SECURITY ALERT: INTEGERITY CHECK ERROR”

    myeclipse10.7的版本破解后,导出war包时报“SECURITY ALERT: INTEGERITY CHECK ERROR”的错误. 经过测试本次破解可以解决此错误,只需替换一个jar文件 ...

  9. Android应用程序使用两个LinearLayout编排5个Button控件

    学习存档: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...

  10. Codeforces 839D Winter is here【数学:容斥原理】

    D. Winter is here time limit per test:3 seconds memory limit per test:256 megabytes input:standard i ...