Jose's Read Only Forum 2023

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => COM Programming (General) => Source Code => Topic started by: José Roca on August 18, 2008, 10:08:12 AM

Title: SOAP: Simple Object Access Protocol
Post by: José Roca on August 18, 2008, 10:08:12 AM
 
The Simple Object Access Protocol (SOAP) is a lightweight, XML-based protocol for exchanging information in a decentralized, distributed environment. As such, SOAP provides an open methodology for application-to-application communication known as XML Web services.

The Microsoft® Simple Object Access Protocol (SOAP) Toolkit 3.0 consists of the following components:


In addition, the SOAP Toolkit provides a WSDL/WSML Generator tool that generates the WSDL and WSML files for you, relieving you of the tedious process of manually creating such files.

SOAP Toolkit 3.0 download: http://www.microsoft.com/downloads/details.aspx?familyid=c943c0dd-ceec-4088-9753-86f052ec8450&displaylang=en

The Microsoft SOAP Toolkit is deprecated by the .NET Framework. The toolkit provides basic Web services capabilities for COM components and applications. SOAP Toolkit support has been extended from the originally posted July 1, 2004 deadline. Mainstream SOAP Toolkit support will now be retired in March 31, 2005 with extended support lasting until March 31, 2008.
Title: Re: SOAP: Simple Object Access Protocol
Post by: José Roca on August 18, 2008, 10:11:21 AM
 
The following example illustrates the basic steps to use SOAP with PowerBASIC using Automation.


' ########################################################################################
' SOAP example using Automation.
' ########################################################################################

' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG

   LOCAL oSoapClient AS DISPATCH
   LOCAL vWSDLFile AS VARIANT
   LOCAL vCategory AS VARIANT
   LOCAL vRes AS VARIANT

'   oSoapClient = NEWCOM "MSSOAP.SoapClient30"    ' SOAP 3.0
'   oSoapClient = NEWCOM "MSOSOAP.SoapClient30"   ' version installed with Office 11
'   oSoapClient = NEWCOM "MSSOAP.SoapClient.1"    ' SOAP 1.0
   oSoapClient = NEWCOM "MSSOAP.SoapClient"   ' SOAP 1.0 - version independent ProgID
   IF ISNOTHING(oSoapClient) THEN EXIT FUNCTION

   TRY
      LET vWSDLFile = "http://www.interpressfact.net/webservices/getJoke.asmx?wsdl"
      OBJECT CALL oSoapClient.MSSoapInit(vWSDLFile)
      ' Categories:
      ' Murphy's Laws - 7
      ' Q&A - 3
      ' Unnatural Laws - 18
      ' Cool Jokes - 6
      ' Blondes - 2
      ' Random(contains Adult) - 1
      ' Lawyers - 5
      ' Headlines - 8
      ' Military - 9
      ' Accidents - 4
      ' Excuses - 10 [out of range]
      ' Answering machine - 11 [out of range]
      ' All categories - 0
      vCategory = 8
      OBJECT CALL oSoapClient.getJoke(vCategory) TO vRes
      MSGBOX VARIANT$(vRes)
   CATCH
      OBJECT GET oSoapClient.FaultString TO vRes
      MSGBOX VARIANT$(vRes)
   FINALLY
      oSoapClient = NOTHING
   END TRY

END FUNCTION


The following version uses a mix of Automation and direct interface calls.


' ########################################################################################
' SOAP example mixing direct calls and Automation.
' ########################################################################################

' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "MSSOAP1.INC"      ' SOAP 1.0
'#INCLUDE "MSSOAP30.INC"    ' SOAP 3.0
'#INCLUDE "MSOSOAP30.INC"   ' SOAP 3.0 for Office

FUNCTION PBMAIN () AS LONG

   LOCAL pSoapClient AS ISoapClient      ' SOAP 1.0
'   LOCAL pSoapClient AS ISoapClient30   ' SOAP 3.0
   LOCAL oSoapClient AS DISPATCH
   LOCAL vCategory AS VARIANT
   LOCAL vRes AS VARIANT

'   pSoapClient = NEWCOM "MSSOAP.SoapClient30"    ' SOAP 3.0
'   pSoapClient = NEWCOM "MSOSOAP.SoapClient30"   ' SOAP 3.0 for Office
'   pSoapClient = NEWCOM "MSSOAP.SoapClient.1"    ' SOAP 1.0
'   pSoapClient = NEWCOM "MSOSOAP.SoapClient"     ' SOAP 1.0 - version independent ProgID

   pSoapClient = NEWCOM "MSSOAP.SoapClient"   ' SOAP 1.0 - version independent ProgID
   IF ISNOTHING(pSoapClient) THEN EXIT FUNCTION
   oSoapClient = pSoapClient

   TRY
      ' Note  Despite being flagged as optional, if we don't specify the second
      ' and third parameters (service name and port name) when using a direct call
      ' it returns error &H80070057 (wrong parameter). This doesn't happens if we
      ' use Automation.
      pSoapClient.MSSoapInit( _
         UCODE$("http://interpressfact.net/webservices/getjoke.asmx?wsdl"), _
         UCODE$("getJoke"), UCODE$("getJokeSoap"))
      ' Categories:
      ' Murphy's Laws - 7
      ' Q&A - 3
      ' Unnatural Laws - 18
      ' Cool Jokes - 6
      ' Blondes - 2
      ' Random(contains Adult) - 1
      ' Lawyers - 5
      ' Headlines - 8
      ' Military - 9
      ' Accidents - 4
      ' Excuses - 10 [out of range]
      ' Answering machine - 11 [out of range]
      ' All categories - 0
      vCategory = 8
      OBJECT CALL oSoapClient.getJoke(vCategory) TO vRes
      MSGBOX VARIANT$(vRes)
   CATCH
      MSGBOX ACODE$(pSoapClient.FaultString)
   FINALLY
      oSoapClient = NOTHING
      pSoapClient = NOTHING
   END TRY

END FUNCTION


The following version uses direct interface calls only.


' ########################################################################################
' SOAP example using direct calls exclusively.
' ########################################################################################

' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "MSSOAP1.INC"      ' SOAP 1.0
'#INCLUDE "MSSOAP30.INC"    ' SOAP 3.0
'#INCLUDE "MSOSOAP30.INC"   ' SOAP 3.0 for Office

FUNCTION PBMAIN () AS LONG

   LOCAL pSoapClient AS ISoapClient      ' SOAP 1.0
'   LOCAL pSoapClient AS ISoapClient30   ' SOAP 3.0
   LOCAL hr AS LONG
   LOCAL dispId AS LONG
   LOCAL IID_NULL AS GUID
   LOCAL strName AS STRING
   LOCAL vResult AS VARIANT
   DIM   vArgs(0) AS VARIANT
   LOCAL tDispParams AS DISPPARAMS

'   pSoapClient = NEWCOM "MSSOAP.SoapClient30"    ' SOAP 3.0
'   pSoapClient = NEWCOM "MSOSOAP.SoapClient30"   ' SOAP 3.0 for Office
'   pSoapClient = NEWCOM "MSSOAP.SoapClient.1"    ' SOAP 1.0
'   pSoapClient = NEWCOM "MSOSOAP.SoapClient"     ' SOAP 1.0 - version independent ProgID

   pSoapClient = NEWCOM "MSSOAP.SoapClient"
   IF ISNOTHING(pSoapClient) THEN EXIT FUNCTION

   TRY
      ' Note  Despite being flagged as optional, if we don't specify the second
      ' and third parameters (service name and port name) when using a direct call
      ' it returns error &H80070057 (wrong parameter). This doesn't happens if we
      ' use Automation.
      pSoapClient.MSSoapInit( _
         UCODE$("http://interpressfact.net/webservices/getjoke.asmx?wsdl"), _
         UCODE$("getJoke"), UCODE$("getJokeSoap"))
      ' Categories:
      ' Murphy's Laws - 7
      ' Q&A - 3
      ' Unnatural Laws - 18
      ' Cool Jokes - 6
      ' Blondes - 2
      ' Random(contains Adult) - 1
      ' Lawyers - 5
      ' Headlines - 8
      ' Military - 9
      ' Accidents - 4
      ' Excuses - 10 [out of range]
      ' Answering machine - 11 [out of range]
      ' All categories - 0
      strName = UCODE$("getJoke")
      hr = pSoapClient.GetIDsOfNames(IID_NULL, strName, 1, 0, dispId)
      IF hr = %S_OK THEN
         vArgs(0) = 8
         tDispParams.CountArgs = 1
         tDispParams.VariantArgs = VARPTR(vArgs(0))
         hr = pSoapClient.Invoke(dispId, IID_NULL, 0, %DISPATCH_METHOD, tDispParams, _
              vResult, BYVAL %NULL, BYVAL %NULL)
         IF hr = %S_OK THEN MSGBOX VARIANT$(vResult)
      END IF
      IF hr <> %S_OK THEN MSGBOX ACODE$(pSoapClient.FaultString)
   CATCH
      ' Display error information
      MSGBOX ACODE$(pSoapClient.FaultString)
   FINALLY
      ' Release the object
      pSoapClient = NOTHING
   END TRY

END FUNCTION

Title: SOAP Problem
Post by: Martin Dorfinger on April 10, 2009, 06:39:25 PM
I have installed Soap Toolkit 3.0, and MS Framework, but I get error message: Missing Declaration: NEWCOM when running the code.

There is something wrong with: "MSSOAP.SoapClient" What can I do?

Martin


Title: Re: SOAP: Simple Object Access Protocol
Post by: José Roca on April 10, 2009, 06:49:32 PM
 
Quote
I get error message: Missing Declaration: NEWCOM when running the code.

To use NEWCOM you need PBWIN 9.0+ or PBCC 5.0+. All the code posted in this forum needs the new compilers. For older versions, all what we have available can be found in the Legacy Software forum, at the bottom.
Title: Re: SOAP: Simple Object Access Protocol
Post by: Martin Dorfinger on April 10, 2009, 08:03:47 PM
Thanks a lot for reply!

I am used to work with PBCC, but I am not used to work with all this SOAP stuff.

I am working on a project to get data with the help of a self written SOAP client.
Login to betfair, and get informations according to "Betfair Sports Exchange API Reference Guide v6" on "http://bdpsupport.betfair.com/ics/support/default.asp?deptID=2805&task=download"

The future program should be a Betfair-Bot.

Is there any kind of code showing how to login, or how to get information e.g. "MarketPrices, getCurrentBets, ......"
For me it would be important to find the starting point.

Martin

Title: Re: SOAP: Simple Object Access Protocol
Post by: José Roca on April 10, 2009, 09:02:02 PM
 
I don't have specific examples for Betfair.

To initialize SOAP, use:


pSoapClient.MSSoapInit( _
   UCODE$("https://api.betfair.com/global/v3/BFGlobalService.wsdl"), _
   UCODE$("BFGlobalService"), UCODE$("BFGlobalService"))


or this one if you are using an older version of the compiler:


LOCAL vWSDLFile AS VAEIANT
LOCAL vServiceName AS VARIANT
LOCAL vPort AS VARIANT
LET vWSDLFile = "http://www.interpressfact.net/webservices/getJoke.asmx?wsdl"
vServiceName = "BFGlobalService"
vPort = "BFGlobalService"
OBJECT CALL oSoapClient.MSSoapInit(vWSDLFile, vServiceName, vPort)


Then call the wanted service, e.g. OBJECT CALL oSoapClient.GetCurrentBets (<parameters>).

The parameters that you have to pass are specified in the documentation provided by Betfair: http://bdpsupport.betfair.com/ics/support/default.asp?deptID=2805&task=download
Title: Re: SOAP: Simple Object Access Protocol
Post by: Edwin Knoppert on April 10, 2009, 09:04:47 PM
I had poor results ever with the office version.
Have you tested this fella with succes?
It seems the older release has no more support, running it as a simple unregisterd dll will not work as well.
That's to bad, a self contained dll would have been nice.
(I did not test your code)
Title: Re: SOAP: Simple Object Access Protocol
Post by: Edwin Knoppert on April 10, 2009, 09:07:06 PM
FYI, i have a webservice running at:
http://www.hellobasic.com/webservices/test1.asmx

It may be useful to test with this ASP.NET webservice.
Some instructions are also in this topic:
http://www.hellobasic.com/cgi-bin/forum/YaBB.pl?board=VDExamples;action=display;num=1202649022
Title: Re: SOAP: Simple Object Access Protocol
Post by: Martin Dorfinger on April 10, 2009, 09:48:03 PM
 oSoapClient.MSSoapInit(UCODE$("https://api.betfair.com/global/v3/BFGlobalService.wsdl"), _
   UCODE$("BFGlobalService"), UCODE$("BFGlobalService"))

Here I get error message: Method or Property name expected
                                                                   
Title: Re: SOAP: Simple Object Access Protocol
Post by: José Roca on April 10, 2009, 09:51:54 PM
 
I have posted that if you are using an older version of the compiler you will have to use:


LOCAL vWSDLFile AS VAEIANT
LOCAL vServiceName AS VARIANT
LOCAL vPort AS VARIANT
LET vWSDLFile = "http://www.interpressfact.net/webservices/getJoke.asmx?wsdl"
vServiceName = "BFGlobalService"
vPort = "BFGlobalService"
OBJECT CALL oSoapClient.MSSoapInit(vWSDLFile, vServiceName, vPort)


Do not try to use code written for PBWIN 9/PBCC 5 with PBCC 4.
Title: Re: SOAP: Simple Object Access Protocol
Post by: Martin Dorfinger on December 04, 2009, 07:46:22 PM
I can not call the wanted service.  :-[


#COMPILE EXE
#DIM ALL
'#INCLUDE "MSSOAP1.INC"      ' SOAP 1.0
'#INCLUDE "MSSOAP30.INC"    ' SOAP 3.0
#INCLUDE "MSOSOAP30.INC"   ' SOAP 3.0 for Office

FUNCTION PBMAIN () AS LONG

'   LOCAL pSoapClient AS ISoapClient      ' SOAP 1.0
   LOCAL pSoapClient AS ISoapClient30   ' SOAP 3.0
   LOCAL hr AS LONG
   LOCAL dispId AS LONG
   LOCAL IID_NULL AS GUID
   LOCAL strName AS STRING
   LOCAL vResult AS VARIANT
   DIM   vArgs(0) AS VARIANT
   LOCAL tDispParams AS DISPPARAMS
   LOCAL vRes AS VARIANT

   pSoapClient = NEWCOM "MSSOAP.SoapClient"
   IF ISNOTHING(pSoapClient) THEN EXIT FUNCTION


      pSoapClient.MSSoapInit(UCODE$("https://api.betfair.com/global/v3/BFGlobalService.wsdl"), _
      UCODE$("BFGlobalService"), UCODE$("BFGlobalService"))

      hr =   pSoapClient.BFGlobalService.APIRequestHeader(clientStampField) TO vRes
      MSGBOX VARIANT$(vRes)
 
END FUNCTION 
Title: Re: SOAP: Simple Object Access Protocol
Post by: José Roca on December 04, 2009, 08:44:03 PM
 
It should be something like:


' ########################################################################################
' SOAP example using Automation.
' ########################################################################################

' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG

   LOCAL oSoapClient AS DISPATCH
   LOCAL vWSDLFile AS VARIANT
   LOCAL vClientStampField AS VARIANT
   LOCAL vRes AS VARIANT

   oSoapClient = NEWCOM "MSSOAP.SoapClient"
   IF ISNOTHING(oSoapClient) THEN EXIT FUNCTION

   TRY
      vWSDLFile = UCODE$("https://api.betfair.com/global/v3/BFGlobalService.wsdl")
      OBJECT CALL oSoapClient.MSSoapInit(vWSDLFile)
'      vClientStampField = "<some name>"   ' <--- change me
'      OBJECT CALL oSoapClient.APIRequestHeader(vClientStampField) TO vRes
'      MSGBOX VARIANT$(vRes)
   CATCH
      OBJECT GET oSoapClient.FaultString TO vRes
      MSGBOX VARIANT$(vRes)
   FINALLY
      oSoapClient = NOTHING
   END TRY

END FUNCTION


If it doesn't work, I don't know what more to do. Other than the posted example, I never have done anything with SOAP.