PDA

View Full Version : Solved: SOAP Action fails



stanl
05-16-2009, 03:12 AM
In a previous post (http://vbaexpress.com/forum/showthread.php?t=26650), I referenced how the Excel web services toolkit buils class code for SOAP. I decided to test going directly to the wdsl function as the class code is a bit verbose. The code below if modified for Winbatch or as vbscript in a .wsc file works... but fails on oSOAP.MSSoapInit2 in VBA. Why? Stan


sub getweather()
Dim oSOAP, cZip, c_WSDL_URL, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE, c_WSML
c_WSDL_URL = "http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl"
c_SERVICE = "Weather"
c_PORT = "WeatherSoap"
c_SERVICE_NAMESPACE = "http://ws.cdyne.com/WeatherWS/"
c_WSML = "<servicemapping>"
c_WSML = c_WSML & "<service name='Weather'>"
c_WSML = c_WSML & "<using PROGID='MSOSOAP.GenericCustomTypeMapper30' cachable='0' ID='GCTM'/>"
c_WSML = c_WSML & "<types>"
c_WSML = c_WSML & "<type name='ForecastReturn' targetNamespace='http://ws.cdyne.com/WeatherWS/' uses='GCTM' targetClassName='struct_ForecastReturn'/>"
c_WSML = c_WSML & "<type name='POP' targetNamespace='http://ws.cdyne.com/WeatherWS/' uses='GCTM' targetClassName='struct_POP'/>"
c_WSML = c_WSML & "<type name='WeatherDescription' targetNamespace='http://ws.cdyne.com/WeatherWS/' uses='GCTM' targetClassName='struct_WeatherDescription'/>"
c_WSML = c_WSML & "<type name='WeatherReturn' targetNamespace='http://ws.cdyne.com/WeatherWS/' uses='GCTM' targetClassName='struct_WeatherReturn'/>"
c_WSML = c_WSML & "<type name='temp' targetNamespace='http://ws.cdyne.com/WeatherWS/' uses='GCTM' targetClassName='struct_temp'/>"
c_WSML = c_WSML & "</types>"
c_WSML = c_WSML & "</service>"
c_WSML = c_WSML & "</servicemapping>"
Set oSOAP = New SoapClient30
oSOAP.MSSoapInit2 c_WSDL_URL, c_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE

cZip = "27603"
oNodeList = oSOAP.GetCityForecastByZIP(cZip)
Set oSOAP = Nothing
strXml = ""
For Each oNode In oNodeList
strXml = strXml & oNode.XML & vbCrLf
Next
Set oNode = Nothing
Set oNodeList = Nothing
MsgBox strXml
End Sub

Oorang
05-19-2009, 05:16 AM
It doesn't like being weakly typed. If you change the declaration to:
Dim oSOAP As MSOSOAPLib30.SoapClient30 It will get past that line. It will of course get stuck at the next line though:)

I used Web Services Tool Kit (http://www.microsoft.com/downloads/details.aspx?familyid=fa36018a-e1cf-48a3-9b35-169d819ecf18&displaylang=en) (VBE Add-In from MS) with http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl as the URL and got this code to work fine in Excel:
Sub Test()
Dim clsWthr As clsws_Weather
Dim xmlResult() As MSXML2.IXMLDOMSelection
Dim xmlNode As MSXML2.IXMLDOMNode
Dim strXML As String
Dim i As Long
Set clsWthr = New clsws_Weather
xmlResult = clsWthr.wsm_GetCityForecastByZIP("27603").ForecastResult
For i = 0 To UBound(xmlResult)
For Each xmlNode In xmlResult(i)
Debug.Print xmlNode.XML
Next
Debug.Print
Next
End Sub

stanl
05-19-2009, 06:28 AM
Right, the SOAP dll is set up to return a Nodelist and you are probably better off just reading the wdsl for the appropriate function/parameters and ignoring the verbose class code.

Of course just returning the node.xml gets you nothing - you actually want each nodeName, the text, and if haschildnodes() is true, recurse through those.

As an alternative to even using the SOAP dll, you could just package a SOAP envelope and send the request via WinHTTP. This will return the data as XML text rather than a nodelist, bit then you could process with a lightweight parser such as the free one from Chilkat.

I'll mark this solved... thank you for taking an interest. Stan

Oorang
05-19-2009, 08:27 AM
Just out of morbid curiosity what are intending to accomplish here?

stanl
05-19-2009, 10:40 AM
Just out of morbid curiosity what are intending to accomplish here?

As I mentioned in a thread previous to this, I was just looking for a refresher with SOAP.. the webservices toolkit is just one option, and as I discovered is arcane and verbose, and probably useless for any serious webservice activity.

I used the weather service because it was a free example and interested others could replicate any code. The serious work is in the parsing..

Hope your morbid curiosity is somewhat abated:think: Stan

Oorang
05-20-2009, 01:30 PM
I agree, the serious work is in the parsing:) That was why I was asking:)