Вызов сервиса WCF VBScript

Здесь обсуждается тема встроенного умножения против Math.pow

Очевидно, Math.pow медленнее, но не намного ...

10
задан Alex 5 June 2009 в 07:56
поделиться

1 ответ

Не использовать MSSOAP. Я думаю, что он не поддерживается сейчас, последние 3 или 4 года. Рассмотрите возможность использования XmlHttp, который является частью MSXML, который поддерживается и продолжает поддерживаться. Вам нужно будет создать конверт SOAP вручную. Но так надежнее.

пример кода

' URL to the WCF service'
url= "http://server:port/Wcf.Service.Address"

Dim requestDoc
Set requestDoc = WScript.CreateObject("MSXML2.DOMDocument.6.0")

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, "Register", "urn:Your.Namespace.Here")
nodeBody.appendChild nodeOp

Dim nodeRequest
Set nodeRequest = requestDoc.createNode(1, "request", "urn:Your.Namespace.Here")
'content of the request will vary depending on the WCF Service.'
' This one takes just a plain string. '
nodeRequest.text = "Hello from a VBScript client."

nodeOp.appendChild nodeRequest

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


'the request will look like this:'
'       <s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> '
'         <s:Body> '
'           <Register xmlns='urn:Your.Namespace.Here'> '
'               <request>hello from a VBScript client.</request> '
'           </Register> '
'         </s:Body> '
'       </s:Envelope>'


WSCript.Echo  "sending request " & vbcrlf & requestDoc.xml


dim xmlhttp

set xmlhttp = WScript.CreateObject("MSXML2.ServerXMLHTTP.6.0")
' set the proxy as necessary and desired '
xmlhttp.setProxy 2, "http://localhost:8888"
xmlhttp.Open "POST", url, False
xmlhttp.setRequestHeader "Content-Type", "text/xml"
' set SOAPAction as appropriate for the operation '
xmlhttp.setRequestHeader "SOAPAction", "urn:Set.As.Appropriate"
xmlhttp.send requestDoc.xml

WScript.Echo vbcrlf & "Raw XML response:" & vbcrlf 
WSCript.Echo  xmlhttp.responseXML.xml

dim response
set response= xmlhttp.responseXML
'the response is an MSXML2.DOMDocument.6.0' 
'party on the response here - XPath, walk the DOM, etc. '

FYI: см. which-version-of-msxml-should-i-use , чтобы узнать, как выбрать версию MSXML.

15
ответ дан 3 December 2019 в 22:38
поделиться
Другие вопросы по тегам:

Похожие вопросы: