views:

1798

answers:

3

Hi,

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.

+6  A: 

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/'&gt; '
'         <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.

Cheeso
@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
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
@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
ok Jon, you convinced me. I updated the example to use the DOM.
Cheeso
@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
Really? I am not at all clear on the rules about which version of MSXML to use. is there a relevant SO question?
Cheeso
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
Yes, I started with that but it did not expose the setProxy method ! b
Cheeso
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
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
A: 

I tried this. But it does not work. Any idea why???

tried what? maybe you need to post a new question.
Cheeso
A: 

Hi Cheeso, we are getting an 400/bad Request when we send a request. Please find our code below.

Public Sub test123() URL = "http://dev1.xxxxx.employer/employer/v02/Employer.svc"

Dim requestDoc Set requestDoc = CreateObject("MSXML2.DOMDocument.3.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", "http://xxxxx.com/Employer/Contracts/v2") nodeBody.appendChild nodeOp

Dim nodeRequest Set nodeRequest = requestDoc.createNode(1, "request", "http://xxxxx.com/Employer/Contracts/v2")

'content of the request will vary depending on the WCF Service.'

' This one takes just a plain string. '

Dim sv_strTempxml As Variant sv_strTempxml1 = "" _ & "0707 NS2 DEV1 KRISH 001" _ & "Alexander City" _ & "US111 Main Street35010" _ & "ALSTPL" _ & "1000001" _ & "100" _ & "100018" _ & "0707 NS2 DEV1 KRISH 0011" _ & "" _ & "UUS"

nodeRequest.Text = sv_strTempxml1 nodeOp.appendChild nodeRequest

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

'MsgBox "sending request " & vbCrLf & requestDoc.XML

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.3.0") ' set the proxy as necessary and desired ' 'xmlhttp.setProxy 2, "http://localhost:8888" xmlhttp.Open "POST", URL, False ' set SOAPAction as appropriate for the operation ' xmlhttp.setRequestHeader "SOAPAction", "http://xxxxx.com/Employer/Contracts/v2/Employer/CreateProspect" xmlhttp.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8" xmlhttp.send requestDoc.XML ' vbCrLf & "Raw XML response:" & vbCrLf MsgBox xmlhttp.responseXML.XML

End Sub

is there any item we have missed out

Santhosh