I’m trying to call a web service, and am not really finding a straight forward example on how to do this anywhere. I’ve seen an example in the demo projects, but I was hoping for something stupidly simple and outlined. The PDF’s don’t have any demo code, so I’m kind of at a loss. Is there any projects or sample code that just list the steps outright?
Here is what I’m trying to do:
1. Create a roUrlTransfer object 2. Call a web service 3. Capture the returning XML
Seems pretty simple, but I can’t find anything that details the steps. Help??
No responses, so maybe too big of a question to ask. Let me post what I have been working on today, and perhaps you can tell me what’s correct/incorrect?
Function TestWebServiceCall() As String
'Set the Web Service URL - (JUST A WEB SERVICE I FOUND FOR TESTING PURPOSES)
webServiceURL = "http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=CA "
'Set Attributes
webTransfer = CreateObject("roUrlTransfer")
webTransfer.SetPort(CreateObject("roMessagePort"))
webTransfer.SetUrl(webServiceURL)
webTransfer.AddHeader("Content-Type","application/x-www-form-urlencoded")
??????????
XmlTransfer = webTransfer.GetToString()
Return XmlTransfer
End Function
Any thoughts as to how to improve this and make it fit my goal? Is this the right path?
Depending on the level of control you need over the transfer, there are several different ways to do this. roURLTransfer is documented in the Component Reference document in the SDK. The simplest way to fetch the contents of a URL would look like this:
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://api.example.com/someMethod")
result = xfer.GetToString()
“RokuChris” wrote:
Depending on the level of control you need over the transfer, there are several different ways to do this. roURLTransfer is documented in the Component Reference document in the SDK. The simplest way to fetch the contents of a URL would look like this:
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://api.example.com/someMethod")
result = xfer.GetToString()
Thanks Chris,
So I built the following, and it’s not returning anything, even though I can see the web service works. What should I be expecting from this, should I see the XML string? Right now, nothing is
Function TestWebServiceCall_2() As String
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=CA ")
result = xfer.GetToString()
Return result
End Function
Print(TestWebServiceCall_2())
“jkard” wrote:
So I built the following, and it’s not returning anything, even though I can see the web service works. What should I be expecting from this, should I see the XML string? Right now, nothing is
Function TestWebServiceCall_2() As String
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=CA ")
result = xfer.GetToString()
Return result
End Function
Print(TestWebServiceCall_2())
Two things. 1) That trailing space in your URL could be the problem. 2) The call to TestWebServiceCall_2() is just hanging out in space. It should be inside your Main() for it to work.
Function TestWebServiceCall_2() As String
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=CA")
result = xfer.GetToString()
Return result
End Function
Sub Main()
Print(TestWebServiceCall_2())
end Sub
Ah! Looks like it was the extra space at the end, nice catch! I actually was calling the method from Main(), but forgot to include that, sorry for the confusion.
So the next question would be, now that I have the XML in a string, can I pass it to a XML object for parsing?