Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

Calling WCF service by VBScript

There is a WCF service with configuration:

<services>
  <service name="MyService" behaviorConfiguration="MyServiceBehavior">
    <endpoint 
      binding="basicHttpBinding"  
      contract="IMyService" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8001/MyService" />
      </baseAddresses>
    </host>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpGetEnabled="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>

This script is supposed to call it:

Option Explicit

Dim soapClient
Dim serviceUri
Dim serviceName
Dim portName
Dim result

serviceUri = "http://localhost:8001/MyService"
serviceName = "MyService"
portName = "BasicHttpBinding_IMyService"

Set soapClient = CreateObject("MSSOAP.soapClient")
soapClient.ClientProperty("ServerHTTPRequest") = True
soapClient.mssoapinit serviceUri & "?WSDL", serviceName, portName

When running the script this error appears:

Client: WSDLReader:Analyzing the WSDL file failed HRESULT=0x8 0004005 - WSDLReader:Initialization of service failed HRESULT=0x80004005 - WSDL Service:Initialization of the port for service MyService failed HRESULT =0x80004005 - WSDLPort:Analyzing the binding information for port BasicHttpBinding_IMyService failed HRESULT=0x80004005 - WSDLPort:An operation for port BasicHttpBinding_IMyService could not be initialized HRESULT=0x8000 4005 - WSDLOperation:The operation //def:portType[@name="IMyService"]/ def:operation[@name="MyMethod"] was not found in the porttype section HRESULT=0x80004005

What is going wrong? Please, help.

Edit:

Thank you, Cheeso, for the answer. The problem with the MSSOAP appears to be that it requires all xsd schemas to be included inline in the generated WSDL file. WCF doesn't do it by default.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Don't use MSSOAP. I think it is out of support now, for the past 3 or 4 years. Consider using the XmlHttp, which is part of MSXML, and is supported and continues to be maintained. You will have to construct a SOAP envelope manually. But it's more reliable this way.

example code

' 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: See which-version-of-msxml-should-i-use to learn how to select a version of MSXML.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...