angularjs - get data from webservice on other domain/server
hi,
I'm trying to get some data to a custom property editor from a remote server, which runs a webservice.
The webservice requires credentials and these should be hidden for the users.
I would not call the webservice directly because your authentication details are in visible in Javascript. What I would do is create a WebAPI Controller. Let that WebAPI Controller communicate with the Webservice that needs the authentication. You can even cache results then or do other modification on the data before sending the result back to Angular.
angularjs - get data from webservice on other domain/server
hi,
I'm trying to get some data to a custom property editor from a remote server, which runs a webservice. The webservice requires credentials and these should be hidden for the users.
Where do i start?
Hi Tom
What webservice is it? And what does your current code look like?
/Jan
For starters I'm just trying to reach a public webservice. I've made this resource:
And then I'm calling the resource like this:
It seem like this is not the right way to do it - I'm getting this error:
No 'Access-Control-Allow-Origin' header is present on the requested resource
Hi Tom,
I would not call the webservice directly because your authentication details are in visible in Javascript. What I would do is create a WebAPI Controller. Let that WebAPI Controller communicate with the Webservice that needs the authentication. You can even cache results then or do other modification on the data before sending the result back to Angular.
If you need a real world example how to use a WEbAPI Controller in combination with Angular in Umbraco check this Blog post from Warren Buckley http://creativewebspecialist.co.uk/2013/12/12/umbraco-7-creating-a-generic-settings-editor-with-webapi-angularjs/.
Hope this helps,
Richard
Hi Richard,
Thanks a lot! Though I've already figured out that I needed to create a WebApi controller instead, the blog post is a great resource.
Now I just have to connect to the webservice...
Hi Tom,
HTTPClient is your friend. You might want to check out this article for a complete example.
http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client
Cheers,
Richard
is working on a reply...