Web Services VBA使用1个参数XMLHTTP调用WSDL简单方法

kmpatx3s  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(164)

我需要一些帮助来调用wsdl web服务函数。WSDL有一个名为“Bye”的函数,它正在等待一个字符串类型的参数。然后它返回一个字符串类型的文本。如何在VBA下进行调用
我可以用我发送的一个预先构建的XML来调用它,但是它返回给我一个XML。

Dim URL As String
URL = "httx://webpage:8080/something/services/ByeService"

Dim requestDoc As New MSXML2.DOMDocument60

Dim root
Set root = requestDoc.createNode(1, "Envelope", "http://schemas.xmlsoap.org/soap/envelope/")
requestDoc.appendChild root

Dim nodeBody
Set nodeBody = requestDoc.createNode(1, "Body", "http://schemas.xmlsoap.org/soap/envelope/")
root.appendChild nodeBody

'Dim nodeOp
Set nodeOp = requestDoc.createNode(1, "Bye", "urn:MatrixService")
nodeBody.appendChild nodeOp

Dim nodeRequest
Set nodeRequest = requestDoc.createNode(1, "Bye", "urn:MatrixService")
'content of the request will vary depending on the WCF Service.'
' This one takes just a string. '
nodeRequest.Text = "This is a string to say goodbye"

nodeOp.appendChild nodeRequest

Set nodeRequest = Nothing
Set nodeOp = Nothing
Set nodeBody = Nothing
Set root = Nothing

'在这里,我可以用XML调用它,并获得一个XML Dim XMLHTTP作为新的MSXML2.XMLHTTP XMLHTTP。打开“POST”,“http://网页:8080/something/services/ByeService”,假XMLHTTP。设置请求头“内容类型”,“文本/xml”XMLHTTP。设置请求头“SOAPAction”,“urn:MatrixService”XMLHTTP。发送请求文档MsgBox XMLHTTP。响应文本

dgtucam1

dgtucam11#

您可以尝试:

Set objXML = CreateObject("MSXML2.XMLHTTP")
strURL = "httx://webpage:8080/something/services/ByeService"
objXML.Open "POST", strURL, False
objXML.setRequestHeader "content-type", "text/xml"
objXML.setRequestHeader "SOAPAction", "urn:MatrixService"
objXML.Send "Bye" 

strResult = objXML.ResponseText

相关问题