10

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.

Alex
  • 321
  • 1
  • 5
  • 14
  • 1
    If you want the XSDs in the WSDL, you can modify the WCF service to "flatten" it. http://www.bing.com/search?q=Wcf+flatten+wsdl If you have no control over the WCF end, you can still build a WSDL that is monolithic and should work. But there are other, more serious problems with MSSOAP. – Cheeso Jun 17 '09 at 13:18

1 Answers1

15

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.

Community
  • 1
  • 1
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • @Cheeso: even in VBScript, XML should not be created via string concatenation. It should be created through MSXML, then the .xml property should be sent. – John Saunders Jun 03 '09 at 19:53
  • 1
    Good point, Absolutely agree. The right thing to do is to create a doc through the DOM. In this case I used a quick-n-dirty string to show just what is going on the wire. – Cheeso Jun 03 '09 at 19:56
  • @Cheeso: Good, but people copy these answers and use them as-is. We've got to be careful not to teach bad habits. OTOH you could add a "don't try this at home - use MSXML instead" comment before the string concat... – John Saunders Jun 03 '09 at 19:59
  • ok Jon, you convinced me. I updated the example to use the DOM. – Cheeso Jun 03 '09 at 20:23
  • @Cheeso: On the subject of bad habits another one is using 4.0 instead of 3.0 or 6.0. In this case I'd use 3.0 that'll work on any version of windows currently in support. – AnthonyWJones Jun 04 '09 at 08:49
  • Really? I am not at all clear on the rules about which version of MSXML to use. is there a relevant SO question? – Cheeso Jun 04 '09 at 13:04
  • I would even use a version agnostic approach by creating an "MSXML2.DOMDocument" and using features that are supported across versions, without requiring any specific version. – Paulo Santos Jun 04 '09 at 17:02
  • Yes, I started with that but it did not expose the setProxy method ! b – Cheeso Jun 04 '09 at 17:44
  • I'm trying to get this working, but can't get past this error: Microsoft VBScript runtime error: Object required: 'WScript', which happens on this line: Set requestDoc = WScript.CreateObject("MSXML2.DOMDocument.6.0") – Tone Mar 30 '10 at 18:46
  • It's possible you don't have MSXML6 installed. If so, convert that to "3.0" rather than "6.0". I'd advise you to get 6.0, though. See also the link "which version of MSXML should I use?" that I referenced: http://stackoverflow.com/questions/951804/which-version-of-msxml-should-i-use – Cheeso Mar 30 '10 at 18:54
  • `MSXML2.DOMDocument` always points to `MSXML2.DOMDocument.3.0`, i think. To use 4.0 and up, you must be explicit with the version number in the progID when calling `CreateObject()` –  Sep 12 '11 at 13:49