Call ImageService web service from javascript

Posted by Community Admin on 05-Aug-2018 17:48

Call ImageService web service from javascript

All Replies

Posted by Community Admin on 06-Apr-2011 00:00

Hi,

Is it possible to call the ImageService web service from the JS of a control designer? I want to pass the image ID, and retrieve back properties of the image.

Thanks
higgsy

Posted by Community Admin on 06-Apr-2011 00:00

Hello higgsy,

You can use the client manager to invoke the service call



        this._successDelegate = Function.createDelegate(this, this._successHandler);
        this._failureDelegate = Function.createDelegate(this, this._failureHandler);

        var clientManager = new Telerik.Sitefinity.Data.ClientManager();
        var serviceUrl = this._webServiceUrl;
        var urlParams = [];        
        if (this._defaultItemTypeName)
            urlParams["itemType"] = this._defaultItemTypeName;
       
        if (providerName)
            urlParams["provider"] = providerName;
       
        urlParams["published"] = true;

        var keys = [defaultImageId];
        clientManager.InvokeGet(serviceUrl, urlParams, keys, this._successDelegate, this._failureDelegate, this);


....



_successHandler: function (caller, data, request, context)
        var item = data.Item;
    ,

_failureHandler: function (error, caller, context)

        alert(error.Detail);
    ,

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 06-Apr-2011 00:00

Hi Ivan - thanks for your quick response. Can I ask why this differs from the documentation? The documentation suggests that the ImageService can be called directly? I'm certainly not questioning your answer, I'm just trying to better understand the sitefinity 4 architecture. Thanks again Higgsy

Posted by Community Admin on 06-Apr-2011 00:00

Hello higgsy,

I am calling the service through the client side using ClientManager. In its basis the ClientManager uses Sys.Net.WebRequest(); that performs an actual web request

Kind regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 07-Apr-2011 00:00

Hi Ivan,

Do you have an example of this  working anywhere? I would like to see how it is structured in a control designer script...

Thanks
higgsy

Posted by Community Admin on 07-Apr-2011 00:00

Hi Ivan,

I've almost got this working, however when I run the code something odd is happening to the URL - if I check firebug there is always a 404 error returned, and when I look at the url it looks like so:

/Sitefinity/Services/Content/ImageService.svc//e/5/c/b/e/4/b/6/-/4/7/a/4/-/4/1/c/8/-/b/e/6/5/-/5/b/e/8/1/b/3/c/5/9/a/e/?itemType=Telerik.Sitefinity.Libraries.Model.Image&published=true&provider=OpenAccessDataProvider&checkOut=true&unv_tstmp_prm=1302197071985

It looks like the key, the Image Guid - has been messed up....is there any reason why this might be happening?

Thanks
higgsy

Posted by Community Admin on 08-Apr-2011 00:00

Hello higgsy,

You should instantiate the keys as

var keys = [];

Then use push method to add a new element to the end of the array.

The same applies for urlParams (var urlParams = [];)

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed