Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
inserting an asset with RTP via web service
JasonCopsey
Hi there,
we are trying to automate the insertion of about 30000 assets into mediabin using the webservice.
We have come up against a brick wall whilst trying to use the insertasset_unc method - we keep getting an invalid cast error.
Do you have any example code which may help us?
Cheers
Jason Copsey
Find more posts tagged with
Comments
Migrateduser
Er... which language?
Folco Banfi
msnider
It may be more helpful than a sample if you can post a snippet of your code to help locate the reason for the invalid cast error.
Mark
JasonCopsey
Good point.
Language = C# .net
Code snippet:
private static media.MBRunTimePrimitive getMBPrimitive(
string id,
object parameterValue)
{
media.MBRunTimePrimitive primitive = new media.MBRunTimePrimitive();
primitive.mID = id;
primitive.mParameters = new media.MBRunTimeParameter [0];
primitive.mParameters[0] = getMBParameter(id, parameterValue);
return primitive;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
media.MBRunTimePrimitive [] primitives = new TestOdbcEtc.media.MBRunTimePrimitive [1];
primitives[0] = new media.MBRunTimePrimitive();
primitives[0].mID = "{8CFEE2C2-F805-4440-9E22-D8B1A098A0B5}";
primitives[0].mParameters = new media.MBRunTimePrimitive [4];
primitives[0].mParameters[0] = getMBPrimitive("{5B250FFA-670E-4C81-ADE5-3AABFBF6F8F8}", "new folder");
primitives[0].mParameters[1] = getMBPrimitive("{451A7601-443B-4849-822C-4CE4A2650B61}", "OTES002");
primitives[0].mParameters[2] = getMBPrimitive("{DF53B366-7C97-4154-B050-CFC2B7EB8562}", "test company");
primitives[0].mParameters[3] = getMBPrimitive("{B76EDE84-F9C8-46CD-85AA-F69E82B7F17F}", 12345);
media.MediaBinServer server = new media.MediaBinServer();
server.Credentials = System.Net.CredentialCache.DefaultCredentials;
//server.BeginPersistentConnection(true);
server.InsertAsset_UNC(
@\\server9\test\5000426154993.tif
,
"bob2.tif",
"{B5E3E6BA-E662-48A0-A237-6E910E2570DC}",
"{40525909-E124-4773-8559-0661DB5F0170}",
primitives,
850,
true);
We build the array of Primitives (not sure whether we do it correctly) and then pass the array to the call to the web method.
I have a feeling it's to do with the array we are creating - but I'm not sure if we are even on the right wavelength.
Thanks for your replies.
Jason Copsey
msnider
Your function getMBPrimitive is not needed.....you've already created the runtime primitive before you call the function. Also, you are mixing runtime primitives with runtime parameters in the following code:
primitives[0].mParameters = new media.MBRunTimePrimitive [4];
primitives[0].mParameters[0] = getMBPrimitive("{5B250FFA-670E-4C81-ADE5-3AABFBF6F8F8}", "new folder");
primitives[0].mParameters[1] = getMBPrimitive("{451A7601-443B-4849-822C-4CE4A2650B61}", "OTES002");
primitives[0].mParameters[2] = getMBPrimitive("{DF53B366-7C97-4154-B050-CFC2B7EB8562}", "test company");
primitives[0].mParameters[3] = getMBPrimitive("{B76EDE84-F9C8-46CD-85AA-F69E82B7F17F}", 12345);
Try changing it to:
primitives[0].mParameters = new media.MBRunTimeParameter[4];
primitives[0].mParameters[0] = getMBParameter("{5B250FFA-670E-4C81-ADE5-3AABFBF6F8F8}", "new folder");
primitives[0].mParameters[1] = getMBParameter("{451A7601-443B-4849-822C-4CE4A2650B61}", "OTES002");
primitives[0].mParameters[2] = getMBParameter("{DF53B366-7C97-4154-B050-CFC2B7EB8562}", "test company");
primitives[0].mParameters[3] = getMBParameter("{B76EDE84-F9C8-46CD-85AA-F69E82B7F17F}", 12345);
Hope this helps,
Mark
Sky_Rumsey
Hi,
I work alongside Jason and have started to develop applications that utilise the MediaBin server.
I have unfortunately gotten into the same problems as it seems Jason had done some time ago (I have attempted to use the Insert_Asset webmethod from scratch without using the above code).
Whilst Jason used Insert_Asset_UNC I am using simply Insert_Asset(byte[] etc.etc) where I am streaming the file across so there are slight differences in code technique.
My program flow is this:
I retrieve a bespoke task (using GetTask(taskID)) we have created which consists of a TIFF DECODER and a METADATA ADDER primitives. I then create an interface to let the user populate the Metadata. Here is where I first noticed that the TIFF DECODER does not return any MBParameters. Fine so far.
The user then populates the textboxes as expected. I then cast the MBPrimitive[] into a MBRunTimePrimitve[] and where I reach the elements I simply copy them e.g.
( this is to show what the variables are)
PSEUDO_CODE
MediaBin.MBPrimitive[] prims = mbs.GetTask(taskID).mPrimtives
MediaBin.MBRunTimePrimitive[] rtps = null
END
// main code example
private void copyPrimitiveArrayToRunTimePrimitiveArray()
{
rtps = new ClientTest.MediaBin.MBRunTimePrimitive[prims.Length];
for(int i=0;i<prims.Length;i++)
{
rtps
= new ClientTest.MediaBin.MBRunTimePrimitive();
rtps
.mID = prims
.mID;
if(prims
.mParameters!=null)
{
rtps
.mParameters = new MediaBin.MBRunTimeParameter[prims
.mParameters.Length];
for(int x=0;x<prims
.mParameters.Length;x++)
{
rtps
.mParameters = new MediaBin.MBRunTimeParameter();
rtps
.mParameters.mID = prims
.mParameters.mID;
rtps
.mParameters.mElements = prims
.mParameters.mElements;
}
}
}
}
(I also use CopyTo method for double checking though no difference).
The program then passes this to the webmethod Insert Asset
e.g.
bool bResult = mbs.InsertAsset(imageBytes, filename, contID, taskID, rtps, codepage, out jobID);
And this is where the problem occurs. I get error:
---------------------------
Server was unable to process request. --> MBException: Object reference not set to an instance of an object.
---------------------------
In the main code example, since the TIFF ENCODER has no parameters (object: prims), no parameters are set in the rtps object. So, for testing I create an empty class reference, e.g.
An else clause is added to the condition
if(prims
.mParameters!=null)
{
...
}
else
{
rtps
.mParameters = new MediaBin.MBRunTimeParameter[1];
rtps
.mParameters[0] = new MediaBin.MBRunTimeParameter();
}
I then run the code and get
---------------------------
Server was unable to process request. --> MBException: Specified cast is not valid.
---------------------------
This is like Jason's original error problem!
The difficulty lies in that to further test whether the parameter object must then contain an instantiated MBMetdataElement object, I need to know the ID of the TIFF DECODER parameter which I am not sure how to retrieve (I haven't delved into this as it seems to start venturing at a tangent which shouldn't be the case!). I would also, based on using the front-end client and seeing the params for the TIFF DECODER, have to add a filename which seems irrelevant as it's passed in the Insert_Assert.
So, pleae can you help me in locating what I am doing wrong. Because I am casting the MBPrimitives to MBRuntimePrimitives in simple loops, I would have thought most of these problems would have been resolved e.g. incorrect ids and value types, but it seems not. I can use the Insert_Asset fine when uploading a Jpg with the Insert unmodified task. However, I do seem to have trouble uploading a Tif with this functionality (a test tif image was created using paint, I assume this should be fine?) (I have just observed this behaviour before sending this reply!). The main question I am asking myself is whether the TIFF DECODER needs parameters set or am I barking up the wrong tree so to speak and the object not set is to do with some MBRunTimePrimitive parameter that I have failed to set whilst looping through the returning MBPrimitive[]? I have made sure that the user interface gets all required fields populated and Ints are cast as Ints.
If it would be a lot easier for you, is there any chance you could provide an c# code that calls an InsertAsset(byte[] etc) with a MBRunTimePrimitive[] and a task that has Tiff Decoder and MetaData Adder rather than adjusting what could be my fatally flawed code!
In all, any help would be most appreciative.
Kind Regards
Sky Rumsey
Edited by Sky_Rumsey on 11/24/05 09:01 AM (server time).
msnider
Here's a code snippet that adds the "Author" metadata during insertion (I've also attached the task file ):
taskID = "{E4F75100-D0BF-4FA8-A871-4C65201628C6}"; //ID of the task "Insert TIFF with comments"
MBRunTimePrimitive[] rtpPrimitives = new MBRunTimePrimitive[1];
rtpPrimitives[0] = new MBRunTimePrimitive();
rtpPrimitives[0].mID = "{8CFEE2C2-F805-4440-9E22-D8B1A098A0B5}"; //ID of Metadata Adder primitive
rtpPrimitives[0].mParameters = new MBRunTimeParameter[1];
rtpPrimitives[0].mParameters[0] = new MBRunTimeParameter();
rtpPrimitives[0].mParameters[0].mID = "{E94A2180-582A-11D4-8104-0050DA27F4FC}"; //ID of the Author metadata item
rtpPrimitives[0].mParameters[0].mElements = new Object[1];
MBParameterElement element = new MBParameterElement();
element.mValue = "Super User"; //The new value we want to set
rtpPrimitives[0].mParameters[0].mElements[0] = element;
bResult = mMediaBinServer.InsertAsset( buffer, assetName, containerID, taskID, rtpPrimitives, 850, out jobID );
Sky_Rumsey
Hi,
Thank you for taking to time to reply to my post.
Sadly, I have been unable to get your example code to work. It exhibits the same behaviour as I previously stated:
Server was unable to process request. --> MBException: Specified cast is not valid.
I have streamlined my code to be reduce any problematic factors eg (attached test code is slightly different):
{
MemoryStream ms = new MemoryStream();
// image is just an instantiated Image object
image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
ms.Position = 0;
byte[] imageBytes = ms.ToArray();
ms.Close();
// as given in the code. The Task had been installed in the Mediabin Server
string taskID = "{E4F75100-D0BF-4FA8-A871-4C65201628C6}";
// TestMethod() is an exact copy of the prievously posted code by msnider except it returns the array rather than attempts to insert within that method
MBRunTimePrimitive[] rtps = TestMethod();
string jobID = string.Empty;
string contID = "{6B3536B3-DCE5-4F9E-AF23-C63EF8F4430C}";
try
{
bool bResult = mbs.InsertAsset(imageBytes, "test.tif", contID, taskID, rtps, 850, out jobID);
if(!bResult)
{
MediaBin.MBJob job = mbs.GetJob(jobID);
MessageBox.Show(ParseMBJob(job));
}
else
this.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I have attached a very simple form that comprises of the above code plus the example code posted previously. I have also attached the test tif file that I have been using.
To use the Test Code, simply create a new C# project and then add the file. The code tries to find the image at C:\Test.tif so either save the image in that location or change the code to point to it. The main thing is to add a webreference to the MediaBin WebServive and update the namespace (calling the webreference MediaBin should alleviate this problem but not 100% sure!)
If someone could please try and use this code and let me know if it works, then I can assume there is a problem with our server. Otherwise, if the code looks fine (and it really is pretty bareboned) and it errors, then I can only assume there is a more complicated issue outside of my control.
Thanks in advance
Kind Regards
Sky Rumsey
Sky_Rumsey
Here is the attached file which I missed last post.
The zip comprises of the .cs file and the test.tif file. Place the tif in c:\ (if you choose not to, be sure to amend the code) and open a project and add the .cs file. Add a WebReference to MediaBin called MediaBin and change the namespace of the .cs file to be the name of the project (or whatever if custom). You may need to a reference to System.Drawing as well. And that should be that!
Thanks
msnider
What version of MediaBin are you running? The sample code should have worked for you, so go ahead and open a support ticket with Interwoven support... I'll be more able to diagnose your specific issue from there.
Mark
Sky_Rumsey
Hi Mark,
We are running 4.5 SP1.
Since this is being used by our customers, our Sys Admin (Jason) is a little reluctant at present to install SP2 as everything else seems okay (though I know he raised a case for RTP metadata revision where a patch has now recently been made available which he needs to install).
I have raised a case 4 days ago. The number is 1229003. Its current status is researching. The details of the case are as per my origingal post, and I have not amended since. If you require any further info, please let me know.
Thank for your assistance in this matter.
Kind Regards
Sky
Konidala
Hi Jason,
May I know how may hours it taken for you to ingest the 30000 assets into mediabin using the webservices?
Thanks
Sky_Rumsey
Hi Konidala,
I have taken over the role of automating the insertion process (I work with Jason). As the posts above describe, we are sadly still experiencing difficulties in getting this underway.
I will endeavour to keep you informed of processing times, though the variations of which will depend on processing power, bandwith and file size etc.
Regards
Sky
Sky_Rumsey
Hi,
I have posted here as this issue may be more of a general coding issue then a bug, and users might have some ideas of best practice and alternatives.
I received an updated DLL through Support and this resolved some issues. I then found another issue, though not as debilitating as the last one! I have replied to the support help, below is a near enough copy of what I wrote.
Here is my posted case reply:
Thanks for the updated DLL. This does seem to fix the problem. However, there is now another issue that I had briefly mentioned in my original case regarding the uploading of a tif image.
I can insert a file unmodified as a Jpg fine. However, when I try to use a Tif file (without RTPs for testing) I get the error
Job type: InsertionJob
Job state: JobFailed
Job start: 06/12/05 12:03:53
Job finish: 06/12/05 12:03:54
Job messages: Exception of unknown origin in Primitive {EA4C42E1}!
ERROR: Job {0225433E-0A97-41F5-AE98-17253476410D} Returned error by primitive TIFF Decoder from ForwardSetup(); RC = The operation failed. Check the log output for details
Now, the interesting point here, is the way I read in the byte[].
My current method is as follows
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
ms.Position = 0;
byte[] imageBytes = ms.ToArray();
ms.Close();
where image is an instantiated Image object (Image.FromFile(string filename) will do this)). Changing the ImageFormat to ImageFormat.Jpg (and having the image object being a Jpg) will work, but not the Tif.
However, if I am reading the byte[] directly from the file as done in the MediaBinWebService SDK the Tif insert works. e.g.
string file =
@c:\test.tif
;
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
byte [] imageBytes = new byte[fs.Length];
fs.Read(imageBytes, 0, imageBytes.Length);
fs.Close();
I hope this information is of use, and if there is a solution, please let me know. Using the FileStream isn't a major issue fortunately, as this is a windows app, but it does mean a small rewrite of some components that I would like to avoid.
Kind Regards
Sky Rumsey
kipioneer
I am trying something similar in java but for one image at a time via a form designed for the purpose and a servlet.
The attached file has the relevant code and my musings on it.
I have followed Mark's example as closely as I could allowing for the differences between C# and java.
The "MBException: Specified cast is not valid." is a bit annoying as the upload of the image works a treat.
What have I done wrong?
Jase_Norwich_UK
Not technically related to my first post on this but.
We tracked down the specified cast is not valid after:
Ensuring the RTP Parameter arrays were all correctly set - turns out in the first attempts we missed out 1 layer of arrays.
Once this was done we got Specified Cast is Not Valid when we attempted to insert the wrong type of information into the metadata detailed in the RTP Task.
Check your Metadata Data-type and ensure you are passing the correct type in your code. I passed a string when the metadata was expecting an int and I received the cast error you got.
Hope this helps you.
Jase