Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Best way to search using API
kbaley
Just trying to search for assets using the web services API. Code for what I have is below but I'm missing something as I'm getting an error ("Object reference not set to an instance of an object"). Basically, I'd like to know what's wrong and if I'm taking the right approach.
MediaBinWebService.MediaBinServer server = new MediaBinWebService.MediaBinServer( );
server.Credentials = myCredentials;
MediaBinWebService.MBSearchableMetadata[] meta = server.GetSearchableMetadata( );
MediaBinWebService.MBSearchConstraint[] searchConstraints = new MediaBinWebService.MBSearchConstraint[1];
MediaBinWebService.MBSearchCriteria searchCriteria = new MediaBinWebService.MBSearchCriteria( );
searchConstraints[0] = new MediaBinWebService.MBSearchConstraint( );
searchConstraints[0].mMetadata = new MediaBinWebService.MBMetadata( );
searchConstraints[0].mMetadata.mName = "MyCustomMetadata";
searchConstraints[0].mMetadata.mValue = Guid;
searchConstraints[0].mSearchOperator = "Equality";
searchCriteria.mSearchConstraints = searchConstraints;
searchCriteria.mContainerID = server.GetRootContainer( ).mID;
string[] assets = server.Search_GetAssetIDsOnly( searchCriteria );
Find more posts tagged with
Comments
Migrateduser
You might find the MediaBin Webcast recording to be of some use. There is a slide search, and I'm pretty the code was covered in the demo as well.
http://devnet.interwoven.com/site.fcgi/webcasts/index.html#webcast-22
lissa
kbaley
Thanks, lissa. Checked out the slide show and will give it a shot. However, it looks like those examples use the Script Model interfaces and I'm using .NET. I can reference the MBPScriptModel2Lib.dll but I'd like to use the .NET API (MBPNetModel) which makes use of the MediaBinServer object rather than the MBSession object. Is this possible?
msnider
You are on the right track, but it appears that you have forgotten to supply the metadata id; add the following line...
searchConstraints[0].mMetadata.mID = <GUID>
For example, to do an AnyText search, your metadata object should look similar to this:
metadata.mName = "Any Text";
metadata.mID = "{DD528FE2-19CE-471E-8DC1-9042F89422B1}";
metadata.mValue = text;
kbaley
Thanks but I'm still getting the same error. Here's the stack trace. Could there be something wrong with the Session class?
[NullReferenceException: Object reference not set to an instance of an object.]
MBPSCRIPTMODEL2Lib.MBSessionClass.CreateConstraintSearchCriteria(MBSearchConstraint SearchConstraint, Int32 MatchLimit, String ImageIdentifier) +0
MBPNetModel.MediaBinScriptModel.MediaBinServerImpl.Search(MBSearchCriteria criteria, Boolean onlyReturnIDs, MBConnection mbConnection)
MBPNetModel.MediaBinServer.Search(MBSearchCriteria criteria)
MediaBinDataAccess.MediaBinConnector.GetAssetIDsForGuid(String Guid) in c:\documents and settings\owner\my documents\my projects\assetmanager\mediabindataaccess\mediabinconnector.cs:65
AssetManager.AssetManager.BindGrid() in c:\inetpub\wwwroot\assetmanager\assetmanager.aspx.cs:39
AssetManager.AssetManager.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\assetmanager\assetmanager.aspx.cs:32
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
msnider
Are you explicitly setting MBSearchCriteria.mAssetID? If not, try setting it to an empty string instead of the default null.
kbaley
That did it. Thanks a lot!