Dear community,
has anyone managed to get SSOAP working with the ChemSpider Web APIs, using
functions which need the security token?
I use SSOAP 0.9-0 from the OmegaHat repository.
In the example code from SSOAP there is a sample which uses a token function.
Interestingly, it checks if(!is.character(token)) first (and proceeds if the
token is NOT character.) I can't test that function since I have no idea how
to get the token into "non-character" form :)
My code:
library(SSOAP)
chemspider_sectoken <- "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# (token was here)
cs <- processWSDL("http://www.chemspider.com/Search.asmx?WSDL")
# intf <- genSOAPClientInterface(,cs)
# (this fails, see below. The Mass Spec API is correctly parsed. Therefore by
hand:)
csidlist <- .SOAP(server=cs@server,
method="SimpleSearch",
.soapArgs=list(
query="Azithromycin",
token=token
),
action=I("http://www.chemspider.com/SimpleSearch"),
xmlns=c("http://www.chemspider.com/")
)
Fehler: Error occurred in the HTTP request: Unauthorized web service usage.
Please request access to this service. ---> Unauthorized web service usage.
Please request access to this service.
If one looks into the request, the doc seems to be correct:
<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns:SimpleSearch xmlns:ns="http://www.chemspider.com/">
<ns:query xmlns:ns="http://www.chemspider.com/"
xsi:type="xsd:string">Azithromycin</ns:query>
<ns:token xmlns:ns="http://www.chemspider.com/"
xsi:type="xsd:string">xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</ns:token>
</ns:SimpleSearch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Compared to the sample request from the ChemSpider homepage:
<?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>
<SimpleSearch xmlns="http://www.chemspider.com/">
<query>string</query>
<token>string</token>
</SimpleSearch>
</soap:Body>
</soap:Envelope>
To me, both look like perfectly fine XML and should be identical to the
ChemSpider XML parser. Do I need to write the token in another format? Is
something else wrong? I also tried to use .literal = T to no avail: "Error
occurred in the HTTP request: Empty query"
Best regards,
-Michael
PS: the error message from the genSOAPClientInterface call is:
Note: Method with signature "ClassDefinition#list" chosen for function
"resolve",
target signature "ExtendedClassDefinition#SchemaCollection".
"SOAPType#SchemaCollection" would also be valid
Fehler in makePrototypeFromClassDef(properties, ClassDef, immediate, where) :
'name' muss eine nicht-Null Zeichenkette sein
Zusätzlich: Warnmeldung:
undefined slot classes in definition of "ExactStructureSearchOptions":
NA(class "EMatchType")
[[alternative HTML version deleted]]
Hi Michael
Thanks for the report and digging into the actual XML documents
that are sent.
It turns out that if I remove the redundant namespace definitions
and just use a single one on the <SimpleSearch> node, all is apparently
fine.
I've put a pre-release version of the SSOAP package that does at
http://www.omegahat.org/Prerelease/SSOAP_0.9-1.tar.gz
You can try that.
I'll release this version when I also fix the issue with
XMLSchema that causes the error in genSOAPClientInterface()
BTW, the if(!is.character(token)) in the example in chemSpider.R
is an error - a mixture of !is.null() and then checking only if it
is a character.
Best,
Duncan
On 3/7/12 4:58 AM, Stravs, Michael wrote:> Dear community,
>
> has anyone managed to get SSOAP working with the ChemSpider Web APIs, using
functions which need the security token?
> I use SSOAP 0.9-0 from the OmegaHat repository.
> In the example code from SSOAP there is a sample which uses a token
function. Interestingly, it checks if(!is.character(token)) first (and proceeds
if the token is NOT character.) I can't test that function since I have no
idea how to get the token into "non-character" form :)
>
> My code:
>
> library(SSOAP)
> chemspider_sectoken <- "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
> # (token was here)
> cs <-
processWSDL("http://www.chemspider.com/Search.asmx?WSDL")
> # intf <- genSOAPClientInterface(,cs)
> # (this fails, see below. The Mass Spec API is correctly parsed. Therefore
by hand:)
>
> csidlist <- .SOAP(server=cs at server,
> method="SimpleSearch",
> .soapArgs=list(
> query="Azithromycin",
> token=token
> ),
>
action=I("http://www.chemspider.com/SimpleSearch"),
> xmlns=c("http://www.chemspider.com/")
> )
>
> Fehler: Error occurred in the HTTP request: Unauthorized web service
usage. Please request access to this service. ---> Unauthorized web service
usage. Please request access to this service.
>
> If one looks into the request, the doc seems to be correct:
>
> <?xml version="1.0"?>
>
> <SOAP-ENV:Envelope
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
>
> <SOAP-ENV:Body>
>
> <ns:SimpleSearch xmlns:ns="http://www.chemspider.com/">
>
> <ns:query xmlns:ns="http://www.chemspider.com/"
xsi:type="xsd:string">Azithromycin</ns:query>
>
> <ns:token xmlns:ns="http://www.chemspider.com/"
xsi:type="xsd:string">xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</ns:token>
>
> </ns:SimpleSearch>
>
> </SOAP-ENV:Body>
>
> </SOAP-ENV:Envelope>
>
>
>
> Compared to the sample request from the ChemSpider homepage:
>
> <?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>
>
> <SimpleSearch xmlns="http://www.chemspider.com/">
>
> <query>string</query>
>
> <token>string</token>
>
> </SimpleSearch>
>
> </soap:Body>
>
> </soap:Envelope>
>
>
>
> To me, both look like perfectly fine XML and should be identical to the
ChemSpider XML parser. Do I need to write the token in another format? Is
something else wrong? I also tried to use .literal = T to no avail: "Error
occurred in the HTTP request: Empty query"
>
> Best regards,
> -Michael
>
> PS: the error message from the genSOAPClientInterface call is:
> Note: Method with signature "ClassDefinition#list" chosen for
function "resolve",
> target signature "ExtendedClassDefinition#SchemaCollection".
> "SOAPType#SchemaCollection" would also be valid
> Fehler in makePrototypeFromClassDef(properties, ClassDef, immediate, where)
:
> 'name' muss eine nicht-Null Zeichenkette sein
> Zus?tzlich: Warnmeldung:
> undefined slot classes in definition of
"ExactStructureSearchOptions": NA(class "EMatchType")
>
>
>
> [[alternative HTML version deleted]]
>
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Dear Duncan,
thanks for the quick answer. However, I already sorted one error out - turned
out that I was just stupid: The security token worked fine once I filled all the
additional "required information" on the ChemSpider profile (which
means the token showing up on your profile is non-functional as long as that
information isn't complete - ChemSpider doesn't tell you that, or force
you to fill in the information, however.)
Best,
-Michael
Message: 114
Date: Wed, 07 Mar 2012 16:57:21 -0800
From: Duncan Temple Lang <duncan at wald.ucdavis.edu>
To: r-help at r-project.org
Subject: Re: [R] SSOAP and Chemspider: Security token?
Message-ID: <4F5803F1.2080704 at wald.ucdavis.edu>
Content-Type: text/plain; charset=ISO-8859-1
Hi Michael
Thanks for the report and digging into the actual XML documents
that are sent.
It turns out that if I remove the redundant namespace definitions
and just use a single one on the <SimpleSearch> node, all is apparently
fine.
I've put a pre-release version of the SSOAP package that does at
http://www.omegahat.org/Prerelease/SSOAP_0.9-1.tar.gz
You can try that.
I'll release this version when I also fix the issue with
XMLSchema that causes the error in genSOAPClientInterface()
BTW, the if(!is.character(token)) in the example in chemSpider.R
is an error - a mixture of !is.null() and then checking only if it
is a character.
Best,
Duncan