Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jkard
Visitor

Calling a Web Service - roUrlTransfer

Good day!

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??

Thanks
Jay
0 Kudos
7 REPLIES 7
jkard
Visitor

Re: Calling a Web Service - roUrlTransfer

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?

Thanks!
Jay
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Calling a Web Service - roUrlTransfer

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()
0 Kudos
jkard
Visitor

Re: Calling a Web Service - roUrlTransfer

"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())


Thanks
Jay
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Calling a Web Service - roUrlTransfer

"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
0 Kudos
jkard
Visitor

Re: Calling a Web Service - roUrlTransfer

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?

Thanks Chris!

Jay
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Calling a Web Service - roUrlTransfer

"jkard" wrote:
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?


Yep. roXMLElement is documented along with some example code in the BrightScript Reference Manual.
0 Kudos
jkard
Visitor

Re: Calling a Web Service - roUrlTransfer

Great, thanks Chris, will check it out now!
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.