Add attachement via web service

If you are having a problem using Vault, post a message here.
Post Reply
kibbey
Posts: 5
Joined: Mon Jun 15, 2009 8:39 am

Add attachement via web service

Post by kibbey » Wed Apr 03, 2013 5:47 am

I'm attempting to work out the details of adding an attachement to a very simple web page that allows our managment to poke bugs into Vault Pro. At the moment, I have the basics working with the DragnetWebServiceSoapClient and MantisItem. The file attachement seems to have multiple examples which don't quite match with what is on my system. Is there an updated example for Vault Pro 6.1?

lbauer
Posts: 9736
Joined: Tue Dec 16, 2003 1:25 pm
Location: SourceGear

Re: Add attachement via web service

Post by lbauer » Wed Apr 03, 2013 8:54 am

The file attachement seems to have multiple examples which don't quite match with what is on my system
Which specific examples are you looking at?

The VaultPro api hasn't really changed from the Fortress api.
Linda Bauer
SourceGear
Technical Support Manager

kibbey
Posts: 5
Joined: Mon Jun 15, 2009 8:39 am

Re: Add attachement via web service

Post by kibbey » Wed Apr 03, 2013 9:32 am

Here's what I'm working with (mostly copied from various posts on this site). At the moment, it spits out an error regarding a date value being out of range.

Code: Select all

  MantisItem mItem = new MantisItem();
            mItem.ProjectID = nProjectID; //required int	
            mItem.Description = txtDesc.Text;
            mItem.CategoryID = Convert.ToInt32(lbCategory.SelectedValue);
            mItem.PriorityID = nPriorityID; // required int 
            mItem.ItemAccessType = DragnetSrvc.AccessType.Public;
            mItem.Details = txtDetails.Text;
            mItem.Version = strVersion; // optional string 
            mItem.PlatformID = nPlatformID; //required int 
            mItem.TypeID = Convert.ToInt32(lbType.SelectedValue);
            mItem.Created = DateTime.Now;        

            // Set Custom 1 (Sponsor, this will be the user making the submission)
            string strCustom1 = UserName;
            mItem.Custom1 = strCustom1; //optional string 

            mItem.Custom2 = strCustom2; //optional string                         
            mItem.StatusID = nStatusID; //required for ModifyItem() - this value is automatically set to "open" for AddItemExternal() and AddItem() 
            mItem.AssigneeID = nAssigneeID; //required for AddItem() - this value is automatically set to "external user ID" for AddItemExternal()             

            
            // Let's try to add an attachement            
            MantisItemAttachmentFullDetail mAttachFull = new MantisItemAttachmentFullDetail();            
            //mAttachFull.AttStream = fileUpload.PostedFile.InputStream;
            mAttachFull.ContentType = fileUpload.PostedFile.ContentType;
            mAttachFull.FileCRC = 0;            
            mAttachFull.FileLength = fileUpload.PostedFile.ContentLength;
            mAttachFull.Description = txtAttachDesc.Text;
            mAttachFull.FileName = fileUpload.PostedFile.FileName;
            mItem.AddedAttachments = new MantisItemAttachmentFullDetail[] { mAttachFull };

            ////The following assumes Dragnet is the name of the web reference 

            CookieContainer cc = new CookieContainer();
            DragnetSrvc.DragnetWebServiceSoapClient dragSvc = new DragnetWebServiceSoapClient();            

            int ret = -1;            
            ret = dragSvc.AddItemExternal(null, mItem);

lbauer
Posts: 9736
Joined: Tue Dec 16, 2003 1:25 pm
Location: SourceGear

Re: Add attachement via web service

Post by lbauer » Wed Apr 03, 2013 9:00 pm

What's the exact error you're getting?

You can also try your command without this:
mItem.Created = DateTime.Now;

VaultPro Server should give the new item a creation date/time.
Linda Bauer
SourceGear
Technical Support Manager

kibbey
Posts: 5
Joined: Mon Jun 15, 2009 8:39 am

Re: Add attachement via web service

Post by kibbey » Thu Apr 04, 2013 7:25 am

1: Failure ---> SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

System.ServiceModel.FaultException was unhandled by user code
HResult=-2146233087
Message=1: Failure ---> SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ClientProfile.DragnetSrvc.DragnetWebServiceSoap.AddItemExternal(AddItemExternalRequest request)
at ClientProfile.DragnetSrvc.DragnetWebServiceSoapClient.ClientProfile.DragnetSrvc.DragnetWebServiceSoap.AddItemExternal(AddItemExternalRequest request) in d:\VaultProjects\ClientProfile\ClientProfile\Service References\DragnetSrvc\Reference.cs:line 7229
at ClientProfile.DragnetSrvc.DragnetWebServiceSoapClient.AddItemExternal(VaultAuth VaultAuth, MantisItem item) in d:\VaultProjects\ClientProfile\ClientProfile\Service References\DragnetSrvc\Reference.cs:line 7236
at ClientProfile.AddBugItem.SaveWorkItem() in d:\VaultProjects\ClientProfile\ClientProfile\AddBugItem.aspx.cs:line 115
at ClientProfile.AddBugItem.btnSubmit_Click(Object sender, EventArgs e) in d:\VaultProjects\ClientProfile\ClientProfile\AddBugItem.aspx.cs:line 120
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

This comes right after the attempt to run the line below.

ret = dragSvc.AddItemExternal(null, mItem);

Thanks,

lbauer
Posts: 9736
Joined: Tue Dec 16, 2003 1:25 pm
Location: SourceGear

Re: Add attachement via web service

Post by lbauer » Thu Apr 04, 2013 10:15 am

Is there an error in the the Vault Server log when you get this error from the API?

The Vault server log is called sgvault.log and is in %windir%\temp\sgvault on the server machine.
Linda Bauer
SourceGear
Technical Support Manager

kibbey
Posts: 5
Joined: Mon Jun 15, 2009 8:39 am

Re: Add attachement via web service

Post by kibbey » Thu Apr 11, 2013 11:18 am

There were no entries in the log file. I did find that by providing a value for DueDate I can now post a bug report through the web service.

The attachment still does not work. I see a few examples from years ago where the answer is that attachments are not supported. Is that still the case?

lbauer
Posts: 9736
Joined: Tue Dec 16, 2003 1:25 pm
Location: SourceGear

Re: Add attachement via web service

Post by lbauer » Fri Apr 12, 2013 10:11 am

If you call ClientInstance.AddItem() and the "MantisItem" variable has an array of AddedAttachments (with filled in with attachment description and attachment local path), that should work in saving the work item with attachment.
Linda Bauer
SourceGear
Technical Support Manager

Post Reply