Jump to content

SOAP Example


ptrex
 Share

Recommended Posts

Simple SOAP Example

For those who don't know what SOAP (Simple Object Access Protocol) is.

SOAP is a simple XML-based protocol to let applications exchange information over HTTP, and is platform independend.

An advantage of SOAP is that program calls are much more likely to get through firewall servers that screen out requests other

than those for known applications (through the designated port mechanism). Since HTTP requests are usually allowed through

firewalls, programs using SOAP to communicate can be sure that they can communicate with programs anywhere.

In this SOAP example, you will learn what SOAP is, and how it uses XML to exchange information between applications.

The next step will be, how to turn AU3 into a Web Services server.

This is the SOAP CLIENT

Dim $objHTTP
Dim $strEnvelope
Dim $strReturn
Dim $objReturn
Dim $dblTax
Dim $strQuery
Dim $value

$value = InputBox("Testing", "Enter your new value here.", 10)

; Initialize COM error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objHTTP = ObjCreate("Microsoft.XMLHTTP")
$objReturn = ObjCreate("Msxml2.DOMdocument.3.0")

; Create the SOAP Envelope
$strEnvelope = "<soap:envelope xmlns:soap=""urn:schemas-xmlsoap-org:soap.v1"">" & _
"<soap:header></soap:header>" & _
"<soap:body>" & _
"<m:getsalestax xmlns:m=""urn:myserver/soap:TaxCalculator"">" & _
"<salestotal>"&$value&"</salestotal>" & _
"</m:getsalestax>" & _
"</soap:body>" & _
"</soap:envelope>"

; Set up to post to our local server
$objHTTP.open ("post", "http://localhost/soap.asp", False)

; Set a standard SOAP/ XML header for the content-type
$objHTTP.setRequestHeader ("Content-Type", "text/xml")

; Set a header for the method to be called
$objHTTP.setRequestHeader ("SOAPMethodName", "urn:myserver/soap:TaxCalculator#getsalestax")

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("Debug : "& $strReturn & @CR & @CR)

; Load the return envelope into a DOM
$objReturn.loadXML ($strReturn)

ConsoleWrite("Return of the SOAP Msg : " & @CR & $objReturn.XML & @CR & @CR)

; Query the return envelope
$strQuery = "SOAP:Envelope/SOAP:Body/m:getsalestaxresponse/salestax"

$dblTax = $objReturn.selectSingleNode($strQuery)
$Soap = $objReturn.Text

MsgBox(0,"SOAP Response","The Sales Tax 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) ; to check for after this function returns
Endfunc

This is the SOAP SERVER

<%
Dim oNode

Set objReq = Server.CreateObject("Msxml2.DOMdocument.3.0")

'Load the request into XML DOM
objReq.Load Request

'Query the DOM for the input parameter
' Remember: xpath is case sensitive. "SalesTotal" is not the same as "salestotal"
strQuery = "SOAP:Envelope/SOAP:Body/m:getsalestax/salestotal"

'varSalesTotal = objReq.SelectSingleNode(strQuery).Text
Set oNode = Nothing
Set oNode = objReq.SelectSingleNode(strQuery)
if not oNode is Nothing Then
varSalesTotal = oNode.Text
else
'handle the error - save the xml to a file so you can look at it
varSalesTotal = objReq.Text
end if

'Calculate the sales tax
varSalesTax = varSalesTotal * 0.04

'Prepare the return envelope
strTmp = _
"<soap:envelope xmlns:soap=""urn:schemas-xmlsoap-org:soap.v1"">" & _
"<soap:header></soap:header>" & _
"<soap:body>" & _
"<m:getsalestaxresponse xmlns:m=""urn:myserver/soap:Taxcalc"">" & _
"<salestax>" & varSalesTax & "</salestax>" & _
"</m:getsalestaxresponse>" & _
"</soap:body>" & _
"</soap:envelope>"

'Write the return envelope
Response.Write strTmp
%>

Save the SOAP SERVER as SOAP.asp and put it in the root of your IIS server.

Run the client and see what happenes.

Enjoy !!

Regards

ptrex

Edited by ptrex
Link to comment
Share on other sites

@all

OK this is an Example connecting to a Web Service collecting the MS stock information.

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.webservicex.net/stockquote.asmx?WSDL")
$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 
oÝ÷ Øg­XsJ)ߢ¹¶*'jëh×6Dim $oMyError
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

dim $SOAPClient
$SOAPClient = ObjCreate("MSSOAP.SOAPClient")

$SOAPClient.mssoapinit("http://www.webservicex.net/whois.asmx?wsdl") 
  if @error then
    ConsoleWrite( $SOAPClient.faultString)
    ConsoleWrite( $SOAPClient.detail)
  Endif
ConsoleWrite($SOAPClient.GetWhois("autoitscript.com"))
  if @error then
    ConsoleWrite($SOAPClient.faultString)
    ConsoleWrite($SOAPClient.detail)
  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
EndfuncoÝ÷ Ù8b²ÞÁ¶Ø§©e
§¶¸±«­¢+Ù¥´ÀÌØí½5åÉɽÈ(ÀÌØí½5åÉɽÈô=©Ù¹Ð ÅÕ½ÐíÕѽ%йÉɽÈÅÕ½Ðì°ÅÕ½Ðí5åÉÉÕ¹ÅÕ½Ðì¤()¥´ÀÌØíM=A
±¥¹Ð(ÀÌØíM=A
±¥¹Ðô=©
ÉÑ ÅÕ½Ðí5MM=@¹M=A
±¥¹ÐÅÕ½Ðì¤((ÀÌØíM=A
±¥¹Ð¹µÍͽÁ¥¹¥Ð ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹÝÍÉ٥๹н½Õ¹ÑÉä¹ÍµàýÝÍ°ÅÕ½Ðì¤(¥ÉɽÈÑ¡¸(
½¹Í½±]É¥Ñ ÀÌØíM=A
±¥¹Ð¹Õ±ÑMÑÉ¥¹¤(
½¹Í½±]É¥Ñ ÀÌØíM=A
±¥¹Ð¹Ñ¥°¤(¹¥)
½¹Í½±]É¥Ñ ÀÌØíM=A
±¥¹Ð¹Ñ
½Õ¹ÑÉ¥Ì ¤¤(¥ÉɽÈÑ¡¸(
½¹Í½±]É¥Ñ ÀÌØíM=A
±¥¹Ð¹Õ±ÑMÑÉ¥¹¤(
½¹Í½±]É¥Ñ ÀÌØíM=A
±¥¹Ð¹Ñ¥°¤(¹¥((íQ¡¥Ì¥Ì
=4Éɽȡ¹±È)Õ¹5åÉÉÕ¹ ¤(ÀÌØí!á9ÕµÈõ¡à ÀÌØí½5åÉɽȹ¹ÕµÈ°à¤(5ͽà À°ÅÕ½Ðí
=4ÉɽÈQÍÐÅÕ½Ðì°ÅÕ½Ðí]¥¹ÑÉÁÑ
=4ÉɽÈÌÌìÅÕ½ÐìµÀì
I1µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹÍÉ¥ÁÑ¥½¸¥ÌèÅÕ½ÐìµÀìQµÀìÀÌØí½5åÉɽȹÍÉ¥ÁÑ¥½¸µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹݥ¹ÍÉ¥ÁÑ¥½¸èÅÕ½ÐìµÀìQµÀìÀÌØí½5åÉɽȹݥ¹ÍÉ¥ÁÑ¥½¸µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ¹ÕµÈ¥ÌèÅÕ½ÐìµÀìQµÀìÀÌØí!á9յȵÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ±Íѱ±ÉɽȥÌèÅÕ½ÐìµÀìQµÀìÀÌØí½5åÉɽȹ±Íѱ±ÉɽȵÀì
I1µÀì|($$$ÅÕ½ÐíÉȹÍÉ¥Áѱ¥¹¥ÌèÅÕ½ÐìµÀìQµÀìÀÌØí½5åÉɽȹÍÉ¥Áѱ¥¹µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹͽÕÉ¥ÌèÅÕ½ÐìµÀìQµÀìÀÌØí½5åÉɽȹͽÕɵÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ¡±Á¥±¥ÌèÅÕ½ÐìµÀìQµÀìÀÌØí½5åÉɽȹ¡±Á¥±µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ¡±Á½¹ÑáÐ¥ÌèÅÕ½ÐìµÀìQµÀìÀÌØí½5åÉɽȹ¡±Á½¹ÑáÐ|($$$¤(MÑÉÉ½È Ä¤ìѼ¡¬½ÈÑÈÑ¡¥Ìչѥ½¸ÉÑÕɹÌ)¹Õ¹

Regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

@Apzo

Thanks !!

Do you have any idea yet for the AU3 server part

Yes I do, but I need to find the time to do some more testing.

I got the framework up and running but I did not get the Client to communicate with the server yet.

I'll be in touch when I got a hit.

Regards

ptrex

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 5 months later...

@Jazkal

I started using the Soap Toolkit

But I didn't put a lot effort in this because it has be declared obsolete by MS.

These days they only support .NET webservices. And this is a different ballgame.

There are other ways of making a webservice server as well using for instance PHP. But I never used that.

Maybe some others like "Toady" can guide us in the better direction on what the best tool to start using the Server Side Webservices.

Regards,

ptrex

Link to comment
Share on other sites

Thanks again for the info.

Maybe you know of something else that would meet my needs?

I'm looking to run an Autoit app on a 'server', and pass it commands or info (to do things with) from 'client' machines. Know of any UDF's or whatever that would handle this?

Thanks

Link to comment
Share on other sites

So can you use Microsoft.XMLHTTP to send http requests instead of HTTP.au3 where that uses tcpsend(). That way windows would manage the requests.

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

  • 2 weeks later...

@CyberZeroCool

Yes you can as shown in my first post and first example.

Look for

$objHTTP = ObjCreate("Microsoft.XMLHTTP")

But it is more labour intensive to do so. Because you have to assemble the SOAP message by hand.

regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

@CyberZeroCool

Yes you can as shown in my first post and first example.

Look for

$objHTTP = ObjCreate("Microsoft.XMLHTTP")

But it is more labour intensive to do so. Because you have to assemble the SOAP message by hand.

regards,

ptrex

thanks

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Here is a very basic example using .Net and XMLHTTP. No special SOAP syntax required. First is your VB ASP.NET page, see below.

MyService.aspx

<%@ Page Language="VB" %>
<script runat="server">
    Sub Page_Load()
        Response.Expires = -1
        Response.ContentType = "text/xml"
        Dim strNL As String = Chr(13) & Chr(10)
        Dim MyCompany As String = Request.QueryString("CompanyName")
        Dim XMLContent As String = "<?xml version='1.0'?><MyCompany>" & strNL
        XMLContent += "<Address>342 West Corban Ln</Address>" & strNL
        XMLContent += "<Employees>" & strNL
        XMLContent += "<Manager>Joe Smith</Manager>" & strNL
        XMLContent += "<Programmer>Jane Smith</Programmer>" & strNL
        XMLContent += "</Employees>" & strNL
        XMLContent += "</MyCompany>" & strNL
        Response.Write(XMLContent)
        Response.End()
    End Sub
</script>

Then your AU3 code to make request and parse XML response.

This way you can pass a query string to the service to do database gathering if you like.

From this you can see how easily it can be expanded to something more extravagant.

I took out the MyErrFunc() to make it easier to read.

MyScript.au3

Dim $objXMLHTTP = ObjCreate("Microsoft.XMLHTTP")
Dim $objReturn = ObjCreate("Msxml2.DOMdocument.3.0")
Dim $XMLDoc, $itemsDoc

$objReturn.async = "false"
$objXMLHTTP.open("GET","http://localhost/MyService.aspx?CompanyName=McDonalds",true)
$objXMLHTTP.send("")

$strReturn = $objXMLHTTP.responseText
$objReturn.loadXML($strReturn)

$itemsDoc = $objReturn.documentElement
MsgBox(0,"","Address=" & $itemsDoc.childNodes(0).childNodes(0).nodeValue & @CRLF & _ 
            "Manager=" & $itemsDoc.childNodes(1).childNodes(0).childNodes(0).nodeValue & @CRLF & _ 
            "Programmer=" & $itemsDoc.childNodes(1).childNodes(1).childNodes(0).nodeValue )

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 4 months later...

I have never used SOAP before, and it's been several years since I did anything with Sharepoint. I've been trying to figure this out in relation to Sharepoint, and I'm sure I'm just overthinking it. Has anyone used SOAP in AutoIt to interact with Sharepoint? Do you have any examples?

Basically, I'm trying to pull data from a Sharepoint database, such as a list of machine names to do something to, and possibly to push data back into another database in Sharepoint. I been using a SQL database for this, but the front end for this tool was designed in VB and is obsolete, and we do not have an approved SQL management tool, so I'm looking to either query the Sharepoint front end or possibly the SQL database behind it as long as that doesn't cause issues with the front end. Then Sharepoint could be used as the front end to the database.

Thoughts? Examples?

My UDFs: ExitCodes

Link to comment
Share on other sites

@c0deWorm

I have walked down that road to myself.

The first attempt was to use Some kind of translated Vbscript code, to access the sharepoint.

I never got far.

Anyhow you will have to use these two objects to start going :

Reporting Services Sharepoint

$xmlHTTP=ObjCreate("MSXML2.xmlHTTP.3.0")  
$objStream = ObjCreate("ADODB.Stream")oÝ÷ Ù8b²+#=ìZ^¶¶ËZ®×jëh×6; Initialize COM error handler 
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$strEndPointURL = "https://your server/global/Lists/AllItems.aspx"
$strListName = "{47327AF9-9E3F-4171-A48A-9F0CA4D467F6}"
$strSoapAction="http://schemas.microsoft.com/sharepoint/soap/GetListItems"
 $objSOAPConnector = ObjCreate("MSOSOAP.HttpConnector30")
with $objSOAPConnector
 .Property("EndPointURL") = $strEndPointURL
 .Property("SoapAction") = $strSoapAction
 .Connect()
EndWith
 $objSOAPSerializer = ObjCreate("MSOSoap.SoapSerializer30")
with $objSOAPSerializer
 .Init($objSOAPConnector.InputStream)
 .startEnvelope()
 .startBody()
 .StartElement ("GetListItems", "http://schemas.microsoft.com/sharepoint/soap/")
 .StartElement ("listName", "http://schemas.microsoft.com/sharepoint/soap/")
 .WriteString($strListName)
 .EndElement()
 .StartElement ("rowLimit", "http://schemas.microsoft.com/sharepoint/soap/")
 .WriteString("10")
 .EndElement()
 .EndElement()
 .endBody()
 .endEnvelope()
EndWith
$objSOAPConnector.EndMessage()

 $objResponseReader = ObjCreate("MSOSOAP.SoapReader30")
$objResponseReader.Load($objSOAPConnector.OutputStream)
Consolewrite ($objResponseReader.Body.xml)

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)  ; to check for after this function returns
Endfunc

You can make an AU3 script ,that accesses the Excel sheet that cantains that linked WSS list.

Using normal COM scripting.

I hope this saves you some time to get you going.

Regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

  • 8 months later...

I am fairly new to SOAP but have worked quite a bit on AutoIt. I have a possibly stupid question, but in your client, say, the MSFT Stock Quote client, the response string is:

CODE
MSFT : <StockQuotes><Stock><Symbol>MSFT</Symbol><Last>19.07</Last><Date>12/15/2008</Date><Time>9:53am</Time><Change>-0.29</Change><Open>19.33</Open><High>19.44</High><Low>19.01</Low><Volume>4317804</Volume><MktCap>171.2B</MktCap><PreviousClose>19.36</PreviousClose><PercentageChange>-1.50%</PercentageChange><AnnRange>17.50 - 36.72</AnnRange><Earns>1.892</Earns><P-E>10.23</P-E><Name>Microsoft Corpora</Name></Stock></StockQuotes>

What is the method other than manual parsing to get, say, just the earnings of the stock, or say, the percentage change. I mean, one of the lowest level items. How do I address down to one of these and get the data?

Anil

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...