Desktop Web Service Woes- Need Help ASAP

I am not knowledgeable about most web stuff. but I need to get a an app done that uses a Web service ASAP (like today) and am having big issues. In my initial testing it seemed to work… but more extensive testing i showing a showstopper.

I am using the service’s search function to retrieve chemical information … I first have to search to get a record ID from teh service and can then can use that to get other info once I have that.

The search request fails on some items (compound names) with “HTTP Error 400. The request is badly formed”, but works with others, which makes it hard to figure out… And i can’t see a significant difference between the names it works for and and the ones it dos not.

The service has a web page where you can enter the search term (and your login token), submit the request and see the returned result. THAT WORKS for the compound name that is failing In my code, so it can’t be something in the name itself.

The service has 4 APIs: SOAP 1.1, SOAP 1.2, HTTP GET and HTTP POST. I don’t know which

I could not get the Xojo Soap class to work (Don’t know if it is 1.1 0r 1.2) at all so I used HTTP GET as it seemed simplest.

Any suggestion/help would be gently appreciated

This is the page:

This is my code (in a subclass of HTTPSocket) :

[code]Private Function GetChemSpiderID(CAS_No as String, Name as String, TimeOut as integer=-1, Retries as integer = -1) As String
Static Cmd As String = “”+CSToken

Dim theCmd As String = Cmd.Replace(“CAS_No”, CAS_No)
Dim XmlStr as String = DefineEncoding(GetTimed(theCmd, TimeOut, Retries), Encodings.UTF8)

Dim XDoc As New XmlDocument(XmlStr)
Dim Node as XmlNode = XDoc.DocumentElement

Dim CS_ID as String
If Node.ChildCount > 0 then CS_ID = Node.FirstChild.FirstChild.Value.Trim

If CS_ID.LenB = 0 then
theCmd = Cmd.Replace(“CAS_No”, Name)
XmlStr = DefineEncoding(GetTimed(theCmd, TimeOut, Retries), Encodings.UTF8)

XDoc= NEW XmlDocument(XmlStr)
Node  = XDoc.DocumentElement
If Node.ChildCount > 0 then CS_ID = Node.FirstChild.FirstChild.Value.Trim

End if

Return CS_ID
End Function

[code]Private Function GetTimed(Query as String, TimeOut as integer=-1, Retries as integer = -1) As String

If TimeOut < 0 then TimeOut = TimeOutSec
If Retries < 0 then Retries = me.Retries
Retries = Retries + 1

Dim RtnVal as String

While Retries > 0
RtnVal = Get(Query, TimeOut)

If ErrorCode = 0  then
  Return RtnVal
ElseIf ErrorCode = -1 then
  Retries = Retries -1
  Raise New HTTPSocketException( ErrorCode)
End if


Return “”
End Function

This is just a hunch, but it sounds like you need to URL encode the query string (which I think is the “CAS_No” param in your GetChemSpiderID function).

For example, maybe you could try this:

Dim theCmd As String = Cmd.Replace("CAS_No", EncodeURLComponent(CAS_No))

Thanks Tim

it looks like I got it to work (at least with the test dataset).

Not sure what worked but I increased the timeout, increased the retries, If I got a failure I tried enclosing the names in quotes, and if THAT failed I tried removing all the spaces (which is a last resort as it can give the wrong results sometime)

  • Karen