Consulting

Results 1 to 6 of 6

Thread: Solved: SOAP Action fails

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Solved: SOAP Action fails

    In a previous post, 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

    [vba]
    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

    [/vba]

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    It doesn't like being weakly typed. If you change the declaration to:
    [vba]Dim oSOAP As MSOSOAPLib30.SoapClient30[/vba] It will get past that line. It will of course get stuck at the next line though

    I used Web Services Tool Kit (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:
    [vba]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[/vba]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  4. #4
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Just out of morbid curiosity what are intending to accomplish here?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Oorang
    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 Stan

  6. #6
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    I agree, the serious work is in the parsing That was why I was asking
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •