Jump to content

SOAP Example


ptrex
 Share

Recommended Posts

@cloud9ine

this will get you going for the stock nodes.

$CollectionNodes = $oXmlDoc.SelectNodes("StockQuotes/Stock")

For $oNodes in $CollectionNodes
    $Symbol = $oNodes.SelectSingleNode("Symbol").text
    $Last = $oNodes.SelectSingleNode("Last").text
    $Date = $oNodes.SelectSingleNode("Date").text
    $Time = $oNodes.SelectSingleNode("Time").text
    $Change = $oNodes.SelectSingleNode("Change").text
    $Open = $oNodes.SelectSingleNode("Open").text
    $High = $oNodes.SelectSingleNode("High").text
    $Low  = $oNodes.SelectSingleNode("Low").text
    ConsoleWrite($Symbol & @CRLF & $Last & @CRLF & $Date & @CRLF & $Time & @CRLF & $Change & @CRLF & $Open & @CRLF & $High & @CRLF & $Low & @CRLF)
Next

regarding the weather Web Servive, without code it's hard to guess what's going on.

regards

ptrex

Link to comment
Share on other sites

ptrex,

Thanks for the help on that. I will use the same format to get my data out as well. Here is some code on the weather that I am doing.

CODE
Dim $oMyError, $xmlFile, $oNode, $strReturn, $objReq

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$xmlDoc= ObjCreate("Msxml2.DOMdocument.3.0")

$SOAPClient = ObjCreate("MSSOAP.SOAPClient")

$SOAPClient.mssoapinit ("http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl")

$strReturn = $SOAPClient.LatLonListCityNames("1234");

The LatLonList function is the simplest from http://www.weather.gov/xml/#use_it which is why I chose it to start.

The real function I will try will be ndfdgenbyday which has as its last parameter, an array of boolean variables. I am already getting a Type Mismatch with the above, however I use it. The guide page says the parameter is integer, but the schema defines it as a string. However I try, I still get a type mismatch.

Thanks for all the help.

Link to comment
Share on other sites

@cloud9ine

If you run this code then you get an error relating to the DISPLAY level.

Type conversion failure for element displayLevel

This means propably that it needs relating parameters which are not correctly set when launching the code.

Try filling in all parameters needed to get the output from the web service.

Regards

ptrex

Link to comment
Share on other sites

Thanks. Here is the sample soap request from the NDFD website

CODE
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<SOAP-ENV:Body>

<ns9309:LatLonListCityNames>

<displayLevel xsi:type="xsd:string">1</displayLevel>

</ns9309:LatLonListCityNames>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

I am pretty sure displayLevel is the only thing I need to pass but I think I am not passing it right. Is there a way to specify that the parameter I am specifying is the displayLevel? I am sure I did not miss any parameters.

Link to comment
Share on other sites

  • 10 months later...

Some one ask if someone would be nice enough to post how to do this with php so here is an example.

> Below is the code for the webservice server written in PHP

<?php
require('fns.system.php');
require('classes/nusoap.php'); // soap classes i use these so i do not need any extra c extensions on my linux server

// this function pulls data from a table in mysql
// i actually went to yahoo finance and pulled Google Stock History for this
// ## google stock history monthly
function getSOAPInfo($date) { // date format 2009-01-01 yyyy-mm-dd
  $db = dblink();
  if($sqlResult = mysql_query("SELECT * FROM googlestockhistory WHERE Date = '".$date."'")) {
    $sqlRows = mysql_numrows($sqlResult);
  } else {
    $sqlRows = 0;
  }
  
  if($sqlRows == 0 || $sqlRows != 1) {
    mysql_close($db);
    return 0.00;
  } else {
    $sqlRow = mysql_fetch_assoc($sqlResult);
    mysql_close($db);
    return $sqlRow['Close'];
  }  
}


// Call the nusoap class and create a soap server
$server = new soap_server();
// tell the server what we are called
$server->configureWSDL('stockserver', 'urn:stockquote');

$server->register("getSOAPInfo",
                  array('date' => 'xsd:string'),
                  array('return' => 'xsd:decimal'),
                  'urn:stockquote',
                  'urn:stockquote#getSOAPInfo');

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
                      ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

?>

> Now below here is the client querying the server

Dim $xmlDoc, $SOAPClient, $strReturn, $date
$date = InputBox("Enter the Date","Use the format 2008-mm-01 replacing the mm.")
$SOAPClient = ObjCreate("MSSOAP.SOAPClient")
$SOAPClient.mssoapinit("http://yourwebserver.com/webservice.php?wsdl")
$strReturn = $SOAPClient.getSOAPInfo($date)

MsgBox(0,"Answer", $strReturn)

I hope this helps someone. Just customize the code. This should be a good enough foundation for your other apps since it is mine.

Edited by tr1px
Link to comment
Share on other sites

  • 2 weeks later...

@tr1px

Thanks for the example.

Since the beginning of this post about SOAP (2007).

MS has done a lot of efforts to offer a good webservice framework, which is part of the DotNet framework.

This means you don't need anything additional if you have Windows & IIS.

Here is a simple example of a webservice, which you can use together with a SOAP client in AU3.

Save this in a file called WS_HelloWorld.asmx and copy it to a location on your IIS.

<%@ WebService Language="c#" Class="FirstWebService" %>

using System;
using System.Web;
using System.Web.Services;


public class FirstWebService {

      [WebMethod]

      public string HelloWorld(string lcName) {

        return "Hello World, " + lcName;     

      }

      [WebMethod]

      public decimal AddNumbers(decimal lnNumber1, decimal lnNumber2)   {

            return lnNumber1 + lnNumber2;
      }


      /*


      [WebMethod]

      public DateTime GetServerTime()     {

            return DateTime.Now;

      }  */
}

Next run the client to access the exposed objects over the web.

; http://www.w3schools.com/webservices/ws_example.asp

Dim $oMyError
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Dim $SOAPClient
$SOAPClient = ObjCreate("MSSOAP.SOAPClient30")


$SOAPClient.mssoapinit("http://localhost/Webservice/WS_HelloWorld.asmx?wsdl") 

If @error <> 0 then
    ConsoleWrite( $SOAPClient.faultString & @CRLF)
    ConsoleWrite( $SOAPClient.faultcode & @CRLF)
    ConsoleWrite( $SOAPClient.faultactor & @CRLF)
    ConsoleWrite( $SOAPClient.FaultCodeNamespace & @CRLF)
    ConsoleWrite( $SOAPClient.detail & @CRLF)
Endif

ConsoleWrite($SOAPClient.HelloWorld("Regards from AU3") & @CRLF)



If @error <> 0 then
    ConsoleWrite( $SOAPClient.faultString & @CRLF)
    ConsoleWrite( $SOAPClient.faultcode & @CRLF)
    ConsoleWrite( $SOAPClient.faultactor & @CRLF)
    ConsoleWrite( $SOAPClient.FaultCodeNamespace & @CRLF)
    ConsoleWrite( $SOAPClient.detail & @CRLF)
Endif

;This is COM error handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"COM Error Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1)  ; to check for after this function returns
Endfunc

This is all you need, quite simple compared to the SOAP 3.0 Toolkit approach.

Rgds,

ptrex

Edited by ptrex
Link to comment
Share on other sites

  • 2 months later...

@tr1px

Thanks for the example.

Since the beginning of this post about SOAP (2007).

MS has done a lot of efforts to offer a good webservice framework, which is part of the DotNet framework.

This means you don't need anything additional if you have Windows & IIS.

@ptrex

I'm attempting to connect and get results from the EU VAT web service to check VAT numbers.

It's located here: http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl

I'm using your great example with SOAPClient30. At least it's not too complex anymore for me :D

But I keep on getting COM errors that the parameters are incorrect.

This is what I'm doing:

Dim $SOAPClient
$SOAPClient = ObjCreate("MSSOAP.SOAPClient30")
$SOAPClient.mssoapinit("http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl", "", "", "")
ConsoleWrite($SOAPClient.CheckVat('GB', '0000000000'))  ;this is the VAT number to be checked whether it's valid

I checked the WSDL file and it looks like it asks for 2 string parameters: countryCode and vatNumber

Do you have an idea what's wrong?

Link to comment
Share on other sites

@bonzo

This is the error that comes back when trying your code :

Client:Incorrect number of parameters supplied for SOAP request HRESULT=0x80070057: The parameter is incorrect.

- Client:Unspecified client error. HRESULT=0x80070057: The parameter is incorrect.

I did a quick look on Google and there seem to many people suffering with the same problem using this webservice.

So I am not sure how reliable this is ?

If you find the solution let us know.

Rgds,

ptrex

Link to comment
Share on other sites

@bonzo

This is the error that comes back when trying your code :

I did a quick look on Google and there seem to many people suffering with the same problem using this webservice.

So I am not sure how reliable this is ?

If you find the solution let us know.

Rgds,

ptrex

I noticed the problems that others have too. It looks like the wsdl is too complex? One function even asks for 21 parameters. But some managed to write a client under asp/php.

Thanks for your findings, I'll research further how to tackle this one.

Link to comment
Share on other sites

  • 4 months later...

I notice that all the SOAP client examples in this thread are based on Microsoft's "soap toolkit". MSSOAP.SOAPClient, MSOSoap.SoapSerializer30, MSOSOAP.SoapReader30, all of that is SOAP toolkit. Which unfortunately has been obsolete for many years now. I have working examples that are not based on the soap toolkit, but they are ugly - adapted from vbscript samples with a hand-built soap envelope.

Does anybody have soap client examples not based on SOAP toolkit?

Link to comment
Share on other sites

  • 10 months later...

I believe I am doing something incorrectly, when I run the client .exe, it says to "input a new value here." The default is 10, and when I hit ok, I recieve, "The Sales Tax is : " and its just blank. I have SOAP.asp in the root of my webserver, and if I try to load it in a browser I simply get

"An error occurred on the server when processing the URL. Please contact the system administrator.

If you are the system administrator please click here to find out more about this error."

I believe im just being really dumb, but any help? thanks

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 month later...

Hmm...would be nice to have a web service/server done or integrated with AutoIt standalone w/o need of web server stuff (e.g. IIS, ASP, ASP.NET, PHP, etc.). But that likely isn't possible unless there is a COM server version of SOAP, XML-RPC, HTTP, etc.

Next best alternative, at least for those who use AutoIt just for GUI automation, would be to use some other platform that has standalone web services/server support (.NET, Perl, Java, Python, Ruby, etc.) and call AutoIt from there (via COM, DLL call, or shell execute).

By the way, what I mean by this usage is to drive AutoIt functionality as a server rather than a client. A client makes call to AutoIt server (over web service) to make AutoIt do something. For example, GUI automation, though other people may have other things in mind besides that.

Edited by daluu
Link to comment
Share on other sites

  • 2 years later...

This is a great topic. i recently created a client/server tool the only thing that was lacking was the server. As i relied on windows file sharing to deliver content from and to the client - there was no server side autoit tool listening for any requests. However this implementation doesn't scale very well. My next milestone would be to do this over SOAP/HTML/XMLHTTP/SUGGESTIONS???. As a prior poster commented it would be nice to do away with the need for server side utilities like PHP/IIS. Perhaps a compiled autoit app that was listening on a TCP port (server side) then have the clients connect to this TCP port?

Does anyone have an article that mentions why SOAP is no longer supported? Maybe I read it wrong but I have been hearing about SOAP for a long time!

Edited by vortexed
Link to comment
Share on other sites

  • 10 months later...

I am trying to connect with my shipping company API to get some information about my shipping. They provide documentation with examples written in PHP. Please take a look into script I got now:

<?php

$wsKey = '02f7skdzL6IU84PLHPOuiiNa1KAg1KC3';

$params = array(
        'wsKey' => $wsKey,
        'NumeryPrzesylek' => array('226340656'));
$wsdl = "http://kurier.k-ex.pl/api/ws_soap.php?wsdl";
$client = new SoapClient($wsdl);
$result = $client->PobierzDaneTrackingowe($params);
$status = $result->DaneTrackingoweLista->DaneTrackingowe->Status;
echo $status

?>

This code connect with API using my unique key ($wsKey) with their server ($wsdl). It will return information about shipping numer 236340646. I want to get same results with AutoIt as I am more familiar with this envoirment than PHP. Anyone has any idea?

Edited by maniootek
Link to comment
Share on other sites

  • 3 months later...

I tried your code

Dim $oMyError, $xmlFile, $oNode, $strReturn, $objReq

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$xmlDoc= ObjCreate("Msxml2.DOMdocument.3.0")

$SOAPClient = objcreate("MSSOAP.SOAPClient")
$SOAPClient.mssoapinit ("<a href='http://www.webservicex.net/stockquote.asmx?WSDL' class='bbc_url' title='External link' rel='nofollow external'>http://www.webservicex.net/stockquote.asmx?WSDL"</a>)
$strReturn = $SOAPClient.GetQuote("MSFT")

ConsoleWrite( "MSFT : " & $strReturn & @CRLF & @CRLF)

$xmlDoc.loadXML ($strReturn)

$oNode = $xmlDoc.selectSingleNode("StockQuotes")
ConsoleWrite($oNode.text & @CRLF & @CRLF)

;This is COM error handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"COM Error Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1)  ; to check for after this function returns
Endfunc

and received few errors (see attachments)

Any idea what's wrong? Did I miss to install anything?

post-51823-0-04816000-1427456574.png

post-51823-0-60926300-1427456577_thumb.p

post-51823-0-07615500-1427456581_thumb.p

post-51823-0-89130300-1427456584.png

Edited by maniootek
Link to comment
Share on other sites

@maniootek,

First of all this is an old post, +5 years old :(

The consequence is that the Web Services technology has evolved quite a lot in the meantime.

Regarding your issues. In order to run your example you need the SOAP.CLIENT library installed from MS called SOAP Toolkit 3.0

Which they have depreciated but still works for simple examples.

I guess the latest version is here http://www.microsoft.com/en-us/download/details.aspx?id=15489

You need to download and install it first.

This worked still for me after so many year ;)

#AutoIt3Wrapper_UseX64=N
#include <Array.au3>
 
Local $oMyError
Local $Return1, $Return2, $Return3
Local $Rates[5] = ["EUR","USD","CAD","AUD", "ZAR"]
 
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
 
$SOAPClient = ObjCreate("MSSOAP.SoapClient30")
$SOAPClient.mssoapinit("http://www.webservicex.net/CurrencyConvertor.asmx?wsdl")
 
If @error <> 0 then
    ConsoleWrite( $SOAPClient.faultString & @CRLF)
ConsoleWrite( $SOAPClient.faultcode & @CRLF)
ConsoleWrite( $SOAPClient.faultactor & @CRLF)
ConsoleWrite( $SOAPClient.FaultCodeNamespace & @CRLF)
    ConsoleWrite( $SOAPClient.detail & @CRLF)
Endif
 
$Return1 = $SOAPClient.ConversionRate($Rates[0],$Rates[1])
$Return2 = $SOAPClient.ConversionRate($Rates[0],$Rates[2])
$Return3 = $SOAPClient.ConversionRate($Rates[0],$Rates[3])
$Return4 = $SOAPClient.ConversionRate($Rates[0],$Rates[4])
 
If @error <> 0 then
    ConsoleWrite( $SOAPClient.faultString & @CRLF)
ConsoleWrite( $SOAPClient.faultcode & @CRLF)
ConsoleWrite( $SOAPClient.faultactor & @CRLF)
ConsoleWrite( $SOAPClient.FaultCodeNamespace & @CRLF)
    ConsoleWrite( $SOAPClient.detail & @CRLF)
Endif
 
ConsoleWrite(@CRLF)
ConsoleWrite("EUR / USD = " & 1 / $Return1 & @CRLF & @CRLF)
ConsoleWrite("EUR / CAD = " & 1 / $Return2 & @CRLF & @CRLF)
ConsoleWrite("EUR / AUD = " & 1 / $Return3 & @CRLF & @CRLF)
ConsoleWrite("EUR / ZAR = " & 1 / $Return4 & @CRLF & @CRLF)
 
;This is COM error handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"COM Error Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
"err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
"err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: "         & @TAB & $HexNumber              & @CRLF & _
"err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
"err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
"err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
"err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
"err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
)
  SetError(1)  ; to check for after this function returns
Endfunc
Link to comment
Share on other sites

@all

Better is to switch over the plain XML Soap Envelopes instead.

This is a working example :

#AutoIt3Wrapper_UseX64=N
 
local $objHTTP
local $strEnvelope
local $strReturn
local $objReturn
local $strQuery
local $strValue
 
$strValue = InputBox("Testing", "Enter your new value here.", 60007)
 
; Initialize COM error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
 
$objHTTP = ObjCreate("Microsoft.XMLHTTP")
$objReturn = ObjCreate("Msxml2.DOMDocument.3.0")
 
; Create the SOAP Envelope
$strEnvelope = '<?xml version="1.0" encoding="utf-8"?>' & _
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' & _
'<soap:Body>' & _
'<GetInfoByZIP xmlns="http://www.webserviceX.NET">' & _
'<USZip>'&$strValue&'</USZip>' & _
'</GetInfoByZIP>' & _
'</soap:Body>' & _
'</soap:Envelope>'
 
; Set up to post to the server
$objHTTP.open ("post", "http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP", False)
 
; Set a standard SOAP/ XML header for the content-type
$objHTTP.setRequestHeader ("Content-Type", "text/xml")
 
 
ConsoleWrite("Content of the Soap envelope : "& @CR & $strEnvelope & @CR & @CR)
 
; Make the SOAP call
$objHTTP.send ($strEnvelope)
 
; Get the return envelope
$strReturn = $objHTTP.responseText
 
ConsoleWrite("-----------" & @CRLF)
ConsoleWrite ("Debug Response : "& @CR & $strReturn & @CR & @CR)
ConsoleWrite("-----------" & @CRLF)
 
; Load the return envelope into a DOM
$objReturn.loadXML ($strReturn)
 
ConsoleWrite("Return of the SOAP Msg : " & @CR & @CR & $objReturn.XML & @CR & @CR)
 
; Query the return envelope
$strQuery = "SOAP:Envelope/SOAP:Body"
 
$objReturn.selectSingleNode($strQuery)
 
$Soap = $objReturn.Text
 
MsgBox(0,"SOAP Response","The Response is  : " & $Soap)
 
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"COM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
"err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
"err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: "         & @TAB & $HexNumber              & @CRLF & _
"err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
"err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
"err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
"err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
"err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
)
  SetError(1)
Endfunc

Hope this helps

rgds

ptrex

Edited by ptrex
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...