SOAP/WSDL/BETFAIR

T

Tad Bochan

Hi,

I have been making a foray into the world of SOAP/WSDL etc and having
been encouraged with the success of running the googleapi demo code,
I thought I would have a go with Betfair.

Alas, things are not going well,
and I'm not sure if I'm doing something wrong
or if the library module 'soap/wsdlDriver' is faulty
or does not support the BFService.wsdl document.

The login request sequence works great,
but any other requests fail (eg., getAllEventTypes, logout)
because the parameters do not get generated
in the request document which is sent to Betfair,
which seems to indicate a bug in soap/wsdlDriver.rb,
or in the way I have setup the parameters.

I have included the wiredumps for the 'login' and 'getAllEventTypes'
requests
as comments in the code following, and you will see that
the <n1:request> element for 'login' is formatted as per the parameters
passed to login ,
but the one for 'getAllEventTypes' is empty.

Any suggestions ?
(I tried to debug the soap code, but it was all beyond my abilities)

Regards,

Tad


#<Docs>
#http://bdphelp.betfair.com/API4/V1/API4.1aOnlineHelp/wwhelp/wwhimpl/js/html/wwhelp.htm
#</Docs>
require 'soap/wsdlDriver'
wsdl_url="https://api.betfair.com/betex-api-public-ws/v2/BFService.wsdl"
puts ">>CONNECT<<"
soap = SOAP::WSDLDriverFactory.new( wsdl_url ).create_rpc_driver
soap.wiredump_file_base,soap.wiredump_dev = "bdp",STDOUT
puts "------------------------------------------------"
print ">>LOGIN<<"
logindetails={:locationId =>0,
:password =>"mypassword",
:productId =>82,
:username =>"myusername",
:vendorSoftwareId=>0
}
response=soap.login:)request=>logindetails) ;
exit unless response.result.errorCode=="OK"

# WIREDUMP OUTPUT FROM LOGIN REQUEST :-
#-<?xml version="1.0" encoding="utf-8" ?>
#-<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
#- xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
#- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
#- <env:Body>
#- <n1:login
xmlns:n1="http://www.betfair.com/publicapi/BFServiceV2/">
#- <n1:request>
#- <locationId>0</locationId>
#- <password>mypassword</password>
#- <productId>82</productId>
#- <username>myusername</username>
#- <vendorSoftwareId>0</vendorSoftwareId>
#- </n1:request>
#- </n1:login>
#- </env:Body>
#-</env:Envelope>
puts "------------------------------------------------"

print ">>GET ALL EVENT TYPES<<"
apiRequestHeader={:clientStamp => 0,:sessionToken =>
response.result.header.sessionToken}
response=soap.getAllEventTypes:)request=>{:header=>apiRequestHeader,:locale=>"en"})
exit unless response.result.errorCode=="OK"

# WIREDUMP OUTPUT FROM 'getAllEventTypes' REQUEST :-
#<?xml version="1.0" encoding="utf-8" ?>
#<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
# xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
# <env:Body>
# <n1:getAllEventTypes
xmlns:n1="http://www.betfair.com/publicapi/BFServiceV2/">
# <n1:request>
# </n1:request>
# </n1:getAllEventTypes>
# </env:Body>
#</env:Envelope>

puts "------------------------------------------------"
print ">>LOGOUT<<"
apiRequestHeader={:clientStamp => 0,:sessionToken =>
response.result.header.sessionToken}
response=soap.logout:)request=>{:header=>apiRequestHeader})
p [response.result.header.errorCode,response.result.errorCode]
exit unless response.result.errorCode=="OK"
puts "------------------------------------------------"
puts "It all worked OK"
 
G

Gianfranco Cecconi

Hi Tad,
I tried myself, but had to stop at the very beginning. These three lines
of code are sufficient to give me problems:

require 'soap/wsdlDriver'
WSDL_URL = "https://api.betfair.com/betex-api-public-ws/BFService.wsdl"
soap = SOAP::WSDLDriverFactory.new(WSDL_URL).createDriver

I get the following:

warning: peer certificate won't be verified in this SSL session.
Unknown attr {}abstract.
Unknown attr {}nillable.
Unknown attr {}nillable.
Unknown attr {}nillable.
Unknown attr {}abstract.
Unknown attr {}nillable.
Unknown attr {}nillable.
(...)

I am running Ruby 1.8.2 on MacOS 10.4.7 . In general my feeling is that
the SOAP4R library is very immature.

Giacecco
 
T

Tadeusz Bochan

Hi Gianfranco,
Thanks for the reply. I was beginning to lose hope.
I am running this on Windows XP with Ruby 1.8.4-20.
I guess that 'maturity' only comes with people exposing
the problems, and then getting them fixed.
So, I hope this is just one of the steps on the way
to a more robust Ruby development environment.
I just noticed that Hiroshi tested my code with the
development version of soap4r, and he got it to work,
so I will try to do the same.

Best regards,
Tad.
(If you would like me to, I will let you know what progress I make.)
 
G

Gianfranco Cecconi

I agree with you, and the work Hiroshi is doing is incredible. About the
library's robustness, probably I like Ruby so much that I feel
frustrated when I realise the community is not coping with supporting
its growth and consolidation in a timely fashion. At the same time, I am
not good enough to contribute.

I will try the development version myself. Bye,

Gianfranco
 
G

Gianfranco Cecconi

Trying with the official (no development) Ruby 1.8.5 and the situation
is much better now. I seem to login successfully, but I'm getting a "no
session" error when logging out. Difficult to say if it is a Ruby issue
now. Do you think we should move this thread somewhere else?

It is also interesting that it doesn't work if I do not explicitly
specify the URL for version 2 of the WSDL.

The new source is the following:


require 'soap/wsdlDriver'
WSDL_URL =
"https://api.betfair.com/betex-api-public-ws/v2/BFService.wsdl"
BETFAIR_USERNAME = "********"
BETFAIR_PASSWORD = "********"

soapDriver = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver

puts "Establishing connection to Betfair..."
print "Logging in... "
loginDetails = { :locationId => 0,
:password => BETFAIR_PASSWORD,
:productId => 82,
:username => BETFAIR_USERNAME,
:vendorSoftwareId => 0 }
response = soapDriver.login:)request => loginDetails) ;
exit unless response.result.errorCode == "OK"
puts "succeded."

print "Logging out... "
apiRequestHeader = { :clientStamp => 0,
:sessionToken =>
response.result.header.sessionToken }
response = soapDriver.logout:)request => { :header => apiRequestHeader
})
p [response.result.header.errorCode, response.result.errorCode]
exit unless response.result.errorCode=="OK"
puts "succeded."
 
G

Gianfranco Cecconi

Worked for the great part of the evening on this. My feeling is that the
problem is with the web services that require complex types as input, as
the omnipresent apiRequestHeader .

This source:

---
(...)
print "Trying to keep it alive... "
apiRequestHeader = { :clientStamp => "foo",
:sessionToken => "bar" }
response = soapDriver.keepAlive:)request => { :header =>
apiRequestHeader })
exit unless response.result.apiVersion != ""
puts "done."
(...)
---

makes ruby produce the following message; the parameters have
disappeared!

---
<- "POST /betex-api-public-ws/v2/BFService HTTP/1.1\r\nAccept:
*/*\r\nContent-Type: text/xml; charset=utf-8\r\nUser-Agent:
SOAP4R/1.5.5\r\nSoapaction: \"keepAlive\"\r\nContent-Length:
393\r\nHost: api.betfair.com\r\n\r\n"
<- "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<env:Envelope
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n
xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"\n
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <env:Body>\n
<n1:keepAlive
xmlns:n1=\"http://www.betfair.com/publicapi/BFServiceV2/\">\n
<n1:request>\n </n1:request>\n </n1:keepAlive>\n
</env:Body>\n</env:Envelope>"
-> "HTTP/1.1 200 OK\r\n"
(...)
 
T

Tadeusz Bochan

Hi Gianfranco,
Have you updated the soap module ?
I haven't had enough web experience to comment on anything being
normal in this game ! ;-)
I spent most of yesterday evening with this, and, thanks to Hiroshi's
contribution, it works great !
I downloaded the latest tarball as per Hiroshi's instruction ,
unzipped it, (its a .tar.gz file, so I had some difficulty locating
the right tools for unzipping it in windows ... I used 7zip in the end).
Did a 'ruby install.rb' in the extracted directory, and VOILA! my script
worked!

I found one small problem for which I have a workaround.
It is because the Betfair xml defines a method called 'id'
-----------
a= status.result.eventTypeItems.eventType.collect do |market|
[market.name,market.id]
end
-----------
Unfortunately this name clashes with Ruby's 'id' method as in Object.id
Ruby warns that Object.id is 'deprecated' and that you should use
Object.object_id instead. So the wrong value is returned from
'market.id'.

I don't know how to get around this problem, other than substituting
'id='
for 'mktid=' in the xml first, or extracting the data manually.
eg.,
status=soap.getAllEventTypes:)request=>apiRequestHeader)
a= status.result.eventTypeItems.eventType.collect do |s|
b=s.inspect[2..-2].split("{}")[1..-1].collect {|x| eval(x)}
[b[1],b[0]]
end
(ugly, eh?)

Anyway, it's all going in the right direction.
I will keep you posted on any further issues I find.

Cheers,
Tad
 
T

Tad Bochan

Hi Hiroshi (my Hero!)

Yes! event["id"] worked just great.
I have included the wiredumps as requested.
I discovered a utility called WebServiceStudio20
<http://www.schultz.co.nz/Plone/java/WebserviceStudio20.zip/view>
which I found to be very useful on this project to
look at the xml generated.
You just point it to the address of the wsdl file.

Thank you very much for your help.
Tad


WIREDUMP for getActiveEventTypes request :-
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:getActiveEventTypes
xmlns:n1="http://www.betfair.com/publicapi/BFServiceV2/">
<n1:request>
<header>
<clientStamp>0</clientStamp>
<sessionToken>gvBJUBrywxgQuEaTxW3gmNK40ndscv5CRdaeG01z1dv5PF2HRxj5nA==</sessionToken>
</header>
<locale>en</locale>
</n1:request>
</n1:getActiveEventTypes>
</env:Body>
</env:Envelope>

WIREDUMP for getActiveEventTypes response
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:n2="http://www.betfair.com/publicapi/types/v2/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><n:getActiveEventTypesResponse
xmlns:n="http://www.betfair.com/publicapi/BFServiceV2/"><n:Result
xsi:type="n2:GetEventTypesResp"><header
xsi:type="n2:APIResponseHeader"><errorCode
xsi:type="n2:APIErrorEnum">OK</errorCode><minorErrorCode
xsi:nil="1"/><sessionToken
xsi:type="xsd:string">gvBJUBrywxgQuEaTxW3gmNK40ndscv5CRdaeG01z1dv5PF2HRxj5nA==</sessionToken><timestamp
xsi:type="xsd:dateTime">2006-09-03T15:48:04.766Z</timestamp></header><eventTypeItems
xsi:type="n2:ArrayOfEventType"><n2:EventType xsi:type="n2:EventType"><id
xsi:type="xsd:int">6423</id><name xsi:type="xsd:string">American
Football</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">61420</id><name
xsi:type="xsd:string">Australian Rules</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">7511</id><name
xsi:type="xsd:string">Baseball</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">7522</id><name
xsi:type="xsd:string">Basketball</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">6</id><name
xsi:type="xsd:string">Boxing</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">982477</id><name
xsi:type="xsd:string">Bridge</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">4968929</id><name
xsi:type="xsd:string">Combat Sports</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">4</id><name
xsi:type="xsd:string">Cricket</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">11</id><name
xsi:type="xsd:string">Cycling</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">3503</id><name
xsi:type="xsd:string">Darts</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">6231</id><name
xsi:type="xsd:string">Financial Bets</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">2152880</id><name
xsi:type="xsd:string">Gaelic Games</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">3</id><name
xsi:type="xsd:string">Golf</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">4339</id><name
xsi:type="xsd:string">Greyhound Racing</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">15</id><name
xsi:type="xsd:string">Greyhound - Todays Card</name><nextMarketId
xsi:type="xsd:int">20041615</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">468328</id><name
xsi:type="xsd:string">Handball</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">7523</id><name
xsi:type="xsd:string">Hockey</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">7</id><name
xsi:type="xsd:string">Horse Racing</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">13</id><name
xsi:type="xsd:string">Horse Racing - Todays Card</name><nextMarketId
xsi:type="xsd:int">20040862</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">7524</id><name
xsi:type="xsd:string">Ice Hockey</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">8</id><name
xsi:type="xsd:string">Motor Sport</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">315220</id><name
xsi:type="xsd:string">Poker</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">2378961</id><name
xsi:type="xsd:string">Politics</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">1477</id><name
xsi:type="xsd:string">Rugby League</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">5</id><name
xsi:type="xsd:string">Rugby Union</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">1</id><name
xsi:type="xsd:string">Soccer</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">14</id><name
xsi:type="xsd:string">Soccer - Fixtures</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">10</id><name
xsi:type="xsd:string">Special Bets</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">4726642</id><name
xsi:type="xsd:string">Surfing</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">2</id><name
xsi:type="xsd:string">Tennis</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType><n2:EventType
xsi:type="n2:EventType"><id xsi:type="xsd:int">2901849</id><name
xsi:type="xsd:string">Water Polo</name><nextMarketId
xsi:type="xsd:int">0</nextMarketId></n2:EventType></eventTypeItems><minorErrorCode
xsi:nil="1"/><errorCode
xsi:type="n2:GetEventsErrorEnum">OK</errorCode></n:Result></n:getActiveEventTypesResponse></soap:Body></soap:Envelope>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top