Page 1 of 1

Using COM and SOAP to get temperature at XMethods

Posted: Mon Dec 20, 2004 1:53 pm
by Leo
To promote the use of ActiveX and of Axend's InterfaceGenerator, I post here a small example how to use the pocketSOAP component that can be downloaded from http://www.pocketsoap.com/ The example retrieves the temperature from the http://services.xmethods.net:80/soap/servlet/rpcrouter site

For some reason the ComLib of Axend does not work with CreateObject("pocketSOAP.HTTPTransport.2") (it crashes), so I used the CoCreateInstanceEx instead.

The generated interface pSoap32.pb

Code: Select all

; Interface generated by Interface Generator 1.0, Date 12/10/2004 

; PocketSOAP, PocketSOAP 1.5.0 Type Library

; Enumerations

Enumeration ; sfConfigOptions
  #sfcNormal_11 = 0
  #sfcScripting_11 = 1
  #sfcNormal_12 = 2
  #sfcScripting_12 = 3
EndEnumeration

Enumeration ; pocketSOAPErrors
  #E_SOAPFAULT = -2147204607
  #E_NOFAULTCODE = -2147204606
  #E_NOFAULTSTRING = -2147204605
  #E_DONT_UNDERSTAND = -2147204604
  #E_INVALID_ARRAY_POS = -2147204592
  #E_ARRAY_COORD_FORMAT = -2147204591
  #E_NO_DESERIALIZER = -2147204576
  #E_NO_SERIALIZER = -2147204560
  #E_ATTR_SIMPLE_ONLY = -2147204559
  #E_DESER_NO_SIMPLE = -2147204558
  #E_PARSE_ERROR = -2147204544
  #E_UNKNOWN_PRIMARYSCHEMA = -2147204528
  #E_INVALID_LEX_REP = -2147204512
EndEnumeration

Enumeration ; pocketSOAPHttpErrors
  #E_SSL_FAILURE = -2147204351
  #E_DEFLATE_FAILURE = -2147204350
  #E_INFLATE_FAILURE = -2147204349
EndEnumeration

; Interfaces

Interface ISOAPEnvelope Extends IUnknown
  get_ThrowFaults(a)
  put_ThrowFaults(a)
  get_URI(a)
  put_URI(a)
  get_MethodName(a)
  put_MethodName(a)
  get_EncodingStyle(a)
  put_EncodingStyle(a)
  SetMethod(a,b)
  Parse(a,b,c,d,e)
  Serialize(a)
  get_Headers(a)
  get_Body(a)
  get_Parameters(a)
  get_SerializerFactory(a)
  putref_SerializerFactory(a)
EndInterface

Interface ISOAPNodes Extends IUnknown
  get__NewEnum(a)
  get_Item(a,b)
  get_ItemByName(a,b,c)
  get_Count(a)
  Append(a)
  Clear()
  Create(a,b,c,d,e,f,g,h,i)
EndInterface

Interface ISOAPNode Extends IUnknown
  get_Name(a)
  put_Name(a)
  get_Namespace(a)
  put_Namespace(a)
  get_Type(a)
  put_Type(a)
  get_TypeNS(a)
  put_TypeNS(a)
  get_Value(a)
  put_Value(a,b,c,d)
  get_ValueAs(a,b,c)
  putref_SerializerFactory(a)
  get_root(a)
  get_id(a)
  get_href(a)
  get_actor(a)
  get_mustUnderstand(a)
  get_offset(a)
  get_position(a)
  get_nil(a)
  put_root(a)
  put_id(a)
  put_href(a)
  put_actor(a)
  put_mustUnderstand(a)
  put_offset(a)
  put_position(a)
  put_nil(a)
  get_Nodes(a)
EndInterface

Interface ISerializerFactoryConfig Extends IUnknown
  ElementMapping(a,b,c,d)
  Deserializer(a,b,c,d,e,f,g,h)
  Serializer(a,b,c,d,e,f,g)
  get_PrimarySchema(a)
  put_PrimarySchema(a)
  get_RootFirst(a)
  put_RootFirst(a)
  SetConfig(a,b,c,d)
EndInterface

Interface ISOAPNamespaces Extends IUnknown
  GetPrefixForURI(a,b)
  GetURIForPrefix(a,b)
EndInterface

Interface ISOAPEnvelope2 Extends ISOAPEnvelope
  get_EnvelopeVersion(a)
  put_EnvelopeVersion(a)
EndInterface

Interface ISOAPTransport Extends IUnknown
  Send(a,b)
  Receive(a,b)
EndInterface

Interface IHTTPTransport Extends ISOAPTransport
  get_SOAPAction(a)
  put_SOAPAction(a)
EndInterface

Interface IHTTPTransportAdv Extends IHTTPTransport
  put_Timeout(a)
  get_Timeout(a)
  SetProxy(a,b)
  NoProxy()
  Authentication(a,b)
  ProxyAuthentication(a,b)
  get_StatusCode(a)
  get_MaxRedirectDepth(a)
  put_MaxRedirectDepth(a)
EndInterface

Interface ISOAPTransport2 Extends IUnknown
  Send(a,b,c,d,e)
  Receive(a,b)
EndInterface

Interface ISwATransport Extends IUnknown
  get_ContentType(a)
  put_ContentType(a)
  Send(a,b,c,d,e)
  Receive(a,b)
EndInterface

Interface ISOAPTransportTimeout Extends ISOAPTransport
  put_Timeout(a)
  get_Timeout(a)
EndInterface

Interface IHTTPTransportAdv2 Extends IHTTPTransportAdv
  get_Option(a,b)
  put_Option(a,b,c,d,e)
EndInterface

Interface ISOAPNode2 Extends ISOAPNode
  get_EncodingStyle(a)
  put_EncodingStyle(a)
EndInterface

Interface ISOAPNode3 Extends ISOAPNode2
  get_explicitRoot(a)
  put_explicitRoot(a)
EndInterface

Interface ISOAPNode12 Extends IUnknown
  get_role(a)
  put_role(a)
  get_relay(a)
  put_relay(a)
  get_ref(a)
  put_ref(a)
EndInterface

Interface ISerializerFactory Extends IUnknown
  SerializerForValue(a,b)
  SerializerForNode(a,b)
  ReturnSerializer(a)
  DeserializerForType(a,b,c,d)
  DeserializerForElement(a,b,c,d)
  ReturnDeSerializer(a)
  XsiForPrimaryNS(a)
  IsAnyType(a,b,c)
  AreEqualComTypes(a,b,c,d,e)
  FindComType(a,b,c)
EndInterface

Interface ISoapSerializer Extends IUnknown
  Serialize(a,b,c)
EndInterface

Interface ISerializerContext Extends IUnknown
  get_Namespaces(a)
  get_SerializerFactory(a)
EndInterface

Interface ISerializerOutput Extends IUnknown
  StartElement(a,b)
  EndElement(a,b)
  Attribute(a,b,c)
  QNameAttribute(a,b,c,d)
  SerializeNode(a)
  SerializeValue(a,b,c)
  WriteText(a)
  WriteTextNoEncoding(a)
EndInterface

Interface ISoapDeSerializer Extends IUnknown
  Start(a,b,c,d)
  Child(a,b,c)
  ChildReady(a,b)
  ChildRef(a,b)
  ref(a,b)
  Characters(a)
  End()
EndInterface

Interface ISoapDeSerializerAttributes Extends IUnknown
  Exists(a,b,c)
  Value(a,b,c)
EndInterface

Interface ISerializerFactoryConfig2 Extends ISerializerFactoryConfig
  LocalTypeMapping(a,b,c,d,e,f)
EndInterface

Interface ISerializerFactory2 Extends ISerializerFactory
  DeserializerForChild(a,b,c,d,e,f,g,h)
EndInterface

Interface ISerializerFactoryPool Extends IUnknown
  Reset()
EndInterface

Interface ISerializerFactoryPool2 Extends ISerializerFactoryPool
  Fetch(a,b)
EndInterface

Interface ISerializerFactoryEx Extends IUnknown
  SerializerForValue(a,b,c,d,e,f,g,h)
  SerializerForNode(a,b,c,d,e,f)
  ReturnSerializer(a)
  DeserializerForType(a,b,c,d)
  DeserializerForElement(a,b,c,d,e,f,g,h)
  ReturnDeSerializer(a)
  FindType(a,b,c,d,e,f)
  XsiForPrimaryNS(a)
  IsAnyType(a,b,c)
  AreEqualComTypes(a,b,c,d,e)
  FindComType(a,b,c)
EndInterface

Interface ISerializerFactoryConfig3 Extends ISerializerFactoryConfig2
  understoodHeader(a,b)
EndInterface

Interface ITypesInit Extends IUnknown
  Initialize(a,b,c,d,e,f)
EndInterface

Interface ISimpleSoapSerializer Extends IUnknown
  Serialize(a,b,c)
EndInterface

Interface IXmlQName Extends IUnknown
  get_Name(a)
  put_Name(a)
  get_Namespace(a)
  put_Namespace(a)
  Set(a,b)
EndInterface

Interface IInterfaceFinder Extends IUnknown
  DefaultIID(a,b)
EndInterface

Interface ISerializerOutput2 Extends ISerializerOutput
  SerializeAttribute(a,b,c)
EndInterface

Interface ISoapDeSerializerAttributes2 Extends ISoapDeSerializerAttributes
  ValueAs(a,b,c,d,e)
EndInterface

Interface ISerializerContext2 Extends ISerializerContext
  get_EnvelopeVersion(a)
EndInterface

Interface IHTTPTransportDisp Extends IUnknown
  Send(a,b,c,d,e)
  Receive(a,b)
  get_SOAPAction(a)
  put_SOAPAction(a)
  put_Timeout(a)
  get_Timeout(a)
  SetProxy(a,b)
  NoProxy()
  Authentication(a,b)
  ProxyAuthentication(a,b)
  get_StatusCode(a)
  get_MaxRedirectDepth(a)
  put_MaxRedirectDepth(a)
  get_Option(a,b)
  put_Option(a,b,c,d,e)
EndInterface

Interface ISOAPNodeDisp Extends IUnknown
  get_Name(a)
  put_Name(a)
  get_Namespace(a)
  put_Namespace(a)
  get_Type(a)
  put_Type(a)
  get_TypeNS(a)
  put_TypeNS(a)
  get_Value(a)
  put_Value(a,b,c,d)
  get_ValueAs(a,b,c)
  putref_SerializerFactory(a)
  get_root(a)
  get_id(a)
  get_href(a)
  get_actor(a)
  get_mustUnderstand(a)
  get_offset(a)
  get_position(a)
  get_nil(a)
  put_root(a)
  put_id(a)
  put_href(a)
  put_actor(a)
  put_mustUnderstand(a)
  put_offset(a)
  put_position(a)
  put_nil(a)
  get_Nodes(a)
  get_EncodingStyle(a)
  put_EncodingStyle(a)
  get_explicitRoot(a)
  put_explicitRoot(a)
  get_role(a)
  put_role(a)
  get_relay(a)
  put_relay(a)
  get_ref(a)
  put_ref(a)
EndInterface
The actual program

Code: Select all

XIncludeFile "pSoap32.pb"

Result.l = CoCreateInstance_(?CLSID_CoEnvelope,0,1,?IID_ISOAPEnvelope,@oEnvelope.ISOAPEnvelope) 
;oEnvelope.ISOAPEnvelope = CreateObject("pocketSOAP.Envelope.2")
Result=oEnvelope\SetMethod ( Ansi2Uni("getTemp"), Ansi2Uni("urn:xmethods-Temperature"))
pNodes.l
Result=oEnvelope\get_Parameters(@pNodes)

zip.VARIANT 
zip\vt = #VT_BSTR 
zip\bstrVal = Ansi2Uni("94107")
*zip.pToVariant=zip
 
*oNodes.ISOAPNodes=pNodes
Result=*oNodes\Create(Ansi2Uni(""),*zip\a,*zip\b,*zip\c,*zip\d,0,0,0,0)
Result=*oNodes\Release()

Result.l =CoInitialize_(0)
Result.l = CoCreateInstance_(?CLSID_HTTPTransport,0,1,?IID_IHTTPTransport,@oHTTP.IHTTPTransport) 
;oHTTP.IHTTPTransport = CreateObject("pocketSOAP.HTTPTransport.2")

Result=oHTTP\put_SOAPAction(Ansi2Uni(""))

Envelope=AllocateMemory(5000)
Result=oEnvelope\Serialize(@Envelope)
Result=oHTTP\Send ( Ansi2Uni("http://services.xmethods.net:80/soap/servlet/rpcrouter"), Envelope )

voHTTP.VARIANT
voHTTP\vt = #VT_UNKNOWN
voHTTP\value=oHTTP
*voHTTP.pToVariant = voHTTP
oEnvelope\Parse(*voHTTP\a, *voHTTP\b, *voHTTP\c, *voHTTP\d, Ansi2Uni(""))
oNodes.l
Result=oEnvelope\get_Parameters(@oNodes)
*oNodes.ISOAPNodes=oNodes
oNode.l
Result=*oNodes\get_Item(0, @oNode)
*oNode.ISOAPNode=oNode
v.VARIANT
*v.pToVariant = v
*oNode\get_Value(@v)
BSTR.VARIANT
Result=VariantChangeType_(@BSTR,@V,0,#VT_BSTR)
h.f=48.0
MessageRequester("Temperature in Fahrenheit",Uni2Ansi(BSTR\value),0)


DataSection
  CLSID_HTTPTransport:
  Data.l $D76BA06F
  Data.w $ABF3,$4c1f
  Data.b $BD,$C9,$18,$48,$D4,$E3,$CF,$2B
EndDataSection

DataSection
  IID_IHTTPTransport:
  Data.l $C2F39358
  Data.w $2B60,$4FDA
  Data.b $B6,$FC,$E9,$5D,$CC,$4E,$9C,$9B
EndDataSection

DataSection
  CLSID_CoEnvelope:
  Data.l $e2e0fb24
  Data.w $e58f,$458f
  Data.b $84,$e0,$6e,$09,$d2,$d5,$15,$11
EndDataSection

DataSection
  IID_ISOAPEnvelope:
  Data.l $8b2091b1
  Data.w $dcf9,$44a7
  Data.b $a5,$0b,$f0,$29,$71,$a0,$1b,$f1
EndDataSection



Posted: Mon Dec 20, 2004 10:23 pm
by Blade
This looks great, but I have a "clean" PB installation, and I can't run it.

I found the "Ansi2Uni" command coping the COMLIB in the userlibraries, but still don't know where to find the VARIANT type...

Perhaps PB should have a "tool" to detect (and optionally download) needed libraries... a small on-line libaries database would be cool!

Posted: Mon Dec 20, 2004 10:56 pm
by thefool

Using COM and SOAP to get temperature at XMethods

Posted: Mon Dec 27, 2004 9:13 am
by aXend
Code updated For 5.20+

@Leo: I also found that CreateObject() doesn't work in all situations. I'm looking into it as soon as I have the time.
@Blade: You can use the following include file with all the variant types.

Code: Select all

; All kind of constants and structures needed to work with the VARIANT type.
; The VARIANT type is used by COM components like ActiveX and others.

Enumeration
  #VT_EMPTY           = 0
  #VT_NULL            = 1
  #VT_I2              = 2
  #VT_I4              = 3
  #VT_R4              = 4
  #VT_R8              = 5
  #VT_CY              = 6
  #VT_DATE            = 7
  #VT_BSTR            = 8
  #VT_DISPATCH        = 9
  #VT_ERROR           = 10
  #VT_BOOL            = 11
  #VT_VARIANT         = 12
  #VT_UNKNOWN         = 13
  #VT_DECIMAL         = 14
  #VT_I1              = 16
  #VT_UI1             = 17
  #VT_UI2             = 18
  #VT_UI4             = 19
  #VT_I8              = 20
  #VT_UI8             = 21
  #VT_INT             = 22
  #VT_UINT            = 23
  #VT_VOID            = 24
  #VT_HRESULT         = 25
  #VT_PTR             = 26
  #VT_SAFEARRAY       = 27
  #VT_CARRAY          = 28
  #VT_USERDEFINED     = 29
  #VT_LPSTR           = 30
  #VT_LPWSTR          = 31
  #VT_RECORD          = 36
  #VT_FILETIME        = 64
  #VT_BLOB            = 65
  #VT_STREAM          = 66
  #VT_STORAGE         = 67
  #VT_STREAMED_OBJECT = 68
  #VT_STORED_OBJECT   = 69
  #VT_BLOB_OBJECT     = 70
  #VT_CF              = 71
  #VT_CLSID           = 72
  #VT_BSTR_BLOB       = $fff
  #VT_VECTOR          = $1000
  #VT_ARRAY           = $2000
  #VT_BYREF           = $4000
  #VT_RESERVED        = $8000
  #VT_ILLEGAL         = $ffff
  #VT_ILLEGALMASKED   = $fff
  #VT_TYPEMASK        = $fff
EndEnumeration               



Structure BRECORD       ; No idea where this is used
  pvRecord.l;
  IRecordInfo.l
EndStructure



Structure SIGNSCALE
  scale.b               ; The number of decimal places for the number. Valid values are from 0 To 28.
  sign.b                ; 0 for positive numbers or DECIMAL_NEG for negative numbers. So -1 is represented as 1 with the DECIMAL_NEG bit set.
EndStructure

Structure DECIMAL      ; Special type of VARIANT, also 16 bytes
  wReserved.w
  signscale.SIGNSCALE
  high32.l
  low64.DOUBLE
EndStructure

Structure pToVariant   ; Used to pass a VARIANT to a method when you can't us a pointer, also 16 bytes
  a.l
  b.l
  c.l
  d.l
EndStructure


#VARIANT_FALSE  = $0000 ; Variant version of FALSE