cancel
Showing results for 
Search instead for 
Did you mean: 

How to create NamedValue in .NET 2003 / .NET 2005

kannank
Champ in-the-making
Champ in-the-making
Hi,

Thanks for your earlier answers.I am trying to upload an image file from local computer to alfresco server.I have referred the following URL from your forum as reference,
http://forums.alfresco.com/viewtopic.php?t=880&highlight=contentwebservice+write

I am currently working in .NET 2003 and .NET 2005 with C# - I need two clarification in the above URL post.

1.How to create NamedValue in .Net 2003/2005 - I guess the above URL is in java and when I try to create NamedValue in .NET it looks different (No overloading available in dotnet for NamedValue) - So please tell me how to the create NamedValue property in .NET?

2.CMLCreate in .NET also looks different than java - The following is the code snippet with "build sucess",

NamedValue[] properties = new NamedValue[] { new NamedValue() };
properties[0].name          = "test.txt";
properties[0].value         = "{http://www.alfresco.org/model/content/1.0}name";
                          
Alfresco.RepositoryWebService.ParentReference parent    = new Alfresco.RepositoryWebService.ParentReference();
parent.store          = reference.store;
parent.uuid           = reference.uuid;    
         
CMLCreate create  = new CMLCreate()
create.id               = "1";
create.parent        = parent;
create.property     = properties;
create.type            = "{http://www.alfresco.org/model/content/1.0}content";

CML cml             = new CML();
cml.create          = new CMLCreate[1] {(create)};
                           
UpdateResult[] result          = repoService.update(cml);
Reference newcontentnode = result[0].destination;

Is that correct?What is the correct "properties[0].value" to be used?When I build this code, it says sucessfully builded and when I tried to execute this code this throws error at "repoService.update(cml)" - The error is thrown at invoke method (in reference.cs page),

public UpdateResult[] update(CML statements) {
object[] results = this.Invoke("update", new object[]{statements});
return ((UpdateResult[])(results[0]));
                                                                    }

I am not sure what is the problem - Can you please give some clue to overcome this.

Your early message is much appreciated,

Looking for your message,

Thanks,
K.Kannan.
8 REPLIES 8

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Lokinig at the code snipit supplied it looks like you are creating the namedValue list correctly.  The name of the property looks correct.

I thnk the bits you are missing are on the parent reference.  You need to set the assocication type and nad name.  Try this …

Alfresco.RepositoryWebService.ParentReference parent = new Alfresco.RepositoryWebService.ParentReference();parent.store = reference.store;parent.uuid = reference.uuid; parent.associationType = "{http://www.alfresco.org/model/content/1.0}contains";parent.childName= "{http://www.alfresco.org/model/content/1.0}" + folderName ;‍‍‍‍‍‍‍‍‍

Let me know how you get on,

Cheers,
Roy

kannank
Champ in-the-making
Champ in-the-making
Hi,

Thanks for your immediate response - It was much useful for us today.

Now I am able create the node and able to write the image into that node with the help of your code. Still I have couple of errors here,
1.The node created is in the form of some numbers - How do i pass my image name to that newly created node?

2.Immediately after content.write statement the following error is thrown,

Error (InnerException) - System.Xml.XmlException:Root element is missing - at System.Xml.Xmldocument.Load(XmlReader reader) - at Miscrosoft.Web.Services3.SoapEnvelope.Load(Stream inStream) etc.

Error (Source) - Microsoft.web.services3

Error (Stack trace) - at Alfresco.ContentWebService.ContentService.write in Reference.cs line 121

The modified code snippet is as follows,

Start …

// Write the contents into the node.
ContentFormat formatval = new ContentFormat();
formatval.mimetype        = "text/html";
                          
// Get the text value from file.
FileStream fsfile = null;
fsfile = File.Open("D:\\test.txt", FileMode.Open);
byte[] toSend = new byte[fsfile.Length];
fsfile.Read(toSend, 0, System.Convert.ToInt32(fsfile.Length));
fsfile.Close();

NamedValue[] properties = new NamedValue[] { new NamedValue() };
properties[0].name = "test.txt";
properties[0].value = "{http://www.alfresco.org/model/content/1.0}name";

Alfresco.RepositoryWebService.ParentReference parent = new Alfresco.RepositoryWebService.ParentReference();
parent.store = reference.store;
parent.uuid = reference.uuid;
parent.associationType                                = "{http://www.alfresco.org/model/content/1.0}contains";
parent.childName                                        = "{http://www.alfresco.org/model/content/1.0}" + "text.txt";

CMLCreate create = new CMLCreate()
create.id = "1";
create.parent = parent;
create.property = properties;
create.type = "{http://www.alfresco.org/model/content/1.0}content";

CML cml = new CML();
cml.create = new CMLCreate[1] {(create)};

UpdateResult[] result = repoService.update(cml);
Reference newcontentnode = result[0].destination;

Alfresco.ContentWebService.Reference contentreference = new Alfresco.ContentWebService.Reference();
contentreference.store= spacesStore2;
contentreference.uuid = newcontentnode.uuid;  

this.contentService.write(contentreference, "{http://www.alfresco.org/model/content/1.0}content", toSend, formatval);

End …

The soaperror is thrown immediately after content.write statement - Still the picture or text file is uploaded to alfresco and I am able see the image in alfresco login - Is this error allowed?

Secondly I want to pass the imagename or filename with extension (Eg - image1.jpg or test.txt)to the newly created node - How to do that?Is that "parent.child" tag is correct - Please tell us how to get the image name in the node instead of numbers shown now.

Looking for your immediate reply,

Thanks,

K.Kannan.

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Try …

…formatval.encoding = "UTF-8"; …‍‍‍‍‍‍‍

… it might stop the exception occuring.

The node is apprearing with a GUID as a name becuase the name attribute of the node has not been set.  Although looking at your code it appears that should not be the case.  Can you check that the properties array does have the values for the name property in it when it is set on the CMLCreate object.

Cheers,
Roy

kannank
Champ in-the-making
Champ in-the-making
Hi,

Thanks for your high speed response.I appreciate that very much.

First, I have tried that "formatval.encoding = UTF-8" and still I get the same exception as above - I think those exceptions I can handle temporarily.

Second, most importantly I want to set the image or file name - I have tested the properties name value with message (properties[0].name.ToString()) and that is showing the correct value - Whether the "parent.childName" is correct?

I am not sure how to see the name property values when it is set on CMLCreate object - Please help us to solve this - We need this very urgently.

Looking for your help,

Thanks,

K.Kannan.

kannank
Champ in-the-making
Champ in-the-making
Hi,

Still I am searching the various possibilities to get the image name in the node - Now the posted code works fine and image is transferred, however the node diplays GUID number instead of image name.

I am attaching the error shown in the alfresco command line when I tried content.write method in my code,

{http://xml.apache.org/axis/}hostname:newdev

at org.alfresco.repo.webservice.content.ContentWebService.write(ContentWebService.java:240)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
y.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:69
9)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
e.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
12:54:38,234 ERROR [encoding.ser.BeanSerializer] Exception:
java.io.IOException: Non nillable element 'message1' is null.
at org.apache.axis.encoding.ser.BeanSerializer.serialize(BeanSerializer.
java:215)
at org.apache.axis.encoding.SerializationContext.serializeActual(Seriali
zationContext.java:1502)
at org.apache.axis.encoding.SerializationContext.serialize(Serialization
Context.java:978)
at org.apache.axis.encoding.SerializationContext.serialize(Serialization
Context.java:678)
at org.alfresco.repo.webservice.content.ContentFault.writeDetails(Conten
tFault.java:156)
at org.apache.axis.message.SOAPFault.outputImpl(SOAPFault.java:165)
at org.apache.axis.message.MessageElement.output(MessageElement.java:120
😎
at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:139)
at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478)
at org.apache.axis.message.MessageElement.output(MessageElement.java:1208)
        at org.apache.axis.AxisFault.output(AxisFault.java:759)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:301)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
        at org.apache.axis.Message.writeTo(Message.java:539)
        at org.apache.axis.transport.http.AxisServlet.sendResponse(AxisServlet.j
ava:902)
        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:77
7)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
e.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)  …

Can you able to guess what could be the problem?

Please tell me some solution to transfer the image name to the node.

Looking for your help,

Thanks,

K.Kannan.

kannank
Champ in-the-making
Champ in-the-making
Hi,

I am still not able to get the image name - I have tried various things and still not getting the result.

Please look at the error message & my sample code and give me some possible solution to get the image name in the node when upload.

Looking for suggestion,

K.Kannan.

kannank
Champ in-the-making
Champ in-the-making
Hi,

Today I have sucessfully solved the problem in image uploading in .NET2003 - I understand the problem due to interchange of name and value properties of namedvalue - The correct named value code is,

NamedValue[] properties = new NamedValue[] { new NamedValue() };           
properties[0].name   = "{http://www.alfresco.org/model/content/1.0}name";
properties[0].value = "test.txt";

Now the alfresco server side errors mentioned above also disappeared and upload image is functioning properly.

Thanks very much for Roy and his team.

Regards,

K.Kannan.

manfung78
Champ in-the-making
Champ in-the-making
Hi,

I have added an image file upload via web services example in the .net project which can be downloaded with svn from forge

http://forge.alfresco.com/scm/?group_id=16