项目中经常需要调用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. sql基本知识

    1.类型转换 用convert,cast float转换出现科学计数字母的问题:可以先转成numeric再转成varchar declare @fl float set @fl=1234567.123 ...

  2. Python 的类的下划线命名有什么不同?

    1.   以一个下划线开头的命名 ,如_getFile2.  以两个下划线开头的命名 ,如__filename3.  以两个下划线开头和结尾的命名,如 __init__()4.  其它 单下划线前缀的 ...

  3. DirectSound---输出设备基本操作(枚举、查询等)

    DirectSound是DirectX组件之一,提供了对音频设备的捕获和播放能力,同时它也是唯一几个支持Xp系统的音频技术之一. DirectSound主要有以下特点: 优点: 播放音频低延迟. 硬件 ...

  4. Linux常用命令之文件处理命令

    注:由于Linux操作系统有些目录不能轻易操作,特此建议大家在家目录home,或root.tmp目录下练习命令,以免带来不必要的损失 一.查询目录中的内容:ls 命令格式:ls [选项] [文件或目录 ...

  5. sort()没有返回值

    aList = [1,3,5,2,4] aList = aList.sort() print(aList) None

  6. 关于mybatis-generator的问题

    1.运行完mybatis-generator没有出现问题,但是代码看不到,出现这种东西: 你需要使用相对路径,如项目名+/src/main/java,就可以解决了 2.附录我的代码以供参考: < ...

  7. windows server,nginx安装,配置,运行nodeJS后端的web项目的实现,以及错误分析及解决方法

    一.安装nginx 下载windows版nginx (http://nginx.org/download/nginx-1.12.2.zip),之后解压到需要放置的位置(C:\nginx) 二.将Ngi ...

  8. Scrapy运行错误:ImportError: No module named win32api

    需要安装pypiwin32,直接通过官网安装exe会出现很多错误,所以直接运行以下命令: pip install pypiwin32

  9. Django_自带的admin管理页面

    Django的admin管理页面非常的好用,接下来就简单的说一下: 首先当你在pycharm中启动django服务端程序之后,在浏览器中输入地址就可以访问 当你输入默认的admin页面,,会弹出来下边 ...

  10. HDU2243 考研路茫茫――单词情结

    Description 背单词,始终是复习英语的重要环节.在荒废了3年大学生涯后,Lele也终于要开始背单词了. 一天,Lele在某本单词书上看到了一个根据词根来背单词的方法.比如"ab&q ...