WebService错误使用SOAP从VBA调用Web服务

时间:2016-05-23 12:49:22

标签: xml excel-vba soap vba excel

尝试使用SOAP通过VBA执行Web服务调用时收到Web服务错误。 XML输出和VBA代码如下。如果有人能告知VBA代码中是否有任何明显错误,我将不胜感激。

XML

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"        xmlns:prag="http://www.pragmaticsw.com/">
<soap:Body>
  <prag:Bugs_LoadByCriteria>
     <prag:AuthenticationData>
        <prag:AppCode>agSP</prag:AppCode>
        <prag:DeptId>81842</prag:DeptId>
        <prag:ProjId>92553</prag:ProjId>
        <prag:UserId>147280</prag:UserId>
        <prag:PassCode>Password1</prag:PassCode>
     </prag:AuthenticationData>
     <prag:Condition><![CDATA[<Conditions     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema' Operation='opLIKE'>
<Items Type='tField'> 
  <Value xsi:type='xsd:string'>Custom17</Value> 
</Items> 
<Items Type='tString'> 
  <Value xsi:type='xsd:string'>SIT5</Value> 
</Items> 
</Conditions>]]></prag:Condition>
  </prag:Bugs_LoadByCriteria>
 </soap:Body>
</soap:Envelope>

VBA:

Sub login()

Dim responseText As String
Dim sURL As String
Dim sEnv As String
Dim xmlhtp As New MSXML2.XMLHTTP
Dim xmlDoc As New DOMDocument
Dim webserviceSOAPActionNameSpace

sURL = "http://soap.qacomplete.smartbear.com/psWS.asmx"

sEnv = "<?xml version =""1.0"" encoding=""utf-8""?>"
sEnv = sEnv & "<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-    envelope"" xmlns:prag=""http://www.pragmaticsw.com/"">"
sEnv = sEnv & "<soap:Body>"
sEnv = sEnv & "<prag:Bugs_LoadByCriteria>"
sEnv = sEnv & "<prag:AuthenticationData>"
sEnv = sEnv & "<prag:AppCode>agSP</prag:AppCode>"
sEnv = sEnv & "<prag:DeptId>81842</prag:DeptId>"
sEnv = sEnv & "<prag:ProjId>92553</prag:ProjId>"
sEnv = sEnv & "<prag:UserId>147280</prag:UserId>"
sEnv = sEnv & "<prag:PassCode>Password1</prag:PassCode>"
sEnv = sEnv & "</prag:AuthenticationData>"
sEnv = sEnv & "<prag:Condition><![CDATA[<Conditions     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
sEnv = sEnv & "xmlns:xsd='http://www.w3.org/2001/XMLSchema'    Operation='opLIKE'>"
sEnv = sEnv & "<Items Type='tField'>"
sEnv = sEnv & "<Value xsi:type='xsd:string'>Custom17</Value>"
sEnv = sEnv & "</Items>"
sEnv = sEnv & "<Items Type='tString'>"
sEnv = sEnv & "<Value xsi:type='xsd:string'>SIT4</Value>"
sEnv = sEnv & "</Items>"
sEnv = sEnv & "</Conditions>]]></prag:Condition>"
sEnv = sEnv & "</prag:Bugs_LoadByCriteria>"
sEnv = sEnv & "</soap:Body>"
sEnv = sEnv & "</soap:Envelope>"

With xmlhtp

webserviceSOAPActionNameSpace = "http://www.pragmaticsw.com/"

    .Open "POST", sURL, False

    .setRequestHeader "post", "http://soap.qacomplete.smartbear.com/psWS.asmx HTTP/1.1"
    .setRequestHeader "Content-Type", "application/soap+xml; charset=UTF-8"
    .setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "Bugs_LoadByCriteria"

    .send sEnv
    xmlDoc.LoadXML .responseText
    MsgBox .responseText

End With

End Sub

1 个答案:

答案 0 :(得分:0)

回答了我自己的疑问。我通过SoapUI将sEnv内容发送到Web服务并收到相同的内部Web服务错误。逐步检查生成的xml数据格式,找到一个不应该存在的额外空间。