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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21428711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:36:38  来源:igfitidea点击:

VBA Calling WSDL simple method with 1 parameter XMLHTTP

web-servicesvbawsdl

提问by user3219009

I need some help Calling a wsdl web service function. The WSDL have one function named "Bye" that is waiting for 1 parameter of a type String. Then it gives back a type of string text. How can is make the call under VBA

我需要一些帮助 调用 wsdl Web 服务功能。WSDL 有一个名为“Bye”的函数,它正在等待字符串类型的 1 个参数。然后它返回一种字符串文本。如何在VBA下拨打电话

I can call it with a prebuilded XML that i send, but it gives me an XML in return. There has to be a simpler way for this.

我可以用我发送的预构建 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

'Here i can call it with the XML and get an XML Dim XMLHTTP As New MSXML2.XMLHTTP XMLHTTP.Open "POST", "httx://webpage:8080/something/services/ByeService", False XMLHTTP.setRequestHeader "Content-Type", "text/xml" XMLHTTP.setRequestHeader "SOAPAction", "urn:MatrixService" XMLHTTP.send requestDoc MsgBox XMLHTTP.responseText

'在这里我可以用 XML 调用它并得到一个 XML Dim XMLHTTP As New MSXML2.XMLHTTP XMLHTTP.Open "POST", "httx://webpage:8080/something/services/ByeService", False XMLHTTP.setRequestHeader "Content- Type", "text/xml" XMLHTTP.setRequestHeader "SOAPAction", "urn:MatrixService" XMLHTTP.send requestDoc MsgBox XMLHTTP.responseText

回答by Jér?me Teisseire

you could try :

你可以试试:

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