留言板

Setting value of attribute in serviceContext when using JSON WS

Zain Abideen,修改在9 年前。

Setting value of attribute in serviceContext when using JSON WS

New Member 帖子: 5 加入日期: 14-8-8 最近的帖子
Hi,

I am accessing liferay services in C#.NET. I need to setup attributes field of serviceContext parameter when calling a service e.g. /dlapp/update-file-entry
I am able to set workflow action using the below format:

formData.Add(new StringContent(status + ""), "serviceContext.workflowAction");


but don't know how to set value of an attribute e.g. setting fileEntryTypeId for a txt file to RichText

I've tried below format, but it is not working
formData.Add(new StringContent("211990"), "serviceContext.attributes.fileEntryTypeId");


kindly provide any pointers, help in this regard

Thanks
thumbnail
Tanweer Ahmed .,修改在1 年前。

RE: Setting value of attribute in serviceContext when using JSON WS

Expert 帖子: 322 加入日期: 10-3-11 最近的帖子
Hi Zain,

Not very sure why you are using formData.But I found few other ways of accessing Liferay Services in C#.
These links might be useful to you.

https://www.liferay.com/community/forums/-/message_boards/message/13362726
https://brunopgalvao.wordpress.com/2011/09/29/adding-users-programmatically-liferay/

For the second link, you can try doing the same for DLApp.

-Tanweer
Zain Abideen,修改在9 年前。

RE: Setting value of attribute in serviceContext when using JSON WS

New Member 帖子: 5 加入日期: 14-8-8 最近的帖子
Hi,

I have searched before posting here but using soap is not an option. We can only use Json. And besides this is something which is not anywhere else so it could help anyone else.

liferay documentation says when consuming JSON WS, parameters can be passed using multipart forms thats why we are using MultipartFormDataContent (type of formData)
thumbnail
Meera Prince,修改在9 年前。

RE: Setting value of attribute in serviceContext when using JSON WS

Liferay Legend 帖子: 1111 加入日期: 11-2-8 最近的帖子
HI
Please go through following article and please cover below sections carefully in the article .it may help you..
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/json-web-services

https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/service-conte-1

Object parameters
Inner Parameters
Sending files as arguments

Inner Parameters

When you pass in an object paramter, you’ll often need to populate its inner parameters (i.e., fields). Consider a default parameter serviceContext of type ServiceContext (see the Service Context section in this chapter to find out more about this type). To make an appropriate call to JSONWS, you might need to set the serviceContext parameter’s fields addGroupPermissions and scopeGroupId.

You can pass inner parameters by specifying them using dot notation. Just apppend the name of the parameter with a dot (i.e., a period, .), followed by the name of the inner parameter. For the ServiceContext inner parameters we mentioned above, you’d specify serviceContext.addGroupPermissions and serviceContext.scopeGroupId. They’re recognized as inner parameters and their values are injected into existing parameters before the API service method is executed.

Inner parameters aren’t counted as regular parameters for matching methods and are ignored during matching.

Tip: Use inner parameters with object parameters to set inner content of created parameter instances!
Regards,
Meera Prince
Zain Abideen,修改在9 年前。

RE: Setting value of attribute in serviceContext when using JSON WS

New Member 帖子: 5 加入日期: 14-8-8 最近的帖子
Hi Meera,

Thanks a lot for taking out time for this. I have tried combining the inner parameters and object parameters like below

 
               Dictionary<string, object> vals = new Dictionary<string, object>();

                vals.Add("fileEntryTypeId", 12215);

                MemoryStream stream = new MemoryStream();
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Dictionary<string, object>));
                serializer.WriteObject(stream, vals);
                string serializedDict = Encoding.UTF8.GetString(stream.ToArray());

                formData.Add(new StringContent(serializedDict), "+serviceContext.attributes"); //serviceContext._attributes didn't work either
</string,></string,></string,>


but didn't get it working

I'm thinking of using xml serialization... didn't work emoticon

but can you give me a sample or any other advice