Calling a WCF Service Using VBScript

There is a WCF service with the 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 should 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 the script starts, this error appears:

Client: WSDLReader: could not parse the WSDL file HRESULT = 0x8 0004005 - WSDLReader: Service initialization failed HRESULT = 0x80004005 - WSDL service: Initialization of the port for MyService failed HRESULT = 0x80004005 - WSDLPort: analysis of the binding information for the Basic_ BasicTypper_support = 0 <b> Basic_Support = Reference_Support = 0 = Basic_Support = 0x8bvice - WSDLPort: operation for the port BasicHttpBinding_IMyService cannot be initialized HRESULT = 0x8000 4005 - WSDLOperation: operation // def: portType [@ name = "IMyService"] / def: operation [@ name = "MyMethod"] was not found in the porttype HRESULT section = 0x80004005

What is going wrong? Please, help.

Edit:

Thank you, Chiso, for the answer. The problem with MSSOAP is that it requires all xsd schemas to be included in the line in the generated WSDL file. WCF does not do this by default.

+10
vbscript wcf msxml
Jun 03 '09 at 14:08
source share
1 answer

Do not use MSSOAP. I think this is not supported now, the last 3 or 4 years. Consider using XmlHttp, which is part of MSXML, and is supported and continues to be supported. You will need to create the SOAP envelope manually. But it is more reliable.

code example

 ' 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 for how to select the version of MSXML.

+15
Jun 03 '09 at 19:48
source share



All Articles