项目中经常需要调用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. docker with flannel

    ** 原创文章,请勿转载 ** docker的单host,多container环境下,是使用host的docker0网桥进行通信的.如果跨host, container之间要通信怎么办呢?答案是fla ...

  2. 【数论】Lucas

    就是个Lucas 对于质数p,有C(n,m)=C(n/p,m/p)*C(n%p,m%p)%p 代码 ll C(ll a,ll b) { ; ; if(a<p&&b<p) r ...

  3. Windows程序设计笔记(二) 关于编写简单窗口程序中的几点疑惑

    在编写窗口程序时主要是5个步骤,创建窗口类.注册窗口类.创建窗口.显示窗口.消息环的编写.对于这5个步骤为何要这样写,当初我不是太理解,学习到现在有些问题我基本上已经找到了答案,同时对于Windows ...

  4. 【转载】LINUX上MYSQL优化三板斧

    现在MySQL运行的大部分环境都是在Linux上的,如何在Linux操作系统上根据MySQL进行优化,我们这里给出一些通用简单的策略.这些方法都有助于改进MySQL的性能. 闲话少说,进入正题. 一. ...

  5. sql servel 报错:将 expression 转换为数据类型 int 时出现算术溢出错误。

    执行sql语句:SELECT   AVG( DATEDIFF(s,s.CreatedDate,s.SendDate)  ) AS submitTime FROM dbo.SmsSend AS s    ...

  6. 2017广东工业大学程序设计竞赛初赛 题解&源码(A,水 B,数学 C,二分 D,枚举 E,dp F,思维题 G,字符串处理 H,枚举)

    Problem A: An easy problem Description Peter Manson owned a small house in an obscure street. It was ...

  7. Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】

    J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...

  8. flume1.8 基础架构介绍(一)

    1. 系统要求 1. Java运行环境 -- Java 1.8及以上 2. 内存 -- 足够的内存供配置的sources,channels 或者sinks使用 3. 硬盘空间 -- 足够的硬盘空间供配 ...

  9. Result Maps collection does not contain value for com.man.impet.dao.OrderBeanMapper.map

    由于mapper.xml中resultMap = "map"  改为 resultType="map"即可,折腾了一下午

  10. 利用object.defineProperty实现数据与视图绑定

    如今比较火的mvvm框架,例如vue就是利用es5的defineProperty来实现数据与视图绑定的,下面我来介绍一下defineProperty的用法. var people= {} Object ...