2

I have created one svc file and want to send data from JavaScript to service data model using Angullia framework. How to do this? Also, how to perform Ajax operations in Angullia framework?

6

If you look at the powertools project, you can see a number of examples about calling webservice methods (code can be found here : https://code.google.com/p/tridion-2011-power-tools/source/browse/trunk/)

For example, the itemcommenting powertool has a webservice like this

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceContract(Namespace = "PowerTools.Model.Services")]
public class AppDataServices : BaseService
{
        [OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
    public void Save(string applicationId, string itemId, string data)
    {
            using (var client = Client.GetCoreService())
            {
                    //Save the appdata here
                    var appdata = new ApplicationData { ApplicationId = applicationId, Data = new ASCIIEncoding().GetBytes(data) };
                    client.SaveApplicationData(itemId, new[] {appdata});
            }
    }

    [OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
            public void Append(string applicationId, string itemId, string data)
    {
            using (var client = Client.GetCoreService())
            {
                    ApplicationData appdata = client.ReadApplicationData(itemId, applicationId);
                    if (appdata != null)
                    {
                            appdata.Data = appdata.Data.Concat(new ASCIIEncoding().GetBytes(data)).ToArray();
                    }
                    else
                    {
                            appdata = new ApplicationData {ApplicationId = applicationId, Data = new ASCIIEncoding().GetBytes(data)};
                    }
                    client.SaveApplicationData(itemId, new[] {appdata});
            }
    }

....

and you call the webservice like this

//Call the service to update
var onFailure = this.getDelegate(this._onError);
PowerTools.Model.Services.AppDataServices.Append("ext:ItemCommenting", commentitemid, "<comment><user>" + commenterdescription + "</user><message>" + comment + "</message><datetime>" + commentdate + "</datetime><version>" + commentversion + "</version></comment>", null, onFailure);

Basically, the "ServiceContract" and "OperationContract" attributes tell .NET they have to create a javascript proxy for these functions.

Regarding your ajax call question, remember that the anguilla framework is built in javascript, so you can make any javascript call in your gui extension functions. Check the powertools util class (https://code.google.com/p/tridion-2011-power-tools/source/browse/trunk/PowerTools.Editor/PowerTools/Client/Shared/Scripts/utils.js) - in here they show how to do an ajax call using jquery. Note off course that in order to do that, you'll need to include the jquery library in your gui extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.