
项目中频繁需要调用Webservice进行验证检测soapui调用wsdl需要安全验证,下面就介绍下怎样使用检测软件SoapUI调用Vsphere vcenter的 Web Service
VSphere的Webservice地址默认为
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>[email protected]</urn:userName> <urn:password>密码</urn:password> <!--Optional:--> <urn:locale>?</urn:locale> </urn:Login> </soapenv:Body> </soapenv:Envelope>

View Code
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>
View Code

注意:需要记录response中的header信息,用于前面设置header,我这儿的header信息如下
Set-Cookie vmware_soap_session="52f2ce6a-8ce9-94cc-bd62-3f750d61cd4f"; Path=/; HttpOnly; Secure;
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>

View Code
注意上面xml中<urn:_this type="SearchIndex">SearchIndex</urn:_this>红色字体是按照文档中的定义填写的
然后添加headersoapui调用wsdl需要安全验证,作为认证信息,此处的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>
View Code
如果你设置的Header不对,那么系统将会报错:
faultstring:The session is not authenticated
参考:
soapUI: faultstring: The session is not authenticated
使用SoapUI调用Vsphere Web Service
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-140910-1.html
宋茜全程似发脾气的女鬼
脓包穿孔不是坏事